-- Leo's gemini proxy

-- Connecting to idiomdrottning.org:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini; lang=en

fn and over


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


(fn body ...)

is shorthand for


(lambda some-basic-bindings body ...)

where some-basic-bindings is one of


args

(x . rest)

(x y . rest)

(x y z . rest)


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


(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)


Implementation


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.

-- Response ended

-- Page fetched on Fri Jul 23 14:57:22 2021