emacs-devel
[Top][All Lists]
Advanced

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

Re: Instead of pcase


From: Spencer Baugh
Subject: Re: Instead of pcase
Date: Thu, 16 Nov 2023 10:20:49 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

Setting aside whether pcase is good or not:

I've thought before that it would be nice to have a cond-let construct,
like if-let and when-let.  The body of a cond clause would be bound to
the result of the condition.  Perhaps that could be a good alternative
to some use-cases for pcase?

For example, if one has a cons whose cdr is a string if the car is 'foo,
and whose cdr is a number if the car is 'bar, then with pcase one can
write:

(let ((exp (if t '(foo . "str") '(bar . 7))))
  (pcase exp
    (`(foo . ,val) (concat "str" val))
    (`(bar . ,val) (+ 1 val))))

and with cond-let one could write:

(let ((exp (if t '(foo . "str") '(bar . 7))))
  (cond-let
   ((val
     (and (eq (car exp) 'foo) (cdr exp)))
    (concat "str" val))
   ((val
     (and (eq (car exp) 'bar) (cdr exp)))
    (+ 1 val))))

Which is maybe nicer?




reply via email to

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