Skip to content

Commit

Permalink
Added (every) and (repeated)
Browse files Browse the repository at this point in the history
  • Loading branch information
skx committed Oct 15, 2022
1 parent 696c2ad commit 52ac625
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ We have a reasonable number of functions implemented, either in our golang core
* `help` will return the supplied help text for any functions which provide it - which includes all of our built-in functions and large parts of our standard-library.
* **NOTE**: This does not (yet?) include help for special forms such as `(let* ..)`, `(if ..)`, etc.
* List operations:
* `butlast`, `car`, `cdr`, `cons`, `drop`, `first`, `last`, `list`,`sort`, & `take`.
* `butlast`, `car`, `cdr`, `cons`, `drop`, `every`, `first`, `last`, `list`, `repeated`, `sort`, & `take`.
* Logical operations:
* `and`, & `or`.
* Mathematical operations:
Expand Down
15 changes: 15 additions & 0 deletions stdlib/stdlib.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@
false))))


;; every is useful and almost a logical operation
(set! every (fn* (xs:list fun:function)
"Return true if applying every element of the list through the specified function resulted in a true result"
(let* (res (map xs fun))
(if (and res)
true
false))))


;; Useful for creating a list of numbers
(set! repeated (fn* (n:number x)
"Return a list of length n whose elements are all x"
(when (pos? n)
(cons x (repeated (dec n) x)))))

;; inc/dec are useful primitives to have
(set! inc (fn* (n:number)
"inc will add one to the supplied value, and return the result."
Expand Down

0 comments on commit 52ac625

Please sign in to comment.