https://github.com/cbaggers/fn
A couple of lambda shorthand macros
https://github.com/cbaggers/fn
Last synced: about 1 year ago
JSON representation
A couple of lambda shorthand macros
- Host: GitHub
- URL: https://github.com/cbaggers/fn
- Owner: cbaggers
- License: other
- Created: 2014-10-10T06:45:12.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2024-04-18T09:59:43.000Z (almost 2 years ago)
- Last Synced: 2025-02-18T19:19:20.547Z (about 1 year ago)
- Language: Common Lisp
- Size: 32.2 KB
- Stars: 26
- Watchers: 5
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-cl - fn - a couple of lambda shorthand macros. `(fn* (+ _ _)) --> (lambda (_) (+ _ _))`. Public domain. (Miscellaneous ##)
README
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 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.
To enable this reader macro, evaluate the following code:
(named-readtables:in-readtable :fn.reader)
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