I realized last night that the ||= is superfluous. A simple assignment
is enough.
b = Proc.new { k -= 1; a(k, b, x1, x2, x3, x4) }
Right, because b will always be nil here, it’s a local variable so
there’s a new b for each resursion. Otherwise it would kind of defeat
what the Man Or Boy example is trying to illustrate.
And it can be made a little shorter, and more computer sciency , by
replacing all those "Proc.new"s with "lambda"s.
Man or boy test
def a(k, x1, x2, x3, x4, x5)
b = lambda { k -= 1; a(k, b, x1, x2, x3, x4) }
return k <= 0 ? x4[] + x5[] : b[]
end
Since I posted your ruby version, there have been more posts in C,
haskell, smalltalk. I sense that a snowball has started an avalanche!
Well, the Ruby version certainly wins the Man-or-boy-test-golf contest.
But I’ve been programming in C for over 20 years and I can say with
authority that whoever did the C version has C-coding cojones the size
of hubcaps.
Well, the Ruby version certainly wins the Man-or-boy-test-golf contest.
But I’ve been programming in C for over 20 years and I can say with
authority that whoever did the C version has C-coding cojones the size
of hubcaps.
I was surprised and amused to find that there was already an PL/I
implementation in the wikipedia article.
A much (unnecessarily) maligned language deep in my past.
A much (unnecessarily) maligned language deep in my past.
Ummmm…before I wrote C I wrote PL/I. Not a lot, but enough to be able
to use the PL/I version of the Man or Boy test to figure out how to code
the Ruby version.
A much (unnecessarily) maligned language deep in my past.
Ummmm…before I wrote C I wrote PL/I. Not a lot, but enough to be able
to use the PL/I version of the Man or Boy test to figure out how to code
the Ruby version.
Sometimes I feel my age.
Last week I gave a talk to the local “agile” meetup group about “A
History of Agility” When I introduced myself I said that I started
programming in College in 1970. Out of the 15-20 people in the
audience, only about 3-4 were born then, some by only a few months.
Your post did not have the formatting that the other languages did. I
added that for you so the other kids would not make fun of your code.
I did not use any language coloring as the wiki does not recognize
mathmatica.
Ummmm…before I wrote C I wrote PL/I. Not a lot, but enough to be
able to use the PL/I version of the Man or Boy test to figure out
how to code the Ruby version.
Interesting. I used your Ruby version to figure out how to code it in
Mathematica. I was able to make a fairly direct translation.
$RecursionLimit = 1665; (* anything less fails for k0 = 10 *)
a[k0_, x1_, x2_, x3_, x4_, x5_] := Module[{k, b },
k = k0;
b = (k–; a[k, b, x1, x2, x3, x4]) &;
If[k <= 0, x4[] + x5[], b[]]]
a[10, 1 &, -1 &, -1 &, 1 &, 0 &] (* => -67 *)
Note how compact the Mathematica notation for the thunks is.
Your post did not have the formatting that the other languages
did. I
added that for you so the other kids would not make fun of your code.
I did not use any language coloring as the wiki does not recognize
mathmatica.
I’m glad you fixed it up. That was my first post on Wikipedia. I
tried , but as you pointed out, that
doesn’t work. I didn’t know that was the best
alternative. But I do now :). Thanks.