A collection of list oriented procedures for the slope programming language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2.6 KiB

list

list is module for the slope programming language containing various procedures that operate on lists.

API

The following procedures are available:

  • (list::reduce [procedure] [list] [init: value]) => value
    • ex. (list::reduce + [1 2 3 4] 0) => 10
    • Reduce, as formulated here, is left associative
  • (list::last [list]) => 'value'
    • Retrieves the last list value (the opposite of car)
    • ex. (list::last [1 2 3 4]) => 4
  • (list::find [procedure] [list] [[last?: bool]] [[nomatch: value]]) => value
    • Find retrieves the first, or last, list value that returns a true when passed to a predicate procedure
    • last? defaults to #f, thus returning the first truthy value. A #t setting for last? will return the last truthy value (it will make the procedure right associative)
    • nomatch defines the value to be returned if no list values are found to be truthy. The default 'nomatch' value is #f
    • ex. (list::find (lambda (x) (> x 50)) [53 43 87]) => 53
    • ex. (list::find (lambda (x) (> x 50)) [53 43 87] #t) => 87
    • ex. (list::find (lambda (x) (> x 90)) [53 43 87]) => #f
    • ex. (list::find (lambda (x) (> x 90)) [53 43 87] #f 0) => 0
  • (list::position [procedure] [list] [[last?: bool]] [[nomatch: value]]) => number|nomatch: value
    • Position retrieves the first, or last, list index that returns a true when passed to a predicate procedure
    • last? defaults to #f, thus returning the first truthy value. A #t setting for last? will return the last truthy value (it will make the procedure right associative)
    • nomatch defines the value to be returned if no list values are found to be truthy. The default 'nomatch' value is #f
    • ex. (list::position (lambda (x) (> x 50)) [53 43 87]) => 0
    • ex. (list::position (lambda (x) (> x 50)) [53 43 87] #t) => 2
    • ex. (list::position (lambda (x) (> x 90)) [53 43 87]) => #f
    • ex. (list::position (lambda (x) (> x 90)) [53 43 87] #f -1) => -1
  • (list::unique [list]) => list
    • ex. (list::unique [1 1 22 4 3 1 3 3 4]) => (1 22 4 3)
  • (list::cadr [list]) => value
    • ex. (list::cadr [1 2 3 4]) => 2
    • ex. (list::cadr [[1 'A] [2 'B] [3 'C']]) => (2 B)
  • (list::alike? [list]) => bool
    • ex. (list::alike? []) => #t
    • ex. (list::alike? [1 2 3 4]) => #t
    • ex. (list::alike? [[1 2] ["a" "b"] []]) => #t
    • ex. (list::alike? [1 2 "3" "hi" []]) => #f
    • Sublists are not evaluated. If the given list contains no atoms, but only other lists, #t will be returned regardless of the contents of the sublists