Currying functions

Currying functions

Post by greg » Wed, 30 Jul 2003 10:27:05

:> > other languages like Python and Java use a more OO (and efficient) way
:> > of caching the pattern than using the method I described.
:> Why do you say "more efficient"

: All I was trying to say (and I didn't explain this very well) was that
: partial application does no actual computation, so if you partially apply a
: regex match function with a particular pattern (assuming pattern means a
: string, not a compiled regex), the regex could potentially be recompiled for
: each iteration.

That is probably the case for the Perl version (score one against
writing Perl in a functional style) but the Haskell version will
compile it the first time it is _used_ and then never again. That's
just as efficient in the general case and more efficient if your
list is empty.


Currying functions

Post by Ed Avi » Thu, 31 Jul 2003 21:37:15

Marcin 'Qrczak' Kowalczyk < XXXX@XXXXX.COM > writes:

Apologies - I was still thinking about olden days when qr// didn't
exist. Yes, it seems you can do

my $letter = 'a';
my $r0 = qr/$letter/;
$letter = 'b';
my $r1 = qr/$letter/;

for (qw(a b)) {
print "testing $_\n";
print "r0\n" if $_ =~ $r0;
print "r1\n" if $_ =~ $r1;

So it looks like the regexp is compiled when qr// is evaluated. This
is a much simpler way to get dynamically-generated (yet compiled once)
regular expressions than the old way of using closures.