Talk:Man or boy test: Difference between revisions

→‎Haskell version: Good thought, and a little faster too. (your liftM2 is still the fastest of all)
(→‎Clarify!: Getting desperate...)
(→‎Haskell version: Good thought, and a little faster too. (your liftM2 is still the fastest of all))
 
(9 intermediate revisions by 7 users not shown)
Line 1:
= MoB =
 
'''Please sign your posts with <nowiki>--~~~~</nowiki>, as it will make the conversation much easier to follow.''' --[[User:Short Circuit|Short Circuit]] 22:35, 28 March 2008 (MDT)
 
All posts are signed at the last entry at the same "indentation level". The alternative is to sign after each remark to some point, which to me seems a bit excessive. Yes, discussion on Wikipages sucks :-( And long discussions suck even more. Any alternative? --[[User:Dirkt|Dirkt]] 05:32, 29 March 2008 (MDT)
 
== Clarify! ==
 
Line 66 ⟶ 72:
Are any of these wrong and are there any more requirements?
: None of these is "required". I don't think such a list makes a lot of sense. Since you insist that I take responsibility, I've updated the task description. It's probably still not satisfactory for you, but unless we can finally find out where the problem in understanding the task is, that's the best I can do. --[[User:Dirkt|Dirkt]] 10:14, 28 March 2008 (MDT)
::Thank you. It's a step in the right direction. At least now there are directions. I still don't understand what to do, but that's because I don't understand ALGOL xx and I don't understand the idea of "activation records." --[[User:Mwn3d|Mwn3d]] 10:37, 28 March 2008 (MDT)
 
=== Copyright issues ===
The fact that this page sprung into being with many language examples at once with code wrapped in <source> blocks makes me worry that the code was transwikied from somewhere like Literate Programs, which would be a copyright violation. Are you certain that you have permission to do this? (Hmm. I was going to point you at a Copyrights page, but I can't seem to find one.) --[[User:IanOsgood|IanOsgood]] 10:35, 18 December 2007 (MST)
Line 89 ⟶ 95:
 
[[User:NevilleDNZ|NevilleDNZ]] 20:20, 18 December 2007 (MST)
 
 
== Helping to Understand the problem! ==
 
Knuth's MoB test is hard to get right. Of course it was designed that way. :)
 
The description in the task is accurate but leaves a bit to be desired. If you haven't seen this problem before, or don't know ALGOL60, or can't just port something close to your language then it's going to give you trouble. Some modern safer languages may have some difficult with parts of this task.
 
Having done some ALGOL programming in the depths of antiquity on a safer version of ALGOL, there are a few things that you need to understand.
* call by value isn't the default you must ask nicely
* procedure call syntax doesn't require () unless you have arguments, hence you can not tell if x is a variable or a function call from looking
* returned values are just assigned to variables representing the function and are subject to scoping conventions
* running with scissors didn't get you any warnings from your Mom
 
The Wikipedia article sums it up fairly well but doesn't really show you where you can get hurt.
 
If you succeed at this task, you'll have a much better understanding of the semantics of your language. Always a good thing. Not to mention it's a bit of fun mental excercise.
 
The thing here is that the process for doing mob, for really understanding it in a different environment, involves a series of enlightenment moments not unlike being hit upside the head with a cricket bat. There are a couple of common ways to fail at this (1) k going negative and recursing to death (2) working correctly for k=0..4 and then messing up. The truly evil "man-compiler" part of mob is in x4 + x5. As B gets rolled through the x's everything is safe up to and including the penultimate B+x5. The trick is that in the ultimate form when you get to B+B is that k will be one less entering the second B!
 
I'd truly love the back story on this program. My suspicion is that Knuth hit a bug his compiler and distilled the problem down to MoB or something close to it. From the Knuth's submission to Algol report 17:
 
: 'I have written the following simple routine, which may separate the "man-compilers" from the "boy-compilers"'; and
: 'This uses nothing known to be tricky or ambiguous.'
: 'My question is: What should the answer be? Unfortunately, I don't have access to a man compiler myself, ...'
 
I find Knuth's comments both understated and mischievously misleading. :)
 
[[User:Dgamey|Dgamey]] 03:25, 6 May 2010 (UTC)-
 
==Haskell version==
: Perhaps skip the Control.Monad import by using an applicative alternative to liftM2 ?
:: liftM2 (+) x4 x5 is equivalent to pure (+) <*> x4 <*> x5
: [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 00:08, 14 March 2017 (UTC)
:: Tho in fact I notice that the applicative reformulation seems to run a little slower … [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 00:17, 14 March 2017 (UTC)
::: What about:
:::: <code>(+) <$> x4 <*> x5</code>
::: Not sure if that's more readable than the <code>liftM2</code> version, but arguably more idiomatic nowadays. &mdash;''[[User:Ruud Koot|Ruud]]'' 08:42, 14 March 2017 (UTC)
:::: Good thought, and a little faster too. Perhaps your first instinct is right though ? liftM2 is not unreadable, and still seems to be the fastest of the three. [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 11:53, 14 March 2017 (UTC)
9,655

edits