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: Wed, 1 Sep 2010 09:30:02 +0200 Message-ID: <201009010930.02942.stefan.tampe@spray.se> References: <201008292356.42854.stefan.tampe@spray.se> <87vd6rhfsc.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 1283326237 18025 80.91.229.12 (1 Sep 2010 07:30:37 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 1 Sep 2010 07:30:37 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Sep 01 09:30:33 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 1OqhmC-0000zr-Nb for guile-devel@m.gmane.org; Wed, 01 Sep 2010 09:30:33 +0200 Original-Received: from localhost ([127.0.0.1]:47573 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OqhmB-000268-PR for guile-devel@m.gmane.org; Wed, 01 Sep 2010 03:30:31 -0400 Original-Received: from [140.186.70.92] (port=52097 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oqhls-00023C-Kz for guile-devel@gnu.org; Wed, 01 Sep 2010 03:30:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oqhln-00039Q-0S for guile-devel@gnu.org; Wed, 01 Sep 2010 03:30:12 -0400 Original-Received: from spsmtp02oc.mail2world.com ([74.202.142.198]:2774) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oqhlm-00038x-Sc for guile-devel@gnu.org; Wed, 01 Sep 2010 03:30:06 -0400 Original-Received: from mail pickup service by spsmtp02oc.mail2world.com with Microsoft SMTPSVC; Wed, 1 Sep 2010 00:30:04 -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; Wed, 01 Sep 2010 00:30:02 -0700 User-Agent: KMail/1.13.5 (Linux/2.6.34-12-desktop; KDE/4.4.4; x86_64; ; ) In-Reply-To: <87vd6rhfsc.fsf@gnu.org> X-OriginalArrivalTime: 01 Sep 2010 07:30:04.0203 (UTC) FILETIME=[7E919FB0:01CB49A7] 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:10826 Archived-At: On Tuesday, August 31, 2010 12:55:15 am Ludovic Court=C3=A8s wrote: > Hmm, sorry, I don=E2=80=99t understand what you mean here. Can you come = up with > a simpler example? >=20 > What does =E2=80=98<>=E2=80=99 mean? Is there a connection between occur= rences of > =E2=80=98=E2=80=99 in patterns and the fact that the procedure is bou= nd to =E2=80=98=E2=80=99? >=20 > Thanks, > Ludo=E2=80=99. Don't be sorry, Communicating is not my strongest asset. 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=20 beeing false. 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=20 (match [a a b b] (( ) (append .r .r))) to result in [b b a a]. e.g. function retrurn in (cons [a a] [b b]), where .r is bounded=20 to the car, e.g. [a a] and [b b] is fed into the next one, . For which returns (cons [b b] []), where the car, e.g. [b b] is binded to .r and the cdr is matched aginst '() and the whole match succeeds and the resu= lt expressing is calcultaed yielding [b b a a]. Now, the construct is anaphoric and also some magic happens so that is understood as beeing a matcher abstraction. One idea that is coded is to name the matchers and corresponding variables that is bound to leading to the suggested=20 (match abstractions (( .r1 .r2) ( .r)) [a a b b a a] (( ) (append .r .r1 .r2))) Note how we use two times and the first time it is bound to .r1 and = the=20 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))) Now, this is more direct, it's simple to implement and are more general. But The resulting matchers are much harder to read and I would personally prefe= re=20 the header approach when using matchers in 90% of the cases. Now the rest of the previous mail just describes that we can send parameters down to the matcher to take full use of an abstraction.=20 Another interesting extension that I think You indicate is that one might w= ant=20 to use custom variants of car,cdr,pair?,equal? consider working of objects [List,Depth,Length] (#car [List,Depth,Length]) -> [(car List),(+ Depth 1),0] (#cdr [List,Depth,Length]) -> [(cdr List),Depth,(+ Length 1)] (#pair? [List,Depth,Length]) -> (pair? List) (#equal? [List,Depth,Length] A) -> (equal? List A) Now just generate the usual matcher and search and replace and we can track position and depth as we match. Kind of cool! Regards Stefan