Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Is it possible to write c...r in lisp, for any combination of letters a and d?.
(defun charfn (char) "maps a character to a function" (case char ((or #\A #\a) #'car) ((or #\D #\d) #'cdr) (t (error "unknown character-function type ~a" char)))) (defun fn-list (decon-name) (mapcar #'charfn (butlast (rest (coerce (symbol-name decon-name) 'list)))))
(defmacro defdecon (fn-name) `(defun ,fn-name (args) (funcall (arnesi:compose ,@(fn-list fn-name)) args)))
;; test cases
(funcall (arnesi:compose 'car) (list 1 2 3)) => 1 (funcall (arnesi:compose 'caar) (list (list 1) 2 3)) => 1
(defdecon caaaaar) ; define first (caaaaar (list (list (list (list (list 1 #\c) #\b) #\a) 2) 3)) ==> 1
just off the top of my head in 8 minutes.
make it to a reader macro if you so wish.
[Edit:
cat >> nfs://cltl3.alu.org/todo.txt
* CASE with custom tests
* COMP^H^H^H^HArnesi FFS!
]
There are no comments on this comment yet.
;; test cases
;; the base works, let's test the syntax; NB, redefining a builtin will not work :-)just off the top of my head in 8 minutes.
make it to a reader macro if you so wish.
[Edit:
cat >> nfs://cltl3.alu.org/todo.txt
* CASE with custom tests
* COMP^H^H^H^HArnesi FFS!
]