From: Josh Cheek Date: 2011-04-04T03:59:49+09:00 Subject: Re: Lambda Shambda --20cf3054ab87244d9004a0083fa9 Content-Type: text/plain; charset=ISO-8859-1 On Sun, Apr 3, 2011 at 6:50 AM, Phillip Gawlowski < cmdjackryan@googlemail.com> wrote: > > Though, considering that LISP was one of, if not the, first language > to use the lambda calculus as basis for a programming language, it is > certainly a forefather of today's crop of functional programming > languages, like Scheme, ML, Erlang, Haskell, or F#. > > I'm not particularly familiar with its history, but I don't think Common Lisp was the original dialect of Lisp. On Sun, Apr 3, 2011 at 7:17 AM, Everett L Williams II wrote: > *Let's not pay too much attention to the code snobs on here. I've yet to > see a recursive function that is more efficient than a more linearly coded > function that accomplishes the same thing, There are many types of efficiency, there is also efficiency of comprehension, and implementation, and it is much easier to comprehend and implement recursion in many situations. Here is an example of a Binary Search Tree with a recursive_print method and a "linearly coded function that that accomplishes the same thing" (I assume by "linear" you mean "imperative"). I can barely comprehend the linear version, and I wrote it. If you can come up with a better version, please post it. class BST attr_accessor :left , :right , :data def << new_data if !data self.data = new_data elsif new_data <= data ( self.left ||= BST.new ) << new_data else ( self.right ||= BST.new ) << new_data end self end # this is for simplicity of the exercise, in reality it # would be an each method and the code using it # would make it print def recursive_print left && left.recursive_print data && puts(data) right && right.recursive_print end def iterative_print todo = [] crnt = self loop do if crnt && crnt.left todo.push crnt crnt = crnt.left elsif crnt && crnt.right puts crnt.data crnt = crnt.right else puts crnt.data if crnt && crnt.data crnt = todo.pop break unless crnt puts crnt.data if crnt.data crnt = crnt.right end end end end root = BST.new << 7 << 3 << 1 << 0 << 2 << 5 << 4 \ << 6 << 11 << 9 << 8 << 10 << 13 << 12 << 14 root.recursive_print puts root.iterative_print I decided to benchmark it, just to see how much faster it really is. And it actually turns out to be slower. In this case, the recursive version is not only elegant, easier to read, write, and comprehend, but it is also faster. def no_output stdout = Object.new def stdout.write(*params) end def stdout.puts(param) end $stdout = stdout yield ensure $stdout = STDOUT end require 'benchmark' Benchmark.bm 10 do |b| b.report "recursive" do no_output do 100_000.times { root.recursive_print } end end b.report "linear" do no_output do 100_000.times { root.iterative_print } end end end # RESULTS # user system total real # recursive 0.840000 0.000000 0.840000 ( 0.843655) # linear 1.040000 0.010000 1.050000 ( 1.059313) On Sun, Apr 3, 2011 at 8:13 AM, Martin DeMello wrote: > > No less a person than Simon Peyton Jones has called Excel "the world's > most popular functional language". > > http://research.microsoft.com/en-us/um/people/simonpj/papers/excel/ > > martin > > It might be easier if you guys could show how one writes a program in excel. OP was talking about a web app, complete with authentication, authorization, cookies, "etc". I can't even conceive of how one would go about doing such a thing. I wouldn't even know how to execute an Excel program (do you make an executable? do you invoke it on the command line? is there an interpreter? compiler?). Here are some examples of programs I've written this semester in Ruby: * A Shoes app to help me in my Chem lab by watching the time and telling me to take a measurement every n seconds. ( http://img209.imageshack.us/img209/2602/93593675.png) * A program to go through my music and rename all my mp3s to "#{mp3.tag['artist']} - #{mp3.tag['title']}", it is invoked on the command line, you pass it the directory with the mp3s that it should rename. * A program to create Conway's game of life videos ( http://vimeo.com/21594165) Is it even possible (let alone viable) to do any of this in Excel? And if so, then why do they bother bundling VBA with Excel? Seems redundant. --20cf3054ab87244d9004a0083fa9--