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:
Paul
Date:
April 9, 2003 14:42
Subject:
Re: alphabet-blind pattern matching (was Ruminating on RFC 93..)
Message ID:
20030409214224.55955.qmail@web41210.mail.yahoo.com

Long post included in its entirety below -- sorry, it just seemed
relevant as a big block..

So, maybe I'm off-base, and please feel free to ignore me....
But I think I'd rather see something like this:

 use Colorific qw(Blue BlazingWhite);
 my Colorific @skysamples = peek_with_some_hardware; 
 my $clear_day ||= ($_ ~~ /<Blue><BlazingWhite>/) for @skysamples;

The whole idea of smart matching on sets hasn't quite settled into a
comfy spot in my brain yet.

--- Jonathan Scott Duff <duff@cbi.tamucc.edu> wrote:
> On Wed, Apr 09, 2003 at 01:05:12PM -0700, Yary Hluchan wrote:
> > What I want is something like:
> >   use Colorific qw(Blue BlazingWhite);
> >   rule same_color($color is Colorific) {
> >     (.) { fail unless $1.looks_like($color); }
> >   }
> >   my Colorific @skysamples = peek_with_some_hardware; 
> >   my $clear_day = @skysamples =~
> > m:sequential_objects/<same_color(Blue)><same_color(BlazingWhite)>/;
> > 
> > In this hypothetical example, there's a "sequential_objects"
> > modifier that treats "@skysamples" as a sequential list of objects,
> > instead of a list of independent strings to grep through. It also
> > tells the "." not to stringify its input.  Then the "color" rule
> > isn't needed to unpack the property of the dummy char anymore. And,
> > the whole thing is cleaner!
> 
> I think this problem is isomorphic with the "generic equality"
> problem.  There's no "generic match" really.  You have to decide what
> things you want to match.  Are you matching class names?  Are you
> matching specific object attributes?  Are you matching object value?
> Are you matching string representations?  Et cetera.
> 
> So, you need at least two things: a way to specify your atoms are
> objects and a way to say what about those objects you are matching.
> You have the first of these quite well with your :sequential_objects
> modifier (though I'd probably call it :uo or maybe :obj), but your
> example is lacking good support for the second I think. It seems like
> you'd be doing a lot of dot matching in order to get the object to
> select the matching criteria.
> 
> What *I'd* like to write instead of your example above, is something
> like this:

> 	use Colorific qw(Blue BlazingWhite);
> 	my Colorific @skysamples = peek_with_some_hardware; 
> 	my $clear_day = @skysamples ~~
> 	    m:obj/<.looks_like(Blue)><.looks_like(BlazingWhite)>/;
> 
> or maybe this if looks_like could be an is-a relationship:
> 	
> 	my $clear_day = @skysamples ~~ m:obj/<Blue><BlazingWhite>/;
> 
> or maybe this:
> 
> 	my $clear_day = @skysamples ~~
> m:obj(looks_like)/<Blue><BlazingWhite>/;
> 
> Where once the parser knows it's dealing with "objects", it can
> Huffmanly decide what "match" means or be explicitly told what
> "match" means and each atom becomes the topic for the current
> assertion.
> 
> I like the first of my examples above because then it's easy to vary
> the idea of matchiness on a per-assertion basis.  Zero or more
> samples that looks_like Blue, followed by a sample that contains
> a cloud could be written something like this:
> 
> 	my $clear_day = @skysamples ~~
> 	    m:obj/<.looks_like(Blue)>* <.contains(Cloud)>/;
> 
> caveat lector, I'm just muddling through  :-)
> 
> -Scott
> -- 
> Jonathan Scott Duff
> duff@cbi.tamucc.edu


__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.com

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