💾 Archived View for idiomdrottning.org › fn-and-over captured on 2022-01-08 at 13:40:31. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2021-12-03)
-=-=-=-=-=-=-
Tired of writing the same basic, boring lambda bindings over and over again.
Let’s automate that.
(fn (cons x rest))
is shorthand for (lambda (x . rest) (cons x rest))
and
(fn (print y) (+ x z))
is shorthand for (lambda (x y z) (print y) (+ x z)).
(fn body ...)
is shorthand for
(lambda some-basic-bindings body ...)
where some-basic-bindings is one of
and the fn macro automatically figures out which of those four you mean. Note that the length of rest will be different based on the presence of y or z.
(over body ...)
is shorthand for
(cut map (lambda some-basic-bindings body ...) <>)
except that the map can take any number of lists and that i is also anaphorically bound to the list index in body.
Here is an example:
((over (+ x x y i)) '(10 20 40) '(3 6 9))
⇒ (23 47 91)
fn and over are part of the brev-separate egg for chicken. For source code,
git clone https://idiomdrottning.org/brev-separate
Thanks to Chris Brannon and Juergen Lorenz for the idea.