[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Patch to add (define-syntax (foo bar) ...) support
From: |
Marijn |
Subject: |
Re: Patch to add (define-syntax (foo bar) ...) support |
Date: |
Mon, 05 Sep 2011 09:58:55 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110825 Thunderbird/6.0 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 09/02/11 15:33, Ian Price wrote:
> Andy Wingo <address@hidden> writes:
>
>> On the whole I am skeptical. But, Chez Scheme and Racket both
>> made this change. So I could go either way, though I would like
>> thoughts from other people before proceeding.
>
> While I like the change, another solution is to try to make a
> 'syntax-case' form that returns a lambda like syntax-rules.
>
> Either,
>
> (define-syntax foo (syntax-case* () ((foo ...) ...) ...))
>
> or if we need access to the syntax object for e.g. unhygienic
> macros
>
> (define-syntax foo (syntax-case* stx () ((foo ...) ...) ...))
If you reduce the requirement of being able to elide `stx' when it's
not used, then it becomes the really simple:
(define-syntax-rule (syntax-case/fn stx . args)
(lambda (stx)
(syntax-case stx . args)))
Personally I think there should also be a macro that let's one write:
(define-syntax-rules syntax-case/fn
((_ stx . args)
(lambda (stx)
(syntax-case stx . args)) ))
but which would also be able to handle the case of multiple rules.
> I haven't used this in practice, but it would cut down on some
> consistent verbosity. A rough implementation could be
>
> (define-syntax syntax-case* (lambda (stx) ; goodbye forever old
> friend ;-) (syntax-case stx () ((syntax-case* syntax-object
> literals rule rules ...) (identifier? #'syntax-object) #'(lambda
> (syntax-object) (syntax-case syntax-object literals rule rules
> ...))) ((syntax-case* literals rule rules ...) #'(lambda
> (syntax-object) (syntax-case syntax-object literals rule rules
> ...))))))
The following macro seems equivalent:
(define-syntax syntax-case/fn
(syntax-rules ()
((_ (lits ...) . rules)
(lambda (stx)
(syntax-case stx (lits ...) . rules)))
((_ stx (lits ...) . rules)
(lambda (stx)
(syntax-case stx (lits ...) . rules)))))
or using the above ``defined'' define-syntax-rules:
(define-syntax-rules syntax-case/fn
((_ (lits ...) . rules)
(lambda (stx)
(syntax-case stx (lits ...) . rules)))
((_ stx (lits ...) . rules)
(lambda (stx)
(syntax-case stx (lits ...) . rules)))))
> It wouldn't match up with the meaning of syntax-case* in racket,
> but if that's important to anyone, feel free to come up with
> another name :-)
Some alternative names might be syntax-case/fn, syntax-case/l,
syntax-case/lambda (but kinda defeats the purpose of not having to
type lambda).
Anyway, less typing for macro boilerplate is something I appreciate.
Marijn
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk5kgT8ACgkQp/VmCx0OL2zyugCguOpctFfLTV+x45cZ0IXrkv6u
ejMAn1ECvJyPbQHwSe1TT2Kd0h2sp8oX
=wv9z
-----END PGP SIGNATURE-----