#!/usr/bin/perl
#
# eg9: closure example - timesn(N) function factory
#

use strict;
use warnings;
use Function::Parameters qw(:strict);

#
# my $f = timesn( $n ):
#	returns a function (code ref) which will
#	(when called) multiple it's argument by $n
#
fun timesn($n)
{
	return fun ($x) { return $n * $x };
}

my $doubler = timesn(2);
my $d = $doubler->(10);		# 20

my $tripler = timesn(3);
my $t = $tripler->(10);		# 30

print "d=$d, t=$t\n";
