Sujet : Re: CL vs scheme macros, namespaces.
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.lispDate : 03. Jul 2024, 16:10:10
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240703065204.66@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
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"))))
2> (flat 3)
3
3> (flat x 1 x)
1
4> (flat x 1 y 2 (+ x y))
3
5> (flat x 1 y 2 4 (+ x y))
** flat: bad syntax
** during evaluation at expr-1:6 of form (error "flat: bad syntax")
5> (flat x 1)
** flat: bad syntax
** during evaluation at expr-1:6 of form (error "flat: bad syntax")
5> (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/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca