I decided today that I wanted to partially apply functions in Common Lisp like you can do in Haskell.
In the package `cl-mongo`, `get-element` takes a name and a document and returns the value or nil for that element of the doc. I was messing around in the repl viewing different documents and every time I did so I had to do something like this:
(mapcar #'(lambda (x) (get-element "uid" x)) (car (db.find "stuff" :all)))
Which, as an also-Haskell programmer, that is just far too verbose.
The solution was, as always, a macro.
(defmacro @-map (toapply list) `(mapcar #'(lambda (x) (,@toapply x)) ,base))
(macroexpand '(@-map (get-element "uid") (docs (db.find "categories" :all))))
(MAPCAR #'(LAMBDA (X) (GET-ELEMENT "uid" X)) (DOCS (DB.FIND "categories" :ALL)))
Now I just need to figure out a better name for this. I’m sure I’ll be making a lot more of this sort of thing.