RosettaCodeData/Task/Man-or-boy-test/Icon/man-or-boy-test-1.icon
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

23 lines
1.4 KiB
Text

record mutable(value) # we need mutable integers
# ... be obvious when we break normal scope rules
procedure main(arglist) # supply the initial k value
k := integer(arglist[1])|10 # .. or default to 10=default
write("Man or Boy = ", A( k, 1, -1, -1, 1, 0 ) )
end
procedure eval(ref) # evaluator to distinguish between a simple value and a code reference
return if type(ref) == "co-expression" then @ref else ref
end
procedure A(k,x1,x2,x3,x4,x5) # Knuth's A
k := mutable(k) # make k mutable for B
return if k.value <= 0 then # -> boy compilers may recurse and die here
eval(x4) + eval(x5) # the crux of separating man .v. boy compilers
else # -> boy compilers can run into trouble at k=5+
B(k,x1,x2,x3,x4,x5)
end
procedure B(k,x1,x2,x3,x4,x5) # Knuth's B
k.value -:= 1 # diddle A's copy of k
return A(k.value, create |B(k,x1,x2,x3,x4,x5),x1,x2,x3,x4) # call A with a new k and 5 x's
end