emacs-devel
[Top][All Lists]
Advanced

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

Re: pcase-if-let?


From: Nathan Moreau
Subject: Re: pcase-if-let?
Date: Tue, 17 Apr 2018 22:26:41 +0200

>
> P.S.: Here is the updated definition:
>
> #+begin_src emacs-lisp
> (defmacro pcase-if (clauses then &rest elses)
>   "Depending on CLAUSES, evaluate THEN or ELSES.
> CLAUSES is a list of the form \((PATTERN VALUE-FORM) ...)
> Successively try to match every `pcase' PATTERN against its
> VALUE-FORM.  When all match, eval THEN, else the
> ELSES."
>   (declare (indent 2)
>            (debug ((&rest (pcase-PAT &optional form))
>                    form body)))
>   (if (null clauses)
>       then
>     (let ((success-syms '()) (last-success-sym nil))
>       (dotimes (i (length clauses))
>         (push (make-symbol (format "matching-%d-success" i))
>               success-syms))
>       (cl-callf nreverse success-syms)
>       `(let ,(mapcar (lambda (s) `(,s nil)) success-syms)
>          (pcase nil
>            ((and ,@(mapcar
>                     (pcase-lambda (`(,pattern ,value))
>                       `(let (and ,@(and last-success-sym
>                                         `((guard ,last-success-sym)))
>                                  ,pattern
>                                  (let ,(setq last-success-sym
>                                              (pop success-syms))
>                                    t))
>                          ,value))
>                     clauses))
>             (if ,last-success-sym ,then ,@elses)))))))
> #+end_src
>
>
>


Hi,

about that new definition, is the following semantics what you expect?


(pcase-if
    ((`(,q . ,r) '())
     (`(,s . ,u) '(b c)))
    (list q r s u 'ok)
  'nope)
=>  nil


?
I would have expected 'nope instead.

Nathan



reply via email to

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