emacs-devel
[Top][All Lists]
Advanced

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

Re: cond* vs pcase


From: Arthur Miller
Subject: Re: cond* vs pcase
Date: Tue, 06 Feb 2024 13:30:17 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Philip Kaludercic <philipk@posteo.net> writes:

> "Alfred M. Szmidt" <ams@gnu.org> writes:
>
>>    I use pcase often; but I use it just as a better cond. For example I find 
>> this
>>    handy:
>>
>>    (defvar foo nil) <-- foo is some symbol
>>
>>    (pcase foo
>>      ('bar (do-some-bar-stuff))
>>      ('baz (do-some-baz-fluff)))
>>
>> cl-case seems more appropriate here (wish cl-case was just case ...)
>
> Why more appropriate?  I always think of pcase as Elisp's case.  In
> addition, pcase avoids the danger of naively writing 
>
>    (cl-case foo
>      ('bar (do-some-bar-stuff))
>      ('baz (do-some-baz-fluff)))
>
> and then getting surprised when foo evaluates to `quote'.
>
>>    or this:
>>
>>    (setq foo "some-string")
>>
>>    (pcase foo
>>      ("foo" (do-foo-case))
>>      ("bar" (do-bar-case)))
>>
>> Same here, with (intern foo) ...
>
> Being able to do equal instead of eql is also something that speaks in
> favour of pcase...

Thanks Philip; that was an useful detail you pointed out. And thanks Alfred for
the suggestion too. I actually wanted to ask the same question as Philip, but I
didn't had time last night.

But what I am most thinking of, is this kind of quesionts and detail for people
to learn, and now we can add yet another case-like construct and perhaps 
slightly
different behaviour in similar cases, and there will be even more mine fields
for people to watch out and debug.




reply via email to

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