Call by name, yes. Lazy evaluation, no.

--
Shmuel (Seymour J.) Metz
http://mason.gmu.edu/~smetz3

________________________________________
From: IBM Mainframe Assembler List <ASSEMBLER-LIST@listserv.uga.edu> on behalf 
of Martin Ward <mar...@gkc.org.uk>
Sent: Monday, February 12, 2018 6:56 AM
To: ASSEMBLER-LIST@listserv.uga.edu
Subject: Call by name

If you want to play with call by name (or lazy evaluation)
you can implement it in perl by passing a reference to a subroutine:

FUNC1 (BY NAME A, BY REFERENCE B, BY VALUE C){...}
RESULT = FUNC1 (RAND (5), MYVARNAME1, 7)

can be implemented:

#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
sub funct1($$$);

my $myvarname1 = 42;
print "Calling funct1:\n";
funct1(sub { rand(5) }, \$myvarname1, 7);

sub funct1($$$) {
   my ($A, $B, $C) = @_;
   printf("1st: A+B+C = %f\n", &$A + $$B + $C);
   printf("2nd: A+B+C = %f\n", &$A + $$B + $C);
}

--
                        Martin

Dr Martin Ward | Email: mar...@gkc.org.uk | http://www.gkc.org.uk
G.K.Chesterton site: http://www.gkc.org.uk/gkc | Erdos number: 4

Reply via email to