• Home
  • Popular Downloads
  • Contact Us
  • Submit

Softpile

Free Downloads

Main Navigation
  • Home
  • Windows
  • Mac OS X
  • Business
  • Desktop
  • Development
  • Education
  • Games
  • Internet
  • Multimedia
  • Utilities
Home » Linux » Scalar::Lazy

Scalar::Lazy

June 19, 2009
Yet another lazy evaluation in Perl
Version: 0.03
License: Perl Artistic License
Operating System: Linux
Homepage: search.cpan.org
Developed by: Dan Kogai
Scalar::Lazy is yet another lazy evaluation in Perl.

SYNOPSIS

 use Scalar::Lazy;
 my $scalar = lazy { 1 };
 print $scalar; # you don't have to force

 # Y-combinator made easy
 my $zm = sub { my $f = shift;
 sub { my $x = shift;
 lazy { $f->($x->($x)) }
 }->(sub { my $x = shift;
 lazy { $f->($x->($x)) }
 })};
 my $fact = $zm->(sub { my $f = shift;
 sub { my $n = shift;
 $n < 2 ? 1 : $n * $f->($n - 1) } });
 print $fact->(10); # 3628800

DISCUSSION

The classical way to implement lazy evaluation in an eager-evaluating languages (including perl, of course) is to wrap the value with a closure:

 sub delay{
 my $value = shift;
 sub { $value }
 }
 my $l = delay(42);

Then evaluate the closure whenever you need it.

 my $v = $l->();

Marking the variable lazy can be easier with prototypes:

 sub delay(&){ $_[0] }
 my $l = delay { 42 }

But forcing the value is pain in the neck.

This module makes it easier by making the value auto-forcing.
evaluation lazy evaluation perl perl module scalar scalar evaluation
Free Download 4K
0
  • Share on:

Scalar::Lazy User Reviews

Sponsored

Categories

  • Linux

Related Downloads

Bio::SeqIO::game::seqHandler
A class for handling game-XML sequences
Apache2::AuthenSecurID::Auth
Authentication handler for Apache2::AuthenSecurID
Net::NIS
Interface to Sun's Network Information Service
Text::EmacsColor
Syntax-highlight code snippets with Emacs
Inside
Find out what's inside your Perl installation
Copyright © 1999-2017 Softpile Free Downloads
  • Contact Us
  • Submit
  • Privacy Policy
  • Disclaimer
  • Terms of Use