[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Thu, 02 Sep 2010 17:59:59 +0200
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Stefan Israelsson Tampe <address@hidden> 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.
> 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].
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
> 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?
- Re: match-abs, Stefan Israelsson Tampe, 2010/09/01
- Re: match-abs,
Ludovic Courtès <=