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.
 
sloum cf28181e9b Updates unique to preserve list order 1 month ago
README.md Initial commit 1 month ago
main.slo Updates unique to preserve list order 1 month ago
module.json Updates unique to preserve list order 1 month ago

README.md

list

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

API

The following procedures are available:

  • (reduce [procedure] [list] [init: value]) => value
    • ex. (reduce + [1 2 3 4] 0) => 10
    • Reduce, as formulated here, is left associative
  • (last [list]) => 'value'
    • Retrieves the last list value (the opposite of car)
    • ex. (last [1 2 3 4]) => 4
  • (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. (find (lambda (x) (> x 50)) [53 43 87]) => 53
    • ex. (find (lambda (x) (> x 50)) [53 43 87] #t) => 87
    • ex. (find (lambda (x) (> x 90)) [53 43 87]) => #f
    • ex. (find (lambda (x) (> x 90)) [53 43 87] #f 0) => 0
  • (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. (position (lambda (x) (> x 50)) [53 43 87]) => 0
    • ex. (position (lambda (x) (> x 50)) [53 43 87] #t) => 2
    • ex. (position (lambda (x) (> x 90)) [53 43 87]) => #f
    • ex. (position (lambda (x) (> x 90)) [53 43 87] #f -1) => -1
  • (unique [list]) => list
    • ex. (unique [1 1 22 4 3 1 3 3 4]) => (1 22 4 3)
  • (cadr [list]) => value
    • ex. (cadr [1 2 3 4]) => 2
    • ex. (cadr [[1 'A] [2 'B] [3 'C']]) => (2 B)
  • (alike? [list]) => bool
    • ex. (alike? []) => #t
    • ex. (alike? [1 2 3 4]) => #t
    • ex. (alike? [[1 2] ["a" "b"] []]) => #t
    • ex. (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