On 21 June 2011 18:19, Scott Sauyet <[email protected]> wrote: >> Here's a fiddle showing the Sieve of Eratosthenes, displaying each >> prime as it is found.http://jsfiddle.net/skilldrick/vT2mC/1/ > > Very interesting stuff. Have you found any practical uses for this? > (I'm sure that's not the point, but I'm curious.) > > Why use arrays rather than, e.g., {first: val, rest: someFunction} ? > Also I'm not convinced that "car" and "cdr" should ever be ported to > other languages by name!
I guess a two-cell array was the closest I could get to a Scheme cons-cell. car and cdr are the same - really I was just trying to get the closest as possible to the Scheme code. I did this because I was intrigued by the idea of infinite streams, and wanted to see what was possible in JS. The conclusion I've come to is that it's not *really* that possible in current implementations - the fact that you can't do something like (cons-stream <exprA> <exprB>) and have to explicitly make a lambda of the second expression means that it'll never be as expressive as Scheme, and the lack of tail calls means you need to resort to ugly hacks. Anyway, glad you enjoyed it! -- Nick Morgan http://skilldrick.co.uk @skilldrick -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
