From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Israelsson Tampe Newsgroups: gmane.lisp.guile.devel Subject: Re: match-abs Date: Thu, 2 Sep 2010 20:07:04 +0200 Message-ID: <201009022007.05201.stefan.tampe@spray.se> References: <201008292356.42854.stefan.tampe@spray.se> <201009010930.02942.stefan.tampe@spray.se> <87occg9lvk.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1283450853 29260 80.91.229.12 (2 Sep 2010 18:07:33 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 2 Sep 2010 18:07:33 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Sep 02 20:07:32 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 1OrECC-000695-4I for guile-devel@m.gmane.org; Thu, 02 Sep 2010 20:07:32 +0200 Original-Received: from localhost ([127.0.0.1]:54103 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OrECB-0006vn-A0 for guile-devel@m.gmane.org; Thu, 02 Sep 2010 14:07:31 -0400 Original-Received: from [140.186.70.92] (port=57860 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OrEBr-0006td-Kg for guile-devel@gnu.org; Thu, 02 Sep 2010 14:07:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OrEBq-0006cN-8K for guile-devel@gnu.org; Thu, 02 Sep 2010 14:07:11 -0400 Original-Received: from spsmtp02oc.mail2world.com ([74.202.142.198]:1820) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OrEBq-0006bg-33 for guile-devel@gnu.org; Thu, 02 Sep 2010 14:07:10 -0400 Original-Received: from mail pickup service by spsmtp02oc.mail2world.com with Microsoft SMTPSVC; Thu, 2 Sep 2010 11:07:08 -0700 auth-sender: stefan.tampe@spray.se Original-Received: from 82.182.254.46 unverified ([82.182.254.46]) by spsmtp02oc.mail2world.com with Mail2World SMTP Server; Thu, 02 Sep 2010 11:07:05 -0700 User-Agent: KMail/1.13.5 (Linux/2.6.34-12-desktop; KDE/4.4.4; x86_64; ; ) In-Reply-To: <87occg9lvk.fsf@gnu.org> X-OriginalArrivalTime: 02 Sep 2010 18:07:08.0047 (UTC) FILETIME=[A82B19F0:01CB4AC9] X-detected-operating-system: by eggs.gnu.org: Windows 2000 SP4, XP SP1+ 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:10839 Archived-At: On Thursday, September 02, 2010 05:59:59 pm Ludovic Court=C3=A8s wrote: > Hi Stefan, >=20 > Stefan Israelsson Tampe writes: > > Anyway consider a list [a a b b] and let be a function so that > >=20 > > ( [a a b b]) -> (cons [a a] [b b]) > > ( [b b]) -> (cons [b b] []) > >=20 > > 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. >=20 > OK. >=20 > > Note, we could use a plain multiple return values protocol but that is > > for later discussion. > >=20 > > so using match-abs we would like the following > >=20 > > (match [a a b b] (( ) (append .r .r))) > >=20 > > to result in [b b a a]. >=20 > OK, but... >=20 > In (ice-9 match), a pattern like =E2=80=98(a b)=E2=80=99 matches any 2-el= ement list and > binds the first element to =E2=80=98a=E2=80=99 and the second to =E2=80= =98b=E2=80=99. Yeah, the <> construct is much more into line with the idea of match. My=20 point is that it can be a bit tough on the eyes to see the overall=20 pattern and I was suggesting prepair things in a header so that we still have some hygiene. But the header approach is more error prone to typos so <> is good for typos and header is good for logical errors. =20 > To match 2-element lists where each element satisfies a certain > predicate, say =E2=80=98p=E2=80=99, and bind the elements to =E2=80=98a= =E2=80=99 and =E2=80=98b=E2=80=99, one must write > =E2=80=98((and (? p) a) (and (? p) b))=E2=80=99. I think that (? p a) may be enough work :-) > The syntax you suggest here departs from this, right? It has a pointwise compainon in (=3D f (? id a))=20 if I'm not misstaken though. (take (define (f x) (match x ('a 'a) (_ #f))) and we have an obfuscation of an 'a match ... oh well a is bound to a' :-)) =09 > [...] >=20 > > One idea that is coded is to name the matchers and corresponding > > variables that is bound to leading to the suggested >=20 > Parse error. :-) >=20 > Could you rephrase this sentence? Here comes an idea (implemented but not solid in match-abs). Consider=20 describing a syntax element in a header as beeing special so that it=20 can stand by it self in the matcher without a surrounding context form. purist may not like it but it helps in spotting logical errors in longer matchers. Now this syntactic elements will bind a variable so let us use=20 a header of the form (( a1 a2) ...) to mean that in a matcher the result of the first match is bound to a1, the second to a2 etc. Let's call this header abstractions and get a match for like .... =20 > > (match abstractions (( .r1 .r2) ( .r)) > >=20 > > [a a b b a a] > > (( ) (append .r .r1 .r2))) >=20 > What=E2=80=99s =E2=80=98abstractions=E2=80=99 here? Is it the name of a = variable, and if so > what=E2=80=99s its value? Is it a literal =E2=80=98abstraction=E2=80=99 = interpreted as magic by > the =E2=80=98match=E2=80=99 macro? see above. > > 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. > >=20 > > 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 > >=20 > > (match [a a b b a a] > >=20 > > ([(<> .r1) (<> .r) (<> .r2)] > > =20 > > (append .r .r1> .r2))) >=20 > Hmm. So IIUC, the sub-pattern =E2=80=98(<> .r1)=E2=80=99 matches = anything that > is a match according to custom matcher =E2=80=98=E2=80=99, and binds t= he sub-match > =E2=80=98r1=E2=80=99 of =E2=80=98=E2=80=99 to =E2=80=98.r1=E2=80=99= , right? yes > Tricky... This do the trick :-) ((match-two abs v ((<> (f ...) p) . l) g+s sk fk i) (let ((res (f ... v))) (if (car res) (match-one abs (car res) g+s=20 (match-one (cdr res) l g+s sk fk) fk i) (isert-abs abs fk)))) But now I think it should be=20 ((match-two abs v ((<> f p) . l) g+s sk fk i) (let ((res (f v))) (if (car res) (match-one abs (car res) g+s=20 (match-one (cdr res) l g+s sk fk) fk i) (isert-abs abs fk)))) and demand currying in the protocol! > Thanks, > Ludo=E2=80=99. Have fun! Stefan