Add partial function.

This commit is contained in:
Kyle 2015-04-06 22:00:45 -07:00
parent 29fdec7e28
commit 614adf31cb
2 changed files with 17 additions and 1 deletions

View File

@ -12,6 +12,21 @@
(list y sep)) (list y sep))
x))) x)))
(defun build-list (arg)
"If arg is an atom, return it as a list. If it's a list, return the
arg. If it's a vector, coerce it to a list. Otherwise, return nil."
(cond
((listp arg) (copy-list arg))
((atom arg) (list arg))
((vectorp arg) (coerce arg 'list))
(t nil)))
(defun partial (fn &rest initial-args)
"partial provides partial function application. It returns a lambda
that will call the function given with the intial args and any
additional args provided to the lambda."
(lambda (&rest args)
(apply fn (append initial-args args))))
;;; hash-table functions. ;;; hash-table functions.
@ -92,4 +107,3 @@ value :b, and :c stores the value :d.
(sethash (car elt) (cdr elt) m)) (sethash (car elt) (cdr elt) m))
m)) m))
(defun kget (elt indicator)

View File

@ -9,6 +9,8 @@
#:compose #:compose
#:defmacro! ; Let Over Lambda utilities #:defmacro! ; Let Over Lambda utilities
#:join ; My utilities #:join ; My utilities
#:build-list
#:partial
#:enable-hash-table-reader #:enable-hash-table-reader
#:hashkeys #:hashkeys
#:sethash #:sethash