From: ludo@gnu.org (Ludovic Courtès)
To: guile-devel@gnu.org
Subject: Re: match-abs
Date: Thu, 02 Sep 2010 17:59:59 +0200 [thread overview]
Message-ID: <87occg9lvk.fsf@gnu.org> (raw)
In-Reply-To: 201009010930.02942.stefan.tampe@spray.se
Hi Stefan,
Stefan Israelsson Tampe <stefan.tampe@spray.se> writes:
> 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.
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] ((<a> <b>) (append <b>.r <a>.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 ((<a> <a>.r1 <a>.r2) (<b> <b>.r))
> [a a b b a a]
> ((<a> <b> <a>) (append <b>.r <a>.r1 <a>.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 <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)))
Hmm. So IIUC, the sub-pattern ‘(<> <a> <a>.r1)’ matches anything that
is a match according to custom matcher ‘<a>’, and binds the sub-match
‘r1’ of ‘<a>’ to ‘<a>.r1’, right?
Tricky...
Thanks,
Ludo’.
next prev parent reply other threads:[~2010-09-02 15:59 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 ` match-abs Stefan Israelsson Tampe
2010-09-02 15:59 ` Ludovic Courtès [this message]
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=87occg9lvk.fsf@gnu.org \
--to=ludo@gnu.org \
--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).