| Acme-Lambda-Expr documentation | Contained in the Acme-Lambda-Expr distribution. |
Acme::Lambda::Expr - Lambda expressions
This document describes Acme::Lambda::Expr version 0.01
use strict; use feature 'say'; use Acme::Lambda::Expr qw(:all); my $f = $x * 2 + $y; say $f->(20, 2); # 20*2 + 2 = 42 my $g = curry $f, $x, 4; say $g->(19); # 18*2 + 4 = 42 my $h = curry deparse => $x; say $h->($f); # $f->deparse() say $h->($g); # $g->deparse() say $g->compile->(19); # => 42
This module provides lambda expressions.
Perl 5.8.1 or later.
No bugs have been reported.
Please report any bugs or feature requests to
bug-acme-lambda-expr@rt.cpan.org/, or through the web interface at
http://rt.cpan.org/.
Goro Fuji <gfuji(at)cpan.org>
Copyright (c) 2008, Goro Fuji <gfuji(at)cpan.org>. Some rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Acme-Lambda-Expr documentation | Contained in the Acme-Lambda-Expr distribution. |
package Acme::Lambda::Expr; use 5.008_001; use strict; use warnings; our $VERSION = '0.01'; use Acme::Lambda::Expr::Util qw(:all); use Acme::Lambda::Expr::Term; use Acme::Lambda::Expr::Placeholder; use Acme::Lambda::Expr::Value; use Acme::Lambda::Expr::Operators; use Acme::Lambda::Expr::Function; use Acme::Lambda::Expr::Method; use Acme::Lambda::Expr::Bound; use Exporter 'import'; our @EXPORT_OK = qw( placeholder value curry $x $y ); our %EXPORT_TAGS = ( all => \@EXPORT_OK, ); sub placeholder{ my $idx = shift; return Acme::Lambda::Expr::Placeholder->new(idx => $idx); } sub value{ return as_lambda_expr(@_); } sub curry{ my($subr, @args) = @_; if(is_lambda_expr($subr)){ return Acme::Lambda::Expr::Bound->new( function => $subr, args => \@args, ); } if(Data::Util::is_code_ref($subr)){ return Acme::Lambda::Expr::Function->new( function => $subr, args => \@args, ); } else{ my $invocant = shift @args; return Acme::Lambda::Expr::Method->new( method => $subr, invocant => $invocant, args => \@args, ); } } our $x = placeholder(0); our $y = placeholder(1); Internals::SvREADONLY($x, 1); Internals::SvREADONLY($y, 1); 1; __END__