3 ms·
In my own scheme-esque language, I have tried hooking up extra-concise means not only for lambdas, but for "anonymous macros" too. (Yes, the readability of the
by frou_dh 11y ago
In my own scheme-esque language, I have tried hooking up extra-concise means not only for lambdas, but for "anonymous macros" too.
(Yes, the readability of the resulting code is very suspect. Just experimenting!)
# Provide a prefix syntax that constructs a unary procedure from just a body.
(extend-parser "^" (mac (x) `(proc (?) ,x)))
# Provide a prefix syntax that constructs a unary macro from just a body.
(extend-parser "%" (mac (x) `(mac (?) ,x)))
# Apply an anonymous macro to 4, resulting in definitions for cad{1,4}r
# being generated then evaluated:
(
%`(seq ~(map ^(let i (codepoint-count ?)
sym (string-to (sprint "ca" ? "r"))
`(def ,sym (proc (xs) (ith-element ,i xs))))
(map ^(apply sprint (repeat "d" ?))
(range 1 ?))))
4)
# What ended up being evaluated at the top-level:
# (seq (def cadr (proc (xs) (ith-element 1 xs)))
# (def caddr (proc (xs) (ith-element 2 xs)))
# (def cadddr (proc (xs) (ith-element 3 xs)))
# (def caddddr (proc (xs) (ith-element 4 xs))))