Every 15 years or so, languages are replaced with better ones. C was replaced by C++, at least for large-scale application development by people who needed performance but desperately wanted data types too. C++ is being replaced by Java, and Java will doubtless be replaced with something better in seven years — well, seven years after it finishes replacing C++, which evidently hasn't fully happened yet, mostly because Microsoft was able to stall it before it became ubiquitous on the desktop. But for server-side applications, C++ is basically on its way out.
Perl will be gone soon, too. That's because a new language called Ruby has finally been translated into English. Yep, it was invented in Japan, of all places — everyone else was as surprised as you are, since Japan's known for its hardware and manufacturing, but not for its software development. Why, is anyone's guess, but I'm thinking it's the whole typing thing; I just can't imagine they were able to type fast enough before, what with having an alphabet with ten thousand characters in it. But Emacs got multibyte support a few years ago, so I can imagine they're pretty dang fast with it now. (And yes, they use Emacs — in fact Japanese folks did the majority of the Mule [multibyte] support for Emacs, and it's rock-solid.)
Anyway, Ruby stole everything good from Perl; in fact, Matz, Ruby's author (Yukihiro Matsumoto, if I recall correctly, but he goes by "Matz"), feels he may have stolen a little too much from Perl, and got some whale guts on his shoes. But only a little.
For the most part, Ruby took Perl's string processing and Unix integration as-is, meaning the syntax is identical, and so right there, before anything else happens, you already have the Best of Perl. And that's a great start, especially if you don't take the Rest of Perl.
But then Matz took the best of list processing from Lisp, and the best of OO from Smalltalk and other languages, and the best of iterators from CLU, and pretty much the best of everything from everyone.
And he somehow made it all work together so well that you don't even notice that it has all that stuff. I learned Ruby faster than any other language, out of maybe 30 or 40 total; it took me about 3 days before I was more comfortable using Ruby than I was in Perl, after eight years of Perl hacking. It's so consistent that you start being able to guess how things will work, and you're right most of the time. It's beautiful. And fun. And practical.
If languages are bicycles, then Awk is a pink kiddie bike with a white basket and streamers coming off the handlebars, Perl is a beach cruiser (remember how cool they were? Gosh.) and Ruby is a $7,500 titanium mountain bike. The leap from Perl to Ruby is as significant as the leap from C++ to Java, but without any of the downsides, because Ruby's essentially a proper superset of Perl's functionality, whereas Java took some things away that people missed, and didn't offer real replacements for them.
>>123
I never said it wasn't inefficient. My point was that simulating recursion (not making a recursive algorithm iterative) is not a straightforward process.
It's not juts a matter of leaving a few gotos here and there and it's done.
>>122
Tailcalls can be turned into loops. Just the other day I tested 4 different implementations of fibs and the tail-recursive version vs iterative version turned out to have exactly the same performance (as your iterative fibonacci), and disassembling the compiled functions showed very similar code.
>>127 Thats amazing(I wouldn't ever force myself to write such horribly inefficient code though).
The whole overhead is getting to the surface.
I want every LISP ``enthusiast' to see how "elegant" and "simple" their recursive functions become when they get deconstructed to primitive operations.
>>130
That's not a very strong argument. What I wrote up there is just the lower lever implementation of my previous post (>>79 ). It's possible to make disasters like that in any language.
>>132 But functional languages encourage it, unlike C buffer overruns, recursion is almost mandatory there.
_________________________________________________ http://xs135.xs.to/xs135/09042/av922.jpg
Velox Et Astrum gamedev forum: http://etastrum.phpbb3now.com
...what we call education and culture is for the most part nothing but the substitution of reading for experience, of literature for life, of the obsolete fictitious for the contemporary real...
>>135 Yes, this (iter i r-1 r-2) is storing variables as >>80 except they are passed in parameters.
________________________________________________ http://xs135.xs.to/xs135/09042/av922.jpg
Velox Et Astrum gamedev forum: http://etastrum.phpbb3now.com
The basic objectives and principles of war do not change.The final objective in war is the destruction of the enemy's capacity and will to fight, and thereby force him to accept the imposition of the victor's will.
>>135 Yes, thees (iter i r-1 r-2) is stureeng fereeebles es >>80 ixcept zeey ere-a pessed in peremeters. Bork Bork Bork!
________________________________________________ http://xs141.xs.to/xs141/09303/av992393.jpg
Felux It Estroom gemedef furoom: http://itestroom.phpbb3noo.cum
Zee beseec oobjecteefes und preenciples ooff ver du nut chunge-a.Zee feenel oobjecteefe-a in ver is zee destroocshun ooff zee inemy's cepeceety und veell tu feeght, und zeereby furce-a heem tu eccept zee impuseeshun ooff zee feectur's veell.
>>133
FV, you may think it's a disaster, but if you examine the disassembly of a tail recursive implementation of fibs, you'll find out it actually uses a simple imperative implementation underneath, much simpler than >>127's code. You're also forgetting how most CPUs work: they have a stack for a purpose, and if tailcall elimintation takes place, there's no recursive calls involved at all.
Not all languages supporting the functional paradigm force you to use tail recursion. I could easily post a 10 page practical proof showing exactly how these things work in practice, but that would just mean that IHBT.