Functional and other utils
LIPS Scheme provide various of utility functions. Some of them are inspired by Ramda.js library and Lodash. Some of those functions are defined in SRFI-1.
Curry
Curry is a common function in functional programming that return a new function with predefined arguments. The classic version, returns functions that accept one argument and keep returning new function until all argumments are passed. In LIPS there is more useful version of curry, that allow to pass more than one argument at the time. This is a common way curry is implemented. This is working in LIPS because Scheme lambdas has length property that indicate number of arguments.
(define (sum a b c)
(+ a b c))
(define add1 (curry sum 1))
(print (add1 2 4))
;; ==> #<procedure>
Take and drop
Take and drop procedures operates on lists and return a new list with:
take
- only first n elementsdrop
- first elements removed
(define lst '(1 2 3 4 5))
(take lst 3)
;; ==> (1 2 3)
(drop lst 3)
;; ==> (4 5)
(equal? lst (append! (take lst 3) (drop lst 3)))
;; ==> #t