Browse Source

Adds namespace support

master
sloum 2 months ago
parent
commit
3215a53562
  1. 48
      README.md
  2. 55
      main.slo
  3. 4
      module.json

48
README.md

@ -6,37 +6,37 @@ list is module for the slope programming language containing various procedures
The following procedures are available:
- `(reduce [procedure] [list] [init: value])` => `value`
- ex. `(reduce + [1 2 3 4] 0)` => `10`
- `(list::reduce [procedure] [list] [init: value])` => `value`
- ex. `(list::reduce + [1 2 3 4] 0)` => `10`
- Reduce, as formulated here, is left associative
- `(last [list])` => 'value'
- `(list::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`
- 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. `(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`
- 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. `(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`
- 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

55
main.slo

@ -7,7 +7,7 @@
;;
;; reduce performs a left associative reduce
;;
;; (reduce [procedure] [list] [initial: value]) => value
;; (list::reduce [procedure] [list] [initial: value]) => value
;;
;; ex: (reduce + [1 2 3 4] 0) => 10
(define reduce (lambda (proc lst init)
@ -26,7 +26,7 @@
;;
;; last retrieves the last element of a list
;;
;; (last [list]) => value
;; (list::last [list]) => value
;;
;; ex: (last [1 'A "Hi"]) => "Hi"
;;
@ -44,7 +44,7 @@
;; find retrieves the first or last value that returns
;; a truthy value when passed to a predicate procedure
;;
;; (find [procedure] [list] [[last: bool]] [[nomatch]]) => value
;; (list::find [procedure] [list] [[last: bool]] [[nomatch]]) => value
;;
;; - 'last' defaults to: #f and determines whether to use the
;; last matching value rather than the first (default)
@ -52,10 +52,10 @@
;; which will be returned if there are no values that
;; return a truthy value from the predicate procedure
;;
;; ex: (find (lambda (x) (> x 50)) [53 43 87]) => 53
;; (find (lambda (x) (> x 50)) [53 43 87] #t) => 87
;; (find (lambda (x) (> x 90)) [53 43 87]) => #f
;; (find (lambda (x) (> x 90)) [53 43 87] #f 0) => 0
;; ex: (list::find (lambda (x) (> x 50)) [53 43 87]) => 53
;; (list::find (lambda (x) (> x 50)) [53 43 87] #t) => 87
;; (list::find (lambda (x) (> x 90)) [53 43 87]) => #f
;; (list::find (lambda (x) (> x 90)) [53 43 87] #f 0) => 0
;;
(define find (lambda (proc lst args-list)
(cond
@ -89,7 +89,7 @@
;; a truthy value when the index's value is passed to a predicate
;; given procedure
;;
;; (position [procedure] [list] [[last: bool]] [[nomatch]]) => value
;; (list::position [procedure] [list] [[last: bool]] [[nomatch]]) => value
;;
;; - 'last' defaults to: #f and determines whether to use the
;; last matching value rather than the first (default)
@ -97,10 +97,10 @@
;; which will be returned if there are no values that
;; return a truthy value from the predicate procedure
;;
;; ex: (position (lambda (x) (> x 5)) [5 7 4 8]) => 1
;; (position (lambda (x) (> x 5)) [5 7 4 8] #t) => 3
;; (position (lambda (x) (> x 9)) [5 4 8]) => #f
;; (position (lambda (x) (> x 9)) [5 4 8] #f -1) => -1
;; ex: (list::position (lambda (x) (> x 5)) [5 7 4 8]) => 1
;; (list::position (lambda (x) (> x 5)) [5 7 4 8] #t) => 3
;; (list::position (lambda (x) (> x 9)) [5 4 8]) => #f
;; (list::position (lambda (x) (> x 9)) [5 4 8] #f -1) => -1
;;
(define position (lambda (proc lst args-list)
(cond
@ -135,9 +135,9 @@
;;
;; unique creates a set/unique-list from a given list
;;
;; (unique [list]) => list
;; (list::unique [list]) => list
;;
;; ex: (unique [1 1 22 4 3 1 3 3 4]) => [1 22 4 3]
;; ex: (list::unique [1 1 22 4 3 1 3 3 4]) => [1 22 4 3]
;;
(define unique (lambda (lst)
(if (not (list? lst))
@ -152,10 +152,10 @@
;;
;; cadr returns the car of the cdr of a list
;;
;; (cadr [list]) => value
;; (list::cadr [list]) => value
;;
;; ex: (cadr [1 2 3 4]) => 2
;; (cadr [[1 'A] [2 'B] [3 'C]]) => (2 'B)
;; ex: (list::cadr [1 2 3 4]) => 2
;; (list::cadr [[1 'A] [2 'B] [3 'C]]) => (2 'B)
;;
(define cadr (lambda (lst)
(cond
@ -170,12 +170,12 @@
;; alike returns a boolean representing whether or not
;; the items in the list are of the same type
;;
;; (alike? [list]) => bool
;; (list::alike? [list]) => bool
;;
;; ex: (alike? [1 2 3 4]) => #t
;; (alike? [1 2 "3" 4]) => #f
;; (alike? [[1 2] ["a" "b"] []]) => #t
;; (alike? []) => #t
;; ex: (list::alike? [1 2 3 4]) => #t
;; (list::alike? [1 2 "3" 4]) => #f
;; (list::alike? [[1 2] ["a" "b"] []]) => #t
;; (list::alike? []) => #t
;;
;; - A null list returns #t
;; - Sublists are not evaluated, if all items in a list
@ -196,4 +196,13 @@
(else (alike-loop (cdr lst) typ)))))
(alike-loop l (type (car l))))))))
; vim: ts=2 sw=2 expandtab ft=scheme
(define _USAGE [
["reduce" "(list::reduce [procedure] [list] [init: value]) => value\n\n`reduce`. This version of reduce is left associative and was added to this module before `reduce` was present in the std library. It remains here for historical reasons, but the builtin should be favored."]
["last" "(list::last [list]) => value\n\n`last` retrieves the last value in the list, and is thus the opposite of the built-in `car`"]
["find" "(list::find [procedure] [list] [[last?: bool]] [[nomatch: value]]) => number|nomatch: value\n\n`find` retrieves the first, or last, list value that returns `#t` when pased to a predicate procedure.\n\n`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).\n\n`nomatch` defines the value to be returned if no list values are found to be truthy. The default `nomatch` value is `#f`."]
["position" "(list::position [procedure] [list] [[last?: bool]] [[nomatch: value]]) => number|nomatch: value\n\n`position` retrieves the first, or last, list index that returns `#t` when pased to a predicate procedure.\n\n`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).\n\n`nomatch` defines the value to be returned if no list values are found to be truthy. The default `nomatch` value is `#f`."]
["unique" "(list::unique [list]) => list\n\n`unique` returns a set/unique-list from the given list"]
["cadr" "(list::cadr [list]) => value\n\n`cadr` returns the car of the cdr of the given list"]
["alike?" "(list::alike [list]) => bool\n\n`alike?` returns a boolean representing whether or not the items in the list are of the same type"]])
; vim: ts=2 sw=2 expandtab ft=slope

4
module.json

@ -2,9 +2,9 @@
"title": "list",
"description": "a collection of list manipulation procedures",
"author": "sloum",
"version": "0.1.2",
"version": "0.1.3",
"homepage": "",
"repository": "https://git.rawtext.club/sloum/list",
"tag": "0.1.2",
"tag": "0.1.3",
"dependencies": []
}

Loading…
Cancel
Save