LISP::Lambda - Perl extension for implementing Lisp Lambda expressions


NAME

LISP::Lambda - Perl extension for implementing Lisp Lambda expressions


SYNOPSIS

  use LISP::Lambda;
  my $lambda = LISP::Lambda->new(\&sub);
  $lambda->mapcar(@lists)
  $lambda->apply($list);


DESCRIPTION

Lambda expressions are Lisp's version of anonymous subroutines, and may be blessed into this package so that you can use them or the provided 'meta-methods' in an object oriented way. If you want to want to use them as regular functions, you may export them. Any reference to lists here refers to linked lists ala Lisp, and not to perl lists/arrays.

Methods

        mapcar(FUNCTION, LISTS)
                mapcar applies the FUNCTION to the list formed by the first
                element of each list, then to the second, etc., up to the
                length of the shortest list, and returns a list of the results.
                $list = LISP->new([[a],[b],[c],[d]]); # ((a) (b) (c) (d))
                $car  = $list->can('car');
                $cars = $car->mapcar($list);
                print   $cars->string;                # Prints (a b c d);
                $list1  = LISP->new([qw(1 2 3)]]);
                $list2  = LISP->new([qw(4 5 6)]]);
                $lister = $list1->can('list');
                $list3  = mapcar($lister, $list1, $list2);
                print $list3->string       # Prints ((1 4) (2 5) (3 6))
        apply(FUNCTION, LIST)
                apply returns the result of executing FUNCTION using the subnodes of
                LIST as arguments.
                $list      = LISP->new([qw(1 2 3)]);
                $totaller  = sub { my $total=0; $total += $_ for @_; $total };
                print apply($totaller, $list);   # Prints 6
                $inc = LISP->new(sub { map {$_ + 1} @_ });
                my @ary = $inc->apply($list);
                print "@ary";     # Prints 2 3 4

EXPORT

        :all
                 exports methods mapcar and apply, and each may be exported individually.


AUTHOR

Douglas Wilson, dwilson@gtemail.net


SEE ALSO

perl(1).