emacs-devel
[Top][All Lists]
Advanced

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

Re: pcase ` meaning


From: Garreau\, Alexandre
Subject: Re: pcase ` meaning
Date: Thu, 01 Nov 2018 00:13:42 +0100
User-agent: Gnus (5.13), GNU Emacs 25.1.1 (i686-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-09-15, modified by Debian

On 2018-10-30 at 09:14, Stefan Monnier wrote:
>> #+BEGIN_SRC ocaml
>>   match [1;2;3] with [a;b;c] -> [a;b;c]
>> #+END_SRC
>>
>> But this is a non-primordial side effect.  Notice how in the later case
>> the matched data *always* look the same as the pattern (beside replacing
>> a number per an identifier): *that’s* the purpose of pattern matching.
>> While in the lisp case you got those extra “,”.
>
> That's for a very simple reason: OCaml doesn't have Lisp's symbols, so
> its [a;b;c] can't mean "a list containing the symbols a, b, and c".

In lisp I would have prefered to be able to directly quote each symbol,
and have this to work, eg: “(pcase (list 1 2 3) (('a 'b 'c) t))” to
return nil, and “(pcase (list 'a 'b 'c) (('a 'b 'c) t))” to return t
(and this is like many other lisp pattern-matching implementations
already work).  In current pcase, pattern “(a b c)” does *not* mean
“with symbols 'a, 'b and 'c”.

“('(a b c) t)” (or same with “`”) seems okay to me, but as “(`(,a ,b ,c)
t)” *may* be confusing (the intended, actual and current meaning must be
intuitive under some definition of “intuitive” too since others
independantly do it too), I’d prefer “((a b c) t)” to work.

> OCaml still has to distinguish between variables and data constructors,
> but instead of using a "," to distinguish the two cases, they force
> constructors to be capitalized.

Oh… yet another (disappointing) reason why they did what (incredibly
limited) they did (though afaik it’s nothing new, it have to come from
Smalltalk, and I’m not that much opposed to identifiers names/meaning
intermeddling).



reply via email to

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