guile-user
[Top][All Lists]
Advanced

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

Re: syntax taste: use of unquote in macros


From: Arne Babenhauserheide
Subject: Re: syntax taste: use of unquote in macros
Date: Mon, 30 Mar 2020 15:07:36 +0200
User-agent: mu4e 1.3.10; emacs 26.1

Matt Wette <address@hidden> writes:

> Hi All,
>
> 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.

I did not know about pmatch, but it gives me the feeling that this is a
pattern that will appear again for other embedded domain specific
languages.

I had a usecase for that in dryads-wake¹ for embedding instructions in
otherwise declarative code. It looks like this:

(Enter (Speaker))
(Speaker
    (My Text, line 1)
    (Second line)
    (very ,(color 'red) important ,(color #f) line))

At this point the difference to quasiquote doesn’t look big. It gets
much bigger when this code is used from wisp:²

Enter : Speaker
Speaker
    My Text, line 1
    Second line
    very ,(color 'red) important ,(color #f) line

With written quasiquote there would either be line-noise on every line
or this would have structure-noise because it would have to be wrapped
in a list instead of working like arguments to a procedure call:

(Enter (Speaker))
(Speaker
  `((My Text, line 1)
    (Second line)
    (very ,(color 'red) important ,(color #f) line)))

or

(Enter (Speaker))
(Speaker
    `(My Text, line 1)
    `(Second line)
    `(very ,(color 'red) important ,(color #f) line))

Best wishes,
Arne

¹: https://hg.sr.ht/~arnebab/dryads-wake/browse/default/dryads-wake.w#L231
²: https://www.draketo.de/english/wisp
-- 
Unpolitisch sein
heißt politisch sein
ohne es zu merken



reply via email to

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