Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Q: What do you call a blind, deaf-mute, quadraplegic Virginian? A: Trustworthy.


comp / comp.lang.lisp / Re: CL vs scheme macros, namespaces.

SubjectAuthor
* Re: CL vs scheme macros, namespaces.B. Pym
`- Re: CL vs scheme macros, namespaces.Kaz Kylheku

1
Subject: Re: CL vs scheme macros, namespaces.
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Wed, 3 Jul 2024 11:58 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: CL vs scheme macros, namespaces.
Date: Wed, 3 Jul 2024 11:58:56 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <v63edt$2637i$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Wed, 03 Jul 2024 13:58:56 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="f596af2a045597d397e348f55d8193c0";
logging-data="2297074"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JlhUEzlWUNDJOhDGacRWT"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:DA9Gx+IkzKVgH7SQQ50mnvQhZts=
View all headers

> To take a simple example:
>
> (define-syntax -->
> (syntax-rules ()
> ((_ . original)
> (-->helper () original))))
>
> (define-syntax -->helper
> (syntax-rules ()
> ((_ pairs (x0 y0 . more))
> (-->helper ((x0 y0) . pairs) more))
> ((_ pairs body)
> (let pairs . body))))
>
>
>
> (defmacro --> (&rest [var-val]*-body)
> `(let ,(loop for (var val) on (butlast [var-val]*-body) by (function cddr)
> collect (list var val))
> ,@(last [var-val]*-body)))

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 ...) ]))

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

Subject: Re: CL vs scheme macros, namespaces.
From: Kaz Kylheku
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Wed, 3 Jul 2024 14:10 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: CL vs scheme macros, namespaces.
Date: Wed, 3 Jul 2024 14:10:10 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <20240703065204.66@kylheku.com>
References: <v63edt$2637i$1@dont-email.me>
Injection-Date: Wed, 03 Jul 2024 16:10:10 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="30e244ac737476d78edd2cd6194d0a15";
logging-data="2332223"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Vty8dS1SungXbXB3dTFz9W80OnbyMZ9A="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:7zoc2mw4R322h3rB0PxodjGicro=
View all headers

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/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

1

rocksolid light 0.9.8
clearnet tor