real hardware meant running the code in real life versus on theoretical 'mental' computers. That is, the concept of believing in an infinite stack when reading pseudocode is an error a lot of folks (but probably not you) make.
But rest assured that when I use a compiler and make use of tail recursion, I know whether it will eliminate it or not
Again, this is good for your work, but I do not rest assured people I work with are this smart, nor do I think everyone who takes some of my code (open source, etc) would be this smart. I write C code that has to run on about 10 different platforms, so I guess my domain might lend me more towards paranoia.
I didn't argue that tail recursion was ok in this example. Tail recursion was bad in this example. But you extended it to make some general remarks about tail recursion, and that's where I disagree.
No prob, that was a failure to communicate on my part. There are certaintly algorithms that are best expressed recursively (this is obvious!), but I don't ever think it's a good idea for replacing an infinite (or even long running) loop with a recursive solution just because you can and the compiler is smarter than you ... again, obvious to some, but not to all. A better example of using recursion is in math examples, which I have mentioned, and there are tons of doing things in different ways in Lisp, where that becomes the normal idiom.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||