From: Stefan Israelsson Tampe <stefan.tampe@spray.se>
To: guile-devel@gnu.org
Subject: Re: match-abs
Date: Wed, 1 Sep 2010 09:30:02 +0200 [thread overview]
Message-ID: <201009010930.02942.stefan.tampe@spray.se> (raw)
In-Reply-To: <87vd6rhfsc.fsf@gnu.org>
On Tuesday, August 31, 2010 12:55:15 am Ludovic Courtès wrote:
> Hmm, sorry, I don’t understand what you mean here. Can you come up with
> a simpler example?
>
> What does ‘<>’ mean? Is there a connection between occurrences of
> ‘<op>’ in patterns and the fact that the procedure is bound to ‘<op>’?
>
> Thanks,
> Ludo’.
Don't be sorry, Communicating is not my strongest asset.
Anyway consider a list [a a b b] and let <a> be a function so that
(<a> [a a b b]) -> (cons [a a] [b b])
(<b> [b b]) -> (cons [b b] [])
e.g. <a> macthes a sequence of a:s and <b> macthes a sequence of b:s. a
failure in this protocol is represented by the car of the retruning cons
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
(match [a a b b] ((<a> <b>) (append <b>.r <a>.r)))
to result in [b b a a].
e.g. function <a> retrurn in (cons [a a] [b b]), where <a>.r is bounded
to the car, e.g. [a a] and [b b] is fed into the next one, <b>. For which
<b> returns (cons [b b] []), where the car, e.g. [b b] is binded to <b>.r
and the cdr is matched aginst '() and the whole match succeeds and the result
expressing is calcultaed yielding [b b a a].
Now, the construct is anaphoric and also some magic happens so that <a> 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
(match abstractions ((<a> <a>.r1 <a>.r2) (<b> <b>.r))
[a a b b a a]
((<a> <b> <a>) (append <b>.r <a>.r1 <a>.r2)))
Note how we use <a> two times and the first time it is bound to <a>.r1 and the
second time it's result is bound to <a>.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]
([(<> <a> <a>.r1) (<> <b> <b>.r) (<> <a> <a>.r2)]
(append <b>.r <a>.r1> <a>.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 prefere
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.
Another interesting extension that I think You indicate is that one might want
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
next prev parent reply other threads:[~2010-09-01 7:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-29 21:56 match-abs Stefan Israelsson Tampe
2010-08-30 22:55 ` match-abs Ludovic Courtès
2010-08-31 14:42 ` match-abs Ludovic Courtès
2010-09-01 9:34 ` match-abs Stefan Israelsson Tampe
2010-09-01 12:05 ` match-abs Ludovic Courtès
2010-09-01 7:30 ` Stefan Israelsson Tampe [this message]
2010-09-02 15:59 ` match-abs Ludovic Courtès
2010-09-02 18:07 ` match-abs Stefan Israelsson Tampe
2010-09-02 18:53 ` match-abs Stefan Israelsson Tampe
2010-09-02 22:46 ` match-abs Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201009010930.02942.stefan.tampe@spray.se \
--to=stefan.tampe@spray.se \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).