From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: EXPVAL in pcase-defmacro docstrings Date: Mon, 04 Jun 2018 10:43:29 -0400 Message-ID: References: <87y3fzx49l.fsf@gnuvola.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1528123345 22906 195.159.176.226 (4 Jun 2018 14:42:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 4 Jun 2018 14:42:25 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jun 04 16:42:21 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fPqgb-0005kK-No for ged-emacs-devel@m.gmane.org; Mon, 04 Jun 2018 16:42:17 +0200 Original-Received: from localhost ([::1]:40127 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPqih-0007ay-5g for ged-emacs-devel@m.gmane.org; Mon, 04 Jun 2018 10:44:27 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56257) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPqhz-0007aX-U2 for emacs-devel@gnu.org; Mon, 04 Jun 2018 10:43:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPqhw-0007Jh-Q3 for emacs-devel@gnu.org; Mon, 04 Jun 2018 10:43:43 -0400 Original-Received: from [195.159.176.226] (port=40268 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPqhw-0007JJ-I5 for emacs-devel@gnu.org; Mon, 04 Jun 2018 10:43:40 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fPqfl-0004oP-Si for emacs-devel@gnu.org; Mon, 04 Jun 2018 16:41:25 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 52 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:mkDPcpKIVbbRk+oY0uOQ8lkuYOU= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:225995 Archived-At: > Yes. That is awkward, when reading the source code. Thanks for > pointing it out; i was focusing on the aggregated docstring for > that change. For docstrings where it makes sense to use EXPVAL > (maybe not this one), how about we add a small comment pointing > to the EXPVAL convention? That way, we retain consistency in > the presentation (for ‘C-h f pcase RET’), and give a clue to > people who read source code. As mentioned, I think "target" is the standard terminology, so we could use that. Of course, there might be cases where EXPVAL would work better, but I don't think we need to encourage people to use EXPVAL nor to decide how best to use it when it makes sense because it will likely depend on the specifics. > ;; FIXME: We'd like to use a negative pattern (not consp), > ;; but pcase doesn't support it. Using `atom' works but > ;; generates sub-optimal code. > `(or `(t . ,,vpat) (and (pred atom) ,vpat)))) > > Does that mean we'd want a hypothetical ‘(pred (not consp))’ if > such a construct were supported by ‘pcase’? The idea was to use `(or `(t . ,,vpat) (and (not (pred consp)) ,vpat)))) Strictly speaking I'm very happy with the appearance of the current code, the comment is only about the resulting macroexpansion because pcase doesn't understand that (atom X) and (consp X) are mutually exclusive. But you're right that maybe a halfway solution would be `(or `(t . ,,vpat) (and (pred (not consp)) ,vpat)))) which might be much easier to implement (in the sense that it might be reasonably easy to add code to the handling of `pred` so it treats negation efficiently). > Another question i have concerns ‘(t . ...)’. My understanding This is used for leaves whose *value* is itself a `cons`. E.g. compare (radix-tree-insert nil "ab" '42) and (radix-tree-insert nil "ab" '(42)) So indeed the `t` is used because it's not a string so it shouldn't match any normal code's `car`. Stefan