GNU bug report logs -
#31311
27.0; doc of `pcase'
Previous Next
Reported by: Drew Adams <drew.adams <at> oracle.com>
Date: Sun, 29 Apr 2018 16:04:02 UTC
Severity: wishlist
Found in version 27.0
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
Thien-Thi Nguyen <ttn <at> gnu.org> writes:
> Also, ‘pcase’ is the only conditional construct that takes a
> first arg and evaluates it (like ‘case’). The new text explains
> its hybrid nature (‘cond’ and ‘case’) in more detail.
The manual should refer to `cl-case', not `case'. I don't think pcase
should be referred to as a hybrid of cond and cl-case; maybe a hybrid of
cond and cl-destructuring-bind. Or perhaps: like cl-case, only more so.
> +These render @code{case} unsuitable for strings or compound
> +data structures (e.g., lists or vectors).
> +For that, why not use @code{cond}? Wait, what? @dots{}
I guess this is supposed to be funny, but I think it might confuse the
reader.
> +(defun grok/traditional (obj)
> + (if (and (stringp obj)
> + (string-match "^key:\\([[:digit:]]+\\)$" obj))
> + (match-string 1 obj)
> + (list "149" 'default)))
> +(defun grok/pcase (obj)
> + (pcase obj
> + ((or ; @r{line 1}
> + (and ; @r{line 2}
> + (pred stringp) ; @r{line 3}
> + (pred (string-match ; @r{line 4}
> + "^key:\\([[:digit:]]+\\)$")) ; @r{line 5}
> + (app (match-string 1) ; @r{line 6}
You have to pass the original string to match-string.
> + val)) ; @r{line 7}
> + (let val (list "149" 'default))) ; @r{line 8}
> + val))) ; @r{line 9}
This doesn't seem like a great example of pcase usage. Not sure if you
want to introduce the extended `rx' pattern here, but it works better
for this, IMO:
(pcase x
((and (pred stringp)
(rx bol "key:" (let val (+ (any digit))) eol))
val)
(_ 'default))
This bug report was last modified 3 years and 24 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.