# Ruby in Lisp, preLisp

**URL:** <https://www.ruby-forum.com/t/ruby-in-lisp-prelisp/181002>\
**Category:** Ruby\
**Created:** [January 3, 2010, 5:28pm UTC](https://www.ruby-forum.com/t/ruby-in-lisp-prelisp/181002 "2010-01-03T17:28:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rulilupy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/49beb7/32.png) [@rulilupy](https://www.ruby-forum.com/u/rulilupy)\
**Post date:** [January 3, 2010, 5:28pm UTC](https://www.ruby-forum.com/t/ruby-in-lisp-prelisp/181002/1 "2010-01-03T17:28:37Z")

</div>

Hello, as I am learning Lisp and I like Ruby, I defined some macros in  
Lisp,  
for example

f.each-line  
h.each-key  
h.each-value

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.

Do you think the notation is very ugly?

The idea is that you can translate Ruby to Lisp in this way and get  
some  
more speed but the syntax requires a little more typing.

What do you think of this? (code in comp.lang.lisp)

---

<div class="post-metadata">

**Author:** ![rulilupy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/49beb7/32.png) [@rulilupy](https://www.ruby-forum.com/u/rulilupy)\
**Post date:** [January 3, 2010, 6:30pm UTC](https://www.ruby-forum.com/t/ruby-in-lisp-prelisp/181002/2 "2010-01-03T18:30:34Z")

</div>

On 01/03/2010 05:28 PM, Ruli Lupy wrote:

> (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.
> 
> Do you think the notation is very ugly?

I am sorry, yes.

> The idea is that you can translate Ruby to Lisp in this way and get  
> some  
> more speed but the syntax requires a little more typing.
> 
> What do you think of this? (code in comp.lang.lisp)

My 0.02EUR: interpretation of programming languages in other programming  
languages usually does not help improve performance. I believe the  
approach to let Ruby run on a highly optimized runtime environment (like  
JRuby does with the JWM or IronRuby with CLR) is a more promising  
approach if you want to speed up Ruby execution.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![rulilupy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/49beb7/32.png) [@rulilupy](https://www.ruby-forum.com/u/rulilupy)\
**Post date:** [January 4, 2010, 6:25pm UTC](https://www.ruby-forum.com/t/ruby-in-lisp-prelisp/181002/3 "2010-01-04T18:25:49Z")

</div>

2010/1/3 Robert K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> with the JWM or IronRuby with CLR) is a more promising approach if you want  
> to speed up Ruby execution.

While it does not necessarily improve performance it may improve  
interoperability between the two languages. That requires a full  
interpreter of the original syntax, though. Doing that correctly for  
Ruby has proven quite difficult in other languages and I don’t see any  
reason for Lisp being any different in this regard.

Thanks

Michal

---

<div class="post-metadata">

**Author:** ![rulilupy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/49beb7/32.png) [@rulilupy](https://www.ruby-forum.com/u/rulilupy)\
**Post date:** [January 4, 2010, 8:23pm UTC](https://www.ruby-forum.com/t/ruby-in-lisp-prelisp/181002/4 "2010-01-04T20:23:28Z")

</div>

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:

> **[Duck typing](https://en.wikipedia.org/wiki/Duck_typing)**
>
> Duck typing in computer programming is an application of the duck test—"If it walks like a duck and it quacks like a duck, then it must be a duck"—to determine whether an object can be used for a particular purpose. With nominative typing, an object is of a given type if it is declared as such (or if a type's association with the object is inferred through mechanisms such as object inheritance). With duck typing, an object is of a given type if it has all methods and properties required by that t...

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/](http://code.google.com/p/v8/)

---

<div class="post-metadata">

**Author:** ![rulilupy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/49beb7/32.png) [@rulilupy](https://www.ruby-forum.com/u/rulilupy)\
**Post date:** [January 6, 2010, 3:09pm UTC](https://www.ruby-forum.com/t/ruby-in-lisp-prelisp/181002/5 "2010-01-06T15:09:33Z")

</div>

On Mon, Jan 4, 2010 at 11:22 AM, Michal S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> While it does not necessarily improve performance it may improve  
> interoperability between the two languages. That requires a full  
> interpreter of the original syntax, though. Doing that correctly for  
> Ruby has proven quite difficult in other languages and I don’t see any  
> reason for Lisp being any different in this regard.

As someone who’s been working on a Ruby impl for the past 4 years, I  
can say that interpreting Ruby is not necessarily the hardest  
part…what actually takes forever (almost literally forever) is  
getting all the core classes behaving correctly. RubySpec and the  
various test suites we use in JRuby have helped that process, but  
there’s still a lot of edge cases you have to use to discover.

It is for this reason that Ruby implementations seem to come out of  
the woodwork but stumble a bit after leaving the gate. They can run  
Ruby code very early (and often very fast). Then they have to address  
the much larger task of implementing all the core classes…

- Charlie

---

<div class="post-metadata">

**Author:** ![rulilupy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/49beb7/32.png) [@rulilupy](https://www.ruby-forum.com/u/rulilupy)\
**Post date:** [January 7, 2010, 5:45am UTC](https://www.ruby-forum.com/t/ruby-in-lisp-prelisp/181002/6 "2010-01-07T05:45:20Z")

</div>

On Jan 6, 2010, at 19:57 , Albert S. wrote:

> Charles Nutter wrote:
> 
> > As someone who’s been working on a Ruby impl for the past 4 years, I  
> > can say that interpreting Ruby is not necessarily the hardest  
> > part…what actually takes forever (almost literally forever) is  
> > getting all the core classes behaving correctly. RubySpec and the  
> > various test suites we use in JRuby have helped that process, but  
> > there’s still a lot of edge cases you have to use to discover.
> 
> Can you give one or two examples (for an edge-case)?

A few easy ones off the top of my head are Array#pack, String#unpack,  
and String#[]. Amazing amount of edge cases on all of those, just  
getting complete test coverage for them is difficult.

---

<div class="post-metadata">

**Author:** ![rulilupy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/49beb7/32.png) [@rulilupy](https://www.ruby-forum.com/u/rulilupy)\
**Post date:** [January 7, 2010, 4:57am UTC](https://www.ruby-forum.com/t/ruby-in-lisp-prelisp/181002/7 "2010-01-07T04:57:45Z")

</div>

Charles Nutter wrote:

> As someone who’s been working on a Ruby impl for the past 4 years, I  
> can say that interpreting Ruby is not necessarily the hardest  
> part…what actually takes forever (almost literally forever) is  
> getting all the core classes behaving correctly. RubySpec and the  
> various test suites we use in JRuby have helped that process, but  
> there’s still a lot of edge cases you have to use to discover.

Can you give one or two examples (for an edge-case)?
