develooper Front page | perl.perl6.language | Postings from April 2003

Re: alphabet-blind pattern matching (was Ruminating on RFC 93..)

Thread Previous | Thread Next
From:
Jonathan Scott Duff
Date:
April 10, 2003 07:31
Subject:
Re: alphabet-blind pattern matching (was Ruminating on RFC 93..)
Message ID:
20030410093104.B21682@cbi.tamucc.edu
On Wed, Apr 09, 2003 at 09:01:25PM -0400, Joseph F. Ryan wrote:
> And then you could do:
> 
>     use Colorific qw(Blue Cloud);
> 
>     my Colorific @skysamples = peek_with_some_hardware;
>     my $clear_day = @skysamples ~~ /<Blue>* <Cloud>/;
> 
> Which ain't too bad, in my book. (-:

That is pretty nifty, but how would you say something like "match 2 blue
things, then a thing that isa Bird, then something that can fly"? Your
way puts all of the logic in the pattern method when it's probably
better in the rule itself, especially if the stream of objects we're
matching against is heterogeneous:

	@things ~~ /<.color(Blue)><2><.isa(Bird)><.can(fly)>/;

versus 

	@things ~~ /<Blue><2><Bird><fly>/;

Imagine that @things contains 2 X objects and 2 Y objects that would
cause the match to succeed. The pattern method for the Y object would
have to somehow handle both the .isa and .can ideas.  How would it
know which to apply when?

-Scott
-- 
Jonathan Scott Duff
duff@cbi.tamucc.edu

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About