Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

New module, Sub::Lambda
Hi, I wrote two modules that try to provide syntactic sugar for
lambdas in Perl.

The standard syntax for lambdas is to use subrefs, like this:

sub { do_something_with($_[0]) }

This works just fine, however it gets ugly for curried functions.

One way to solve the problem is with a function fn, which Sub::Lambda
provides:

(fn a => fn b => '$a+$b')->(1)->(2)      #=3
(fn qw(a b) => '$a+$b')->(1, 2)            #= 3
(fn qw(h -t) => '{$h=>[@t]}')->(1,2,3,4)  #= {1 => [2,3,4]}

Together with ap for application, you can take it as far as defining
the applicative-order Y combinator:

*Y = fn m => ap(
(fn f => ap m => fn a => ap qw(f f a)) =>
(fn f => ap m => fn a => ap qw(f f a))
);

The second, more experimental module, Sub::Lambda::Filter, uses source
filtering to extend Perl syntax with Haskell'ish lambdas.

With that, Y looks more like it should:

use Sub::Lambda::Filter;
my $fac = (\f -> \n -> { ($n<1) ? 1 : $n*$f->($n-1) });
my $Y   = (\m -> (\f -> m (\a -> f f a)) (\f -> m (\a -> f f a)));
print $Y->($fac)->(5) . "\n";  # 120 = 5!

There are yet some issues with Sub::Lambda::Filter as it takes a few
shortcuts to correctly parsing the Perl code it filters. I have not
found a ready Perl parser in Perl, is there one?

Let me know what you think.

I did the upload to CPAN but the module is not appearing yet - maybe
it's the cache, or maybe I messed something up as it's my first CPAN
upload; you can now check out both  module here:

http://ha4.fajno.net/dev/Perl/CPAN/Sub-Lambda/

Or, if you have darcs,

darcs get http://ha4.fajno.net/dev



Cheers,

--Anton


Report this thread to moderator Post Follow-up to this message
Old Post
Антон Таяновский
03-19-08 12:01 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Modules archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:14 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.