From: David Masover Date: 2010-01-05T03:42:32+09:00 Subject: Re: Ruby in Lisp, preLisp On Sunday 03 January 2010 10:28:39 am Ruli Lupy wrote: > so you pay the price of having to specify the first argument, for > example the following Lisp code to collect the lines from a file. > > (let (lines) > (f.each-line "my.file" line (push "line" lines)) > lines) > > you obtain some speed up, because f.each-line is a macro and get > translated > into Lisp code. That would speed up that specific example, but I don't think you could do it in any sort of generic way. Consider these uses: x = lambda{|line| puts line} File.open{|f| f.each(&x) } Or: File.open do |f| lines = f.each_line while (line = lines.next) if need_next_line_now? next_line = niles.next end end end Or: class File def every_other_line lines = self.each_line begin loop do lines.next yield lines.next end rescue StopIteration end end end There are all sorts of interesting ways you can use blocks which are definitely more like lambdas (which Lisp has), and less like macros. There are also plenty of tricks you can do with Lisp macros that you can't really do with Ruby blocks. At best, you can fake it by going back and re- parsing that code. > The idea is that you can translate Ruby to Lisp in this way and get > some > more speed Great! More speed for Ruby is generally a good thing... > but the syntax requires a little more typing. Well, that kind of kills one of the biggest advantages of Ruby in the first place: http://en.wikipedia.org/wiki/Duck_typing And you don't necessarily have to specify types explicitly to get the performance advantages of static typing, or even of native compiled code: http://code.google.com/p/v8/