php closure
call functions
- before first call
- function_exists false
- call of f(1. call von f)
- function_exists 1
- call of inF(2. call von inF)
- call of anonymous function in af(3. call af) use gVar = gVarEins, gArr[0] gArr 0 count=1
- call of anonymous function in ag(4. call ag) global gVar = gVarEins, gArr[0] gArr 0 count=1
- call of anonymous function in af(5. call af nach assign gVar=gVarZwei) use gVar = gVarEins, gArr[0] gArr 0 count=1
- call of anonymous function in ag(6. call ag nach assign gVar=gVarZwei) global gVar = gVarZwei, gArr[0] gArr 0 zwei count=2
- after last call
nested function
- runNest(nestOne) 1
- nest(nestOne) 2 v=useVal nestOne 1:, r=useRef nestOne 1:, appending n2
- run-nestOne-NestB(nestCalls#3) 4 v=useVal nestOne 1:, r=useRef nestOne 1:.n2, appending B4
- nest(nestOne) 5 v=useVal nestOne 1:.n2, r=useRef nestOne 1:.n2.B4, appending n5
- run-nestOne-NestC(nestCalls#6) 7 v=useVal nestOne 1:, r=useRef nestOne 1:.n2.B4.n5, appending C7
- nest(nestOne) 8 v=useVal nestOne 1:.n2.n5, r=useRef nestOne 1:.n2.B4.n5.C7
- run-nestOne-NestB(mainCalls9) 10 v=useVal nestOne 1:, r=useRef nestOne 1:.n2.B4.n5.C7, appending B10
- run-nestOne-NestC(mainCalls11) 12 v=useVal nestOne 1:, r=useRef nestOne 1:.n2.B4.n5.C7.B10, appending C12
- runNest(nestTwo) 13
- nest(nestTwo) 14 v=useVal nestTwo 13:, r=useRef nestTwo 13:, appending n14
- run-nestTwo-NestB(nestCalls#15) 16 v=useVal nestTwo 13:, r=useRef nestTwo 13:.n14, appending B16
- nest(nestTwo) 17 v=useVal nestTwo 13:.n14, r=useRef nestTwo 13:.n14.B16, appending n17
- run-nestTwo-NestC(nestCalls#18) 19 v=useVal nestTwo 13:, r=useRef nestTwo 13:.n14.B16.n17, appending C19
- nest(nestTwo) 20 v=useVal nestTwo 13:.n14.n17, r=useRef nestTwo 13:.n14.B16.n17.C19
- run-nestOne-NestB(mainCalls21) 22 v=useVal nestOne 1:, r=useRef nestOne 1:.n2.B4.n5.C7.B10.C12, appending B22
- run-nestTwo-NestC(mainCalls23) 24 v=useVal nestTwo 13:, r=useRef nestTwo 13:.n14.B16.n17.C19, appending C24
- run-nestOne-NestC(mainCalls25) 26 v=useVal nestOne 1:, r=useRef nestOne 1:.n2.B4.n5.C7.B10.C12.B22, appending C26
- run-nestTwo-NestB(mainCalls27) 28 v=useVal nestTwo 13:, r=useRef nestTwo 13:.n14.B16.n17.C19.C24, appending B28
church numerals
? |
0 ? 0 |
0 ? 1 |
0 ? 2 |
0 ? 3 |
0 ? 4 |
1 ? 0 |
1 ? 1 |
1 ? 2 |
1 ? 3 |
1 ? 4 |
2 ? 0 |
2 ? 1 |
2 ? 2 |
2 ? 3 |
2 ? 4 |
3 ? 0 |
3 ? 1 |
3 ? 2 |
3 ? 3 |
3 ? 4 |
num[r] |
0 -> 0 |
1 -> 1 |
2 -> 2 |
3 -> 3 |
4 -> 4 |
0 -> 0 |
1 -> 1 |
2 -> 2 |
3 -> 3 |
4 -> 4 |
0 -> 0 |
1 -> 1 |
2 -> 2 |
3 -> 3 |
4 -> 4 |
0 -> 0 |
1 -> 1 |
2 -> 2 |
3 -> 3 |
4 -> 4 |
scc(r) |
0 -> 1 |
1 -> 2 |
2 -> 3 |
3 -> 4 |
4 -> 5 |
0 -> 1 |
1 -> 2 |
2 -> 3 |
3 -> 4 |
4 -> 5 |
0 -> 1 |
1 -> 2 |
2 -> 3 |
3 -> 4 |
4 -> 5 |
0 -> 1 |
1 -> 2 |
2 -> 3 |
3 -> 4 |
4 -> 5 |
add(l, r) |
0 |
1 |
2 |
3 |
4 |
1 |
2 |
3 |
4 |
5 |
2 |
3 |
4 |
5 |
6 |
3 |
4 |
5 |
6 |
7 |
mult(l, r) |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
2 |
3 |
4 |
0 |
2 |
4 |
6 |
8 |
0 |
3 |
6 |
9 |
12 |
mulA(l, r) |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
2 |
3 |
4 |
0 |
2 |
4 |
6 |
8 |
0 |
3 |
6 |
9 |
12 |
powr(l, r) |
1 |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
2 |
4 |
8 |
16 |
1 |
3 |
9 |
27 |
81 |
powM(l, r) |
1 |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
2 |
4 |
8 |
16 |
1 |
3 |
9 |
27 |
81 |
End e19Closure.php
args
e19Closure.php
/home/ch45859/web/wlkl.ch/public_html/inf/php/e19Closure.php
*** code does not have a span berfore first <br>***<?php
require_once('env.php');
outBegin("php closure");
outH('call functions');
outUL('before first call');
outLi("function_exists", function_exists('inF'));
f('1. call von f');
echo "<li> function_exists " . function_exists('inF') . "</li>\n";
inF('2. call von inF');
$gVar = 'gVarEins';
$gArr = ['gArr 0'];
$af = function ($a) use ($gVar, $gArr) {
outLi("call of anonymous function in af($a) use gVar = $gVar, gArr[0] $gArr[0] count=" . count($gArr));
};
$ag = function ($a) {
global $gVar, $gArr;
outLi("call of anonymous function in ag($a) global gVar = $gVar, gArr[0] $gArr[0] count=" . count($gArr));
};
$af("3. call af");
$ag("4. call ag");
$gVar = 'gVarZwei';
$gArr[0] .= " zwei";
$gArr[1] = "1 zwei";
$af("5. call af nach assign gVar=$gVar");
$ag("6. call ag nach assign gVar=$gVar");
outULEnd("after last call");
outH('nested function');
outUL();
$nestCnt = 0;
$q1 = nest('nestOne');
$q1[0]('mainCalls' . ++$nestCnt);
$q1[1]('mainCalls' . ++$nestCnt);
$q2 = nest('nestTwo');
$q1[0]('mainCalls' . ++$nestCnt);
$q2[1]('mainCalls' . ++$nestCnt);
$q1[1]('mainCalls' . ++$nestCnt);
$q2[0]('mainCalls' . ++$nestCnt);
outULEnd();
function f ($a) {
outLi("call of f($a)");
function inF($b) {
outLi("call of inF($b)");
}
}
function nest ($a) {
global $nestCnt;
outLi("runNest($a)", ++$nestCnt);
$v = "useVal $a $nestCnt:";
$r = "useRef $a $nestCnt:";
$q = [function ($b) use($a, $v ,&$r) {
global $nestCnt;
outLi("run-$a-NestB($b)" , ++$nestCnt, "v=$v, r=$r, appending B$nestCnt");
$v .= ".B$nestCnt";
$r .= ".B$nestCnt";
},
function ($b) use($a, $v ,&$r) {
global $nestCnt;
outLi("run-$a-NestC($b)" , ++$nestCnt, "v=$v, r=$r, appending C$nestCnt");
$v .= ".C$nestCnt";
$r .= ".C$nestCnt";
}
];
outLi("nest($a)", ++$nestCnt, "v=$v, r=$r, appending n$nestCnt");
$v .= ".n$nestCnt";
$r .= ".n$nestCnt";
$q[0]('nestCalls#' . ++$nestCnt);
outLi("nest($a)", ++$nestCnt, "v=$v, r=$r, appending n$nestCnt");
$v .= ".n$nestCnt";
$r .= ".n$nestCnt";
$q[1]('nestCalls#' . ++$nestCnt);
outLi("nest($a)", ++$nestCnt, "v=$v, r=$r");
return $q;
}
outH('church numerals');
outTB();
tr("?", function($l, $r) {return "$l ? $r"; }, 'outTH');
function p1($x) { return ++$x; }
function n0 ($f, $z) { return $z; }
function n1 ($f, $z) { return $f($z); }
function n2 ($f, $z) { return $f($f($z)); }
$num = ['n0', 'n1', 'n2'
, function ($f, $z) {return $f(n2($f,$z));} , function ($f, $z) {return $f($f(n2($f, $z)));} ];
tr("num[r]", function($l, $r) {global $num; return "$r -> " . call_user_func($num[$r], 'p1', 0);});
function scc($a) { return function($f, $x) use ($a) {return $f($a($f, $x)); } ; }
function add($l, $r) { return function($f, $x) use ($l, $r) {return $l($f, $r($f, $x)); } ; }
function mult($l, $r) { return function($f, $x) use ($l, $r) {return $l(
function($y) use ($l, $r, $f) { return $r($f, $y); }
, $x); } ; }
function mulA($l, $r) { return function($f, $x) use($l, $r) { return $r(aL($l), 'n0')($f, $x); } ; }
function powr($l, $r) { return function($f, $x) use($l, $r) { return $r(
function($v) use($l) { return mult($l, $v);}, 'n1')($f, $x); } ; }
function powM($l, $r) { return function($f, $x) use($l, $r) { return $r(mL($l), 'n1')($f, $x); } ; }
tr("scc(r)", function($l, $r) {global $num; return "$r -> " . scc($num[$r])('p1', 0);});
outTCF('l', 'r');
tr("add(l, r)", function($l, $r) {global $num; return add($num[$l], $num[$r])('p1', 0);});
tr("mult(l, r)", function($l, $r) {global $num; return mult($num[$l], $num[$r])('p1', 0);});
tr("mulA(l, r)", function($l, $r) {global $num; return mulA($num[$l], $num[$r])('p1', 0);});
tr("powr(l, r)", function($l, $r) {global $num; return powr($num[$l], $num[$r])('p1', 0);});
tr("powM(l, r)", function($l, $r) {global $num; return powM($num[$l], $num[$r])('p1', 0);});
outTBEnd();
outEnd(__file__);
function aL($l) { return function($r) use($l) {return add($l, $r); } ; }
function mL($l) { return function($r) use($l) {return mult($l, $r); } ; }
function tr($h, $f, $td='outTD') {
outTR();
outTH($h);
for ($l=0; $l <=3; $l++)
for ($r=0; $r <=4; $r++)
$td($f($l, $r));
}