[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: syntax taste: use of unquote in macros

From: Ludovic Courtès
Subject: Re: syntax taste: use of unquote in macros
Date: Tue, 31 Mar 2020 18:56:17 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)

Hi Matt,

Matt Wette <address@hidden> skribis:

> I'm not sure if you know about this, but there is a discrepancy in the
> way some folks define macros to use unquote (aka ,).   For example,
>> (use-modules (system base pmatch))
>> (pmatch '(foo "bar")  ((foo ,val)  (write val) (newline)))
> => "bar"
>> (use-modules (ice-9 match))
>> (match '(foo "bar")  (`(foo ,val)  (write val) (newline)))
> => "bar"
> Note the difference in the use of quasiquote (aka `) in the pattern
> for (foo ,val): match syntax uses it, pmatch does not.
> In Scheme, quasiquote and unquote always come together.
> Is pmatch syntax in bad taste?  I'm looking for opinions.

It really depends on what you’re going to use the pattern matcher for.
For ‘sxml-match’, it’s more convenient to have literals be the default
because there are usually more literals than variables, as in:

       (sxml-match x
         ((album (@ (title ,t)) (catalog (num ,n) (fmt ,f)) ...)
          `(ul (li ,t)
               (li (b ,n) (i ,f)) ...)))

In more general cases, I prefer the (ice-9 match) style because patterns
typically have more variables than literals.

In one case, I found myself implementing pmatch-style quoting on top of
(ice-9 match) so I would have the best of both worlds:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]