News for hackers. Stuff that matters.
Re:Printing 1 to 1000 without loop or conditionals by tptacek on Monday January 03, 2011 @01:24AM (#2062337)
mapm_ is also looping construct.
Re:Printing 1 to 1000 without loop or conditionals by Confusion on Monday January 03, 2011 @03:10AM (#2062559)
'without using loops' is very ill defined. All solutions that in some way generate all integers up to a thousand need to include something we would, in English, refer to as 'a loop'. The ctor trick also contains 'a loop'. What solutions would you consider valid, without resulting in semantic squabbling over whether 'i < 1000' is a conditional or a condition and whether that matters?
Re:Printing 1 to 1000 without loop or conditionals by tptacek on Monday January 03, 2011 @03:41AM (#2062604)
Where's the loop in the array initialization? Where's the loop in "map"? That's why one's clever and the other's a cheat.
Re:Printing 1 to 1000 without loop or conditionals by Raphael_Amiard on Monday January 03, 2011 @06:33AM (#2062845)
The loop in the array initialization is generated by the compiler for the static version, by the runtime for the dynamic allocation version. It's still a loop.

You're just re-using a loop already implemented in the runtime. That's quite the same thing as using map, though a tiny bit clever. But if you qualify map as cheat, well then the constructor trick is just a cleverer cheat.