emacs-devel
[Top][All Lists]
Advanced

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

RE: The poor state of documentation of pcase like things.


From: Drew Adams
Subject: RE: The poor state of documentation of pcase like things.
Date: Fri, 1 Jan 2016 19:51:39 -0800 (PST)

> >      (pcase skip
> >        (`nil nil)
> >        (`0 t)
> >        (_ (setq i (+ i skip -1)) (funcall get-next-frame)))
> 
> (cond ((null skip))
>       ((eq skip 0) t)
>       (t (setq i (+ i skip -1))
>          (funcall get-next-frame)))

Agreed.  If you don't need decomposition by pattern matching,
why would you need `pcase'?

(But as pointed out, the first clause should be ((null skip) nil).

(The `cond' is 10 chars more to type in this case, not counting
insignificant whitespace.  But that is not important.)

Or:

(cl-case skip
  ((nil) nil)
  (0 t)
  (t (setq i (+ i skip -1)) (funcall get-next-frame)))

(Same number of chars as `pcase'.  Or 3 fewer, if you use alias\
`case'.  But, again, not important.)

Or:

(and skip  (or (eql 0 skip)
               (progn (setq i  (+ i skip -1))
                      (funcall get-next-frame))))

(3 chars more than the `pcase'.  But not important.)

> Not much difference. Also, `0 could just be 0.
> 
> One thing it does do: avoids repeating "skip" in the first two tests. That's
> the only merit I can see, but would have been more worthwhile if there were,
> say, 10 value tests.

The same is true of `cl-case' (it is one of the reasons for
that macro).  But otherwise, just use `let':

(let ((sk  skip))
  (and sk  (or (eql 0 sk)
               (progn (setq i  (+ i skip -1))
                      (funcall get-next-frame))))



reply via email to

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