[Top][All Lists]

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

Re: pcase ` meaning

From: Yuri Khan
Subject: Re: pcase ` meaning
Date: Tue, 30 Oct 2018 23:05:08 +0700

On Tue, Oct 30, 2018 at 7:18 AM Garreau, Alexandre
<address@hidden> wrote:

> (pcase `(1 2 3) (`(1 2 3) t))
> look the same, as well as:
> (pcase `(a b c) (`(a b c) t))
> But not:
> (pcase `(1 2 3) (`(,a ,b ,c) (+ a b c)))

IMO you’re giving too much attention to “looking the same”.

You use identifiers a, b, and c in a pattern. The pattern matcher
needs to know which of these you meant as placeholders to bind, and
which as literal symbols to match against.

    (let ((c 42))
      (pcase `(a x 42) (`(a ,b ,(pred (equal c))) t)))

In an alternate world, you would color the parentheses, the spaces,
and the literal symbol “a” yellow, and say these are the things to
match literally. You would then color “b” and “c” white, and say these
are placeholders. You might even color something green and say these
are expressions whose values should be taken and matched.

In that same world, you could draw nested boxes instead of these
nested parentheses that make newbies so nervous about Lisp.

However, in this world, we only encode Unicode characters in our
source files, and add color only as an aid to understanding. So we use
various funny characters such as parentheses to denote nesting, and `
and , to denote color.

(Upthread, the idea of “holes” was mentioned. That is a very good
analogy, both for pcase and for quoting/antiquoting in general.)

reply via email to

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