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:
Austin Hastings
Date:
April 10, 2003 10:20
Subject:
Re: alphabet-blind pattern matching (was Ruminating on RFC 93..)
Message ID:
20030410172007.99517.qmail@web12307.mail.yahoo.com

--- Jonathan Scott Duff <duff@cbi.tamucc.edu> wrote:
> On Wed, Apr 09, 2003 at 06:05:47PM -0700, Larry Wall wrote:
> > Though the danger of treating patterns as too powerful for just
> > text is that we run the risk of making patterns too powerful for
> text.
> > However lofty we aspire to get, we gotta keep our feet on the
> ground.
> 
> I agree completely. But I think this is an area where hard things can
> be possible.
> 
> The default rule engine should be optimized for homogeneous strings
> composed of characters as that's the common case. But if we can tell
> perl that our "string" is heterogeneous or that it's composed of
> object
> "characters" then it's free to use a different rule engine that
> doesn't make those assumptions and we've just made some nifty things
> possible.

Grammar WallStreet;

rule day
{
  /./   # Expects database stock-price data. See class Ticker.
}

rule trend(&xer_than)
{
  <day>   { $0.min = $1.min; $0.max = $1.max; }
  (
     <day> <(   &xer_than($1.min, $0.min) 
             && &xer_than($1.max, $0.max)   )> 
       { $0.max = $1.max; }
  )+
}

my $up_trend = rx/<trend(infix:>)/;
my $down_trend = rx/<trend(infix:<)/;

my $buy_signal = rx/<$down_trend><$up_trend> <( $2.length == 1 )>/;
my $sell_signal = rx/<$up_trend><$down_trend> <( $2.length == 1)>/;

broker()
{
   my $wire = new Stock::Ticker('NYSE');

   given $wire
   {
      when <$buy_signal> { buy(); }
      when <$sell_signal> { sell(); }
   }
}

Nifty is one way to put it...

=Austin


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