fn

2017-02-27

fn

A couple of lambda shorthand macros. Their goal is to be used in cases where the word 'lambda and args are longer than the body of the lambda. It fixes this by adding implicit arguments.

(fn* (+ _ _))  -->  (lambda (_) (+ _ _))

(fn* (+ _ _1))  -->  (lambda (_ _1) (+ _ _1))

(fn* (subseq _@ 0 2))  -->  (lambda (&rest _@) (subseq _@ 0 2))

The ? reader macro is gives you the clojure like syntax.

?(+ _ _)  -->  (lambda (_) (+ _ _))

?(+ _ _1)  -->  (lambda (_ _1) (+ _ _1))

?(subseq _@ 0 2)  -->  (lambda (&rest _@) (subseq _@ 0 2))

I REALLY dont like adding reader macros, but as ? is such a rarely used character I dont feel too bad about it.

Finally fn~ and fn~r are functions for partial application. fn+ is for composing functions

Emacs

If you are using emacs and want Meta-l to write the ? symbol, add the following to your .emacs file

(global-set-key (kbd "M-l") (lambda () (interactive) (insert (make-char 'greek-iso8859-7 107))))

Some curiosities

?_ the identity function

(mapcar ?_ '(1 2 3)) -> (1 2 3)

?``(1 ,_ 3) list building functions

(mapcar ?`(1 ,_ 3) '(1 2 3)) -> ((1 1 3) (1 2 3) (1 3 3))

?1 a function that takes no args an returns 1

(funcall ?pi) -> 3.141592653589793d0
Author
Chris Bagley (Baggers) <techsnuffle@gmail.com>
License
Public Domain