A freelance software engineer with experience in webapplications, databases and bioinformatics.
A contributor to Parrot and the person behind Pipp.
A physicist who worked with third sound in Helium-III and CCD X-ray detectors.
barney on irc.perl.org
github: http://github.com/bschmalhofer [github.com]
LinkedIn:http://www.linkedin.com/in/bernhardschmalhofer [linkedin.com]
XING: https://www.xing.com/profile/Bernhard_Schmalhofer [xing.com]
In the last days I have been working on supporting closures for Pipp. Yes, you've read correctly. The next version of PHP will support real closures. See
http://www.ibm.com/developerworks/opensource/library/os-php-5.3new2/index.html?
Closures are connected with lexical variables, so I had I had to rethink the way I handle variables in Pipp. Initially I had the variables outside functions as package variables. Since this doesn't play well with closures, and as there are problems with included files, I changed those to lexical variables. This was the major part of the work. Thanks to Patrich Michaud for advising me where I should define the lexicals.
After switching to lexicals everywhere I followed my usual approach and tried to do the same as Rakudo does. This worked without hassle for a simple case.
<?php
function gen_indentor ( ) {
$indention = '+';
$indentor = function ($line) use ($indention) {
echo $indention . $line . "\n";
};
return $indentor;
}
$sub_1 = gen_indentor();
$sub_1('one plus');
?>
correctly gives:
+one plus
But when I create a second closure I run into problems.
<?php
function gen_indentor ($indention) {
$indentor = function ($line) use ($indention) {
echo $indention . $line . "\n";
};
return $indentor;
}
$sub_1 = gen_indentor('+');
$sub_4 = gen_indentor('++++');
$sub_1('one plus');
$sub_2('four plusses');
?>
incorrectly gives:
++++one plus
++++four plusses
Looks like I need to fiddle some more.
Closures for Pipp 0 Comments More | Login | Reply /