Man or boy test: Difference between revisions

m
Tweak irregular header markup
(→‎{{header|Phix}}: added syntax colouring, and a p2js compatible translation of the Go entry)
m (Tweak irregular header markup)
Line 3,095:
say obj.a(10, ->{1}, ->{-1}, ->{-1}, ->{1}, ->{0});</lang>
 
=={{header|Smalltalk}} ==
 
Number>>x1: x1 x2: x2 x3: x3 x4: x4 x5: x5
Line 3,206:
println(A(10, {1}, {-1}, {-1}, {1}, {0}))</lang>
 
=={{header|Tcl}} ==
 
There are two nontrivial features in the "man or boy" test. One is that the parameters ''x1'' though ''x5'' are in general going to be function calls that don't get evaluated until their values are needed for the addition in procedure A, which means that these in Tcl are going to be scripts, and therefore it is necessary to introduce a helper procedure C that returns a constant value. The other is that procedure B needs to refer to variables in the local context of its "parent" instance of procedure A. This is precisely what the '''upvar''' core command does, but the ''absolute'' target level needs to be embedded into the script that performs the delayed call to procedure B ('''upvar''' is more often used with relative levels).
Line 3,489:
(prinl (A 10 1 -1 -1 1 0))</lang>
 
=={{header|Visual Prolog}} ==
 
Visual Prolog (like any other Prolog) does not allow variables to be changed. But behavior can easily be mimicked by using a '''varM''' (modifiable variable), which is actually an object containing a value of the relevant type in a modifiable entity (a so called fact variable). Secondly, anonymous function (lambda-expression) cannot be recursive, but this is mimicked by using yet a '''varM''' to hold the function.
Line 3,519:
end implement main</lang>
 
=={{header|Vorpal}} ==
Adapted from the Lua example. In vorpal, all execution is a message to an object. This task primarily involves functions, so we have the apply the function objects to self for them to execute. Correctly, prints -67.
 
Line 3,597:
</pre>
 
=={{header|zkl}} ==
The compiler is OK but the VM is a girlie-man VM. Due to the way closures are built, the stack blows quickly when closures recurse. So, while the code can be written per Knuth, it is unable to do anything. So, classes are used to simulate the closures. Also (5)()-->5 so no problems there.
<lang zkl>fcn A(k, x1, x2, x3, x4, x5){ // -->1,0,-2,0,1,0,1,-1,-10,-30,-67,-138
10,333

edits