From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: match-abs Date: Thu, 02 Sep 2010 17:59:59 +0200 Message-ID: <87occg9lvk.fsf@gnu.org> References: <201008292356.42854.stefan.tampe@spray.se> <87vd6rhfsc.fsf@gnu.org> <201009010930.02942.stefan.tampe@spray.se> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1283444711 1965 80.91.229.12 (2 Sep 2010 16:25:11 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 2 Sep 2010 16:25:11 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Sep 02 18:25:10 2010 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OrCb0-0001cs-F0 for guile-devel@m.gmane.org; Thu, 02 Sep 2010 18:25:02 +0200 Original-Received: from localhost ([127.0.0.1]:56830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OrCMK-0001Ej-5z for guile-devel@m.gmane.org; Thu, 02 Sep 2010 12:09:52 -0400 Original-Received: from [140.186.70.92] (port=44420 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OrCDE-0006mV-3A for guile-devel@gnu.org; Thu, 02 Sep 2010 12:00:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OrCD3-0005t1-SU for guile-devel@gnu.org; Thu, 02 Sep 2010 12:00:19 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:33030) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OrCD3-0005sb-F3 for guile-devel@gnu.org; Thu, 02 Sep 2010 12:00:17 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OrCCz-0001z6-La for guile-devel@gnu.org; Thu, 02 Sep 2010 18:00:13 +0200 Original-Received: from yoda.fdn.fr ([80.67.169.18]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 02 Sep 2010 18:00:13 +0200 Original-Received: from ludo by yoda.fdn.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 02 Sep 2010 18:00:13 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 71 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: yoda.fdn.fr X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 16 Fructidor an 218 de la =?iso-8859-1?Q?R=E9volutio?= =?iso-8859-1?Q?n?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Cancel-Lock: sha1:xPrloUvmARRCNm1DAM0XoARk4r0= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:10837 Archived-At: Hi Stefan, Stefan Israelsson Tampe writes: > Anyway consider a list [a a b b] and let be a function so that > > ( [a a b b]) -> (cons [a a] [b b]) > ( [b b]) -> (cons [b b] []) > > e.g. macthes a sequence of a:s and macthes a sequence of b:s. a > failure in this protocol is represented by the car of the retruning cons > beeing false. OK. > Note, we could use a plain multiple return values protocol but that is for > later discussion. > > so using match-abs we would like the following > > (match [a a b b] (( ) (append .r .r))) > > to result in [b b a a]. OK, but... In (ice-9 match), a pattern like ‘(a b)’ matches any 2-element list and binds the first element to ‘a’ and the second to ‘b’. To match 2-element lists where each element satisfies a certain predicate, say ‘p’, and bind the elements to ‘a’ and ‘b’, one must write ‘((and (? p) a) (and (? p) b))’. The syntax you suggest here departs from this, right? [...] > One idea that is coded is to name the matchers and corresponding variables > that is bound to leading to the suggested Parse error. :-) Could you rephrase this sentence? > (match abstractions (( .r1 .r2) ( .r)) > [a a b b a a] > (( ) (append .r .r1 .r2))) What’s ‘abstractions’ here? Is it the name of a variable, and if so what’s its value? Is it a literal ‘abstraction’ interpreted as magic by the ‘match’ macro? > Note how we use two times and the first time it is bound to .r1 and the > second time it's result is bound to .r2. > > Now putting some semmatics in a header can make the matchers themselves look > cleaner and save on vertical space. In match-abs there is an alternative way > of express this acording to > > (match [a a b b a a] > ([(<> .r1) (<> .r) (<> .r2)] > (append .r .r1> .r2))) Hmm. So IIUC, the sub-pattern ‘(<> .r1)’ matches anything that is a match according to custom matcher ‘’, and binds the sub-match ‘r1’ of ‘’ to ‘.r1’, right? Tricky... Thanks, Ludo’.