From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel Subject: Re: pcase docs Date: Sat, 23 Jan 2016 13:05:22 +0100 Message-ID: <87mvrwzekd.fsf@web.de> References: <83a8o8gcya.fsf@gnu.org> <87zivx5ree.fsf@web.de> <87r3h95qs3.fsf@web.de> <83wpr15mk1.fsf@gnu.org> <8737toiota.fsf@web.de> <83fuxo5xo4.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1453550742 23320 80.91.229.3 (23 Jan 2016 12:05:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 23 Jan 2016 12:05:42 +0000 (UTC) Cc: jwiegley@gmail.com, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 23 13:05:33 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aMwwe-00009w-TC for ged-emacs-devel@m.gmane.org; Sat, 23 Jan 2016 13:05:33 +0100 Original-Received: from localhost ([::1]:57005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMwwe-0005es-6I for ged-emacs-devel@m.gmane.org; Sat, 23 Jan 2016 07:05:32 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMwwZ-0005eN-SX for emacs-devel@gnu.org; Sat, 23 Jan 2016 07:05:28 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMwwW-0004Xj-J5 for emacs-devel@gnu.org; Sat, 23 Jan 2016 07:05:27 -0500 Original-Received: from mout.web.de ([212.227.15.4]:59903) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMwwW-0004Xf-9N; Sat, 23 Jan 2016 07:05:24 -0500 Original-Received: from drachen.dragon ([92.77.162.209]) by smtp.web.de (mrweb002) with ESMTPSA (Nemesis) id 0MWinD-1abQu93aX5-00Xx9Q; Sat, 23 Jan 2016 13:05:23 +0100 In-Reply-To: <83fuxo5xo4.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 23 Jan 2016 13:43:07 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-Provags-ID: V03:K0:skRQTFXnlEA8RdIOBKJ8sjWuYzOXCSPHBUccG57iHKtP02zMGvI Cnvxj7PAF4A7i8JYFA+GRaV6N3bEiiYfhyGSWOxpa2w+rtd01yRkQZ+EASfLMP+jYRf7XTl NP5zgGxVtdORJS+n9FX+1SOhSxuEoIkf6+W983+Hyxfh72/SbrJPMUYOV/l0jX9R+F/XTW+ gROCghqmRo7UmeSjmMJPw== X-UI-Out-Filterresults: notjunk:1;V01:K0:21LpDmFaoqc=:Zm77zegbFmR8V5RT5WHXgZ EwgoqF7bXZL5Dis68O+9rDORXu+EeoRPx2/BNVtmr707XL4QvLurT7gGh44icLEJslmU4kGTS 2nl5IDl5Ti2gBS47Z88Y7GVqlby9rTf46vZVA94nB6L/gw9kJILNjU54vKRxL11DDrdBwH+iL 0h/zWoML89wHDPtzOHjuBQlmaCOkjF9kTwzzqmplGDtKpVczKknI2tT6GX7M11hbO/AA+RGX4 XmWfuGiJXRA4d4GlFuTLTJk5T/ZN1RoWrOCOw0f+dE4pAbyKmFUZ48cu35q+blEdrwnRuMDRY NVW//ieYOw1DH9EjKkMTbwwIQnA6tfWqUx7tZiVO9SwjC1Y00rcd3x1drQfaVHEnjeoZJrQVy 7o6dR6Ayb3yUqIneEQxhgexF0rGe/GWbz3s9ClIkuinsHg9N1BpR59saALSJIdllOwnRXDCr1 CEaVXie42HTi6e7Z4p6jyJlvfyYJqiIh2YknzNhJUHEWsGZZ1r/o5ElvUkGpqK9djDnie9ukc axPFPMMp0Ep5kiQfCaKqDmEGi5DNZ9tzuTM+Tks9V2pL4OWemt9ee8Kl9UY36zU4diNOPTNty l4oLL45o4KbHE6EjQr11j30gfp4T58roJMltWDJYLRTOudcZg0iZF1XqOxfWWXQQCTLElxwDT lXaXBw/haDGvZlNl21xvS3WnFDhA9RnirgnyfyzV+bYEOcGEkLrP/nHNfhRWp4lNiKQlHCTb4 IQofCcV7Od395H6eRw11sdMJK7Oc3PfNrOSAZpvsmDy+Wd2iWnK7VL7CiXRZrtIA7e64DRlg X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.15.4 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:198634 Archived-At: Eli Zaretskii writes: > Sorry, I don't understand: how can knowing what 'defmacro' does help > to know what 'pcase-defmacro' does? It works extremely analogous. > At the very least, one needs to know which patterns will be possible > after using 'pcase-defmacro', don't you agree? > > Btw, this macro also has "issues". The doc string is less than > helpful: > > "Define a new kind of pcase PATTERN, by macro expansion. > Patterns of the form (NAME ...) will be expanded according > to this macro." > > It says nothing about ARGS, and the "by macro expansion" part sounds > strange -- what useful information does it supply here? I agree that it's quite vague. > And if you turn to the users of this macro, in the hope of gaining > some understanding, you will see, for example, that map.el defines a > pattern whose NAME is "map": > > (pcase-defmacro map (&rest args) > "Build a `pcase' pattern matching map elements. > > The `pcase' pattern will match each element of PATTERN against > the corresponding elements of the map. > (btw: what PATTERN?), the pattern that is gotten by expanding. > but then uses it like this: > > (pcase type > (`list (map-pairs map)) > (`hash-table (map--into-hash-table map)) > (_ (error "Not a map type name: %S" type)))) (why does my definition look like `(and (pred mapp) ,@(map--make-pcase-bindings args)) ?) > IOW, it actually uses sub-classes of 'map' as patterns. Hmm... > As an aside, when I look at such doc strings, I always become > frustrated, because I must be extremely stupid to ask all these > questions, when no one else evidently cares, which must mean they all > understand this stuff, and only I alone don't, right? Surely not! I just had the time to read the code, carefully (I had to, to be able to write my el-search.el thing). Most others don't care because they just don't care, I think. Actually `pcase-defmacro' is easy to understand if you understood `defmacro': You define a pattern by its name and by the arguments it will accept. When the pcase "compiler" finds a pattern that is defined as a macro, it substitutes the "call" with the "code" returned by evaluating the macro definition with the given arguments. Exactly like Lisp macros are expanded by the lisp compiler. Just that we have pcase "code" (i.e., another pattern again) in this case. This is done recursively, i.e. the returned pattern can be a pcase macro, a include pcase macros, again, etc. Try to understand the definition of ` - it's a challenge, but if you succeed, you will see that things are much easier than you had expected. Michael.