On 2024-07-03, B. Pym <
No_spamming@noWhere_7073.org> wrote:
The helper macro isn't needed.
Scheme (Gauche and Racket):
The goal is a let-macro that doesn't need parentheses
around the bindings. Only one expression is allowed
after the bindings.
(define-syntax -->
(syntax-rules ()
[ (_ ((k v) ...) expr)
(let ((k v) ...) expr) ]
[ (_ ((k v) ...) a b . more)
(--> ((k v) ... (a b)) . more) ]
[ (_ a b c more ...)
(--> () a b c more ...) ]))
That's stupid; just make it so the wrapping is not allowed,
rather than optional:
(defmacro flat (. bindings-and-expr)
(tree-case bindings-and-expr
((expr) expr)
((k v . rest) ^(let ((,k ,v)) (flat ,*rest)))
(x (error "flat: bad syntax"))))
(flat 3)
3
(flat x 1 x)
1
(flat x 1 y 2 (+ x y))
3
(flat x 1 y 2 4 (+ x y))
** flat: bad syntax
** during evaluation at expr-1:6 of form (error "flat: bad syntax")
(flat x 1)
** flat: bad syntax
** during evaluation at expr-1:6 of form (error "flat: bad syntax")
(flat)
** flat: bad syntax
** during evaluation at expr-1:6 of form (error "flat: bad syntax")
a 2 m 44 z 88 (print (list a m z)))
(2 44 88)
a 2 m 44 z 88 )
; stdin:10:0: -->: bad syntax
; in: (--> ((a 2) (m 44) (z 88)))
Wut? Your diagnostic is reported against something that the
user didn't write, because it got normalized into
the nested let-style syntax, which is supposd to be
further processed.
What is the point.
--
TXR Programming Language:
http://nongnu.org/txr
Cygnal: Cygwin Native Application Library:
http://kylheku.com/cygnal
Mastodon: @
[email protected]
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)