[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ruby interpreter written in ruby..

Eelco

2/8/2009 9:45:00 AM

Hi there,

I am new to programming and ruby.. Trying to read through the pickaxe
and do the exercises on Sphere Online Judge.
I was wondering is there a ruby written ruby interpreter available?
somehow i`d like to be able to read the interpreter source.

greetz Cat

12 Answers

Ryan Davis

2/8/2009 9:57:00 AM

0


On Feb 8, 2009, at 01:45 , Eelco wrote:

> I was wondering is there a ruby written ruby interpreter available?
> somehow i`d like to be able to read the interpreter source.

no, not 100% (yet) at least. the rubinius project is farthest along in
that effort.

http://...

the doco on that site is... well... not good. Just download the source
and poke around. There is a fair amount in C++ still (last I looked)
but a lot more pure ruby code than available in MRI or any other ruby
impl project (last I looked).


Dylan Evans

2/8/2009 11:40:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

On Sun, Feb 8, 2009 at 7:45 PM, Eelco <catsquotl@gmail.com> wrote:

> Hi there,
>
> I am new to programming and ruby.. Trying to read through the pickaxe and
> do the exercises on Sphere Online Judge.
> I was wondering is there a ruby written ruby interpreter available? somehow
> i`d like to be able to read the interpreter source.
>
> greetz Cat
>
>
It seems to me that would be pointless, since it would require another
interpreter to function. Of course the other alternative would be to write a
ruby compiler which would be awkward in a dynamic language. Of course if it
wasn't actually compiled then you would have the overhead of interpreting a
stack of ruby. Why would you want a ruby interpreter written in ruby?


--
The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum

Eelco

2/8/2009 12:14:00 PM

0

Dylan Evans schreef:
> On Sun, Feb 8, 2009 at 7:45 PM, Eelco <catsquotl@gmail.com> wrote:
>
>
>> Hi there,
>>
>> I am new to programming and ruby.. Trying to read through the pickaxe and
>> do the exercises on Sphere Online Judge.
>> I was wondering is there a ruby written ruby interpreter available? somehow
>> i`d like to be able to read the interpreter source.
>>
>> greetz Cat
>>
>>
>>
> It seems to me that would be pointless, since it would require another
> interpreter to function. Of course the other alternative would be to write a
> ruby compiler which would be awkward in a dynamic language. Of course if it
> wasn't actually compiled then you would have the overhead of interpreting a
> stack of ruby. Why would you want a ruby interpreter written in ruby?
>
>
>
That makes sense......
I wasn`t thinking about the why or what..
Just as this is the first language i am trying to understand i thought i
could learn a lot by reading the code
As C is jibberish to me..

Eelco

Tim Hunter

2/8/2009 1:26:00 PM

0

Eelco wrote:
> I wasn`t thinking about the why or what..
> Just as this is the first language i am trying to understand i thought i
> could learn a lot by reading the code

There's a huge amount of very good Ruby code out there in Ruby libraries
and applications. Rails, Rake, RubyGems. All written in Ruby.

Also take a look at the past Ruby quizzes (rubyquiz.com)

--
RMagick: http://rmagick.ruby...

Julian Leviston

2/8/2009 2:22:00 PM

0

Smalltalk is written in itself. It's quite useful! You can understand
a lot about a language if it has such a high level of self-
describingness. Rubinius is such a project.

Blog: http://random8.ze...
Learn rails: http://sensei.ze...

On 08/02/2009, at 10:40 PM, Dylan Evans <dylan.star@gmail.com> wrote:

> On Sun, Feb 8, 2009 at 7:45 PM, Eelco <catsquotl@gmail.com> wrote:
>
>> Hi there,
>>
>> I am new to programming and ruby.. Trying to read through the
>> pickaxe and
>> do the exercises on Sphere Online Judge.
>> I was wondering is there a ruby written ruby interpreter available?
>> somehow
>> i`d like to be able to read the interpreter source.
>>
>> greetz Cat
>>
>>
> It seems to me that would be pointless, since it would require another
> interpreter to function. Of course the other alternative would be to
> write a
> ruby compiler which would be awkward in a dynamic language. Of
> course if it
> wasn't actually compiled then you would have the overhead of
> interpreting a
> stack of ruby. Why would you want a ruby interpreter written in ruby?
>
>
> --
> The UNIX system has a command, nice ... in order to be nice to the
> other
> users. Nobody ever uses it." - Andrew S. Tanenbaum

Ryan Davis

2/8/2009 9:56:00 PM

0


On Feb 8, 2009, at 03:40 , Dylan Evans wrote:

> It seems to me that would be pointless, since it would require another
> interpreter to function. Of course the other alternative would be to
> write a
> ruby compiler which would be awkward in a dynamic language. Of
> course if it
> wasn't actually compiled then you would have the overhead of
> interpreting a
> stack of ruby. Why would you want a ruby interpreter written in ruby?

smalltalk (squeak, at the very least), many lisps/schemes, factor,
every language designed by wirth... yeah. must be pointless. :P


John Carter

2/8/2009 10:43:00 PM

0

On Sun, 8 Feb 2009, Dylan Evans wrote:

>> I was wondering is there a ruby written ruby interpreter available? somehow
>> i`d like to be able to read the interpreter source.

Hokay, so this is at the trivial "HEY! You Cheated!!" level... but
it's still useful...

ri 'Kernel#eval'
------------------------------------------------------------ Kernel#eval
eval(string [, binding [, filename [,lineno]]]) => obj
------------------------------------------------------------------------
Evaluates the Ruby expression(s) in _string_. If _binding_ is
given, the evaluation is performed in its context. The binding may
be a +Binding+ object or a +Proc+ object. If the optional
_filename_ and _lineno_ parameters are present, they will be used
when reporting syntax errors.

def getBinding(str)
return binding
end
str = "hello"
eval "str + ' Fred'" #=> "hello Fred"
eval "str + ' Fred'", getBinding("bye") #=> "bye Fred"


> Why would you want a ruby interpreter written in ruby?

Actually the original poster asked a very intelligent question.

Why would you want such a thing?

It's a _very_ effective measure of the simplicity and expressiveness
combined of the language.

For example, here is a minimal (non-trivial) Joy0 interpeter written
in Joy0 that will interpret itself.
Source http://www.latrobe.edu.au/philosophy/phimvt/joy/jp-j...

joy0 ==
[ [ [ joy0 body joy0 ]
[ [] ]
[ pop pop pop ]
[ cons pop cons ]
[ opcase pop opcase ]
[ body pop body ]
[ i pop joy0 ]
[ step pop [joy0] cons step ]
[ [] cons i ] ]
opcase
i ]
step


Yup. That was it. All of it.

Says something very very powerful about the simplicity of the Joy
language.

I'll admit I learnt several things about the language when I read that
close enough to understand it.

I bet you'd have a good few "Aha!" moments if you could do the same
with Ruby.

Conversely, if you could strip Ruby to a Ruby0 essence in which you
could easily write a ruby0 in ruby0 interpreter... you'd learn what
was the essence of the language and what was sugar.


John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand


Dylan Evans

2/9/2009 1:52:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

On Mon, Feb 9, 2009 at 7:55 AM, Ryan Davis <ryand-ruby@zenspider.com> wrote:

>
> On Feb 8, 2009, at 03:40 , Dylan Evans wrote:
>
> It seems to me that would be pointless, since it would require another
>> interpreter to function. Of course the other alternative would be to write
>> a
>> ruby compiler which would be awkward in a dynamic language. Of course if
>> it
>> wasn't actually compiled then you would have the overhead of interpreting
>> a
>> stack of ruby. Why would you want a ruby interpreter written in ruby?
>>
>
> smalltalk (squeak, at the very least), many lisps/schemes, factor, every
> language designed by wirth... yeah. must be pointless. :P
>
>
> I see that squeak uses a C translator for it's implementation which is
kinda cool, and the lisps use either a bootstrap implementation or a
translator.I was just thinking of a plain ruby interpreter entirely in ruby,
which really would be pointless.
Of course new languages written in interpreted languages can be good
prototypes.


--
The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum

Julian Leviston

2/9/2009 2:50:00 AM

0

I don't think a measure such as that is useful for anything much. IMHO
you'd want a language written in itself so you could understand it
better at a lower level: pedagogy.

Blog: http://random8.ze...
Learn rails: http://sensei.ze...

On 09/02/2009, at 9:42 AM, John Carter <john.carter@tait.co.nz> wrote:

> On Sun, 8 Feb 2009, Dylan Evans wrote:
>
>>> I was wondering is there a ruby written ruby interpreter
>>> available? somehow
>>> i`d like to be able to read the interpreter source.
>
> Hokay, so this is at the trivial "HEY! You Cheated!!" level... but
> it's still useful...
>
> ri 'Kernel#eval'
> ------------------------------------------------------------
> Kernel#eval
> eval(string [, binding [, filename [,lineno]]]) => obj
> ---
> ---------------------------------------------------------------------
> Evaluates the Ruby expression(s) in _string_. If _binding_ is
> given, the evaluation is performed in its context. The binding may
> be a +Binding+ object or a +Proc+ object. If the optional
> _filename_ and _lineno_ parameters are present, they will be used
> when reporting syntax errors.
>
> def getBinding(str)
> return binding
> end
> str = "hello"
> eval "str + ' Fred'" #=> "hello Fred"
> eval "str + ' Fred'", getBinding("bye") #=> "bye Fred"
>
>
>> Why would you want a ruby interpreter written in ruby?
>
> Actually the original poster asked a very intelligent question.
>
> Why would you want such a thing?
>
> It's a _very_ effective measure of the simplicity and expressiveness
> combined of the language.
>
> For example, here is a minimal (non-trivial) Joy0 interpeter written
> in Joy0 that will interpret itself.
> Source http://www.latrobe.edu.au/philosophy/phimvt/joy/jp-j...
>
> joy0 ==
> [ [ [ joy0 body joy0 ]
> [ [] ]
> [ pop pop pop ]
> [ cons pop cons ]
> [ opcase pop opcase ]
> [ body pop body ]
> [ i pop joy0 ]
> [ step pop [joy0] cons step ]
> [ [] cons i ] ]
> opcase
> i ]
> step
>
>
> Yup. That was it. All of it.
>
> Says something very very powerful about the simplicity of the Joy
> language.
>
> I'll admit I learnt several things about the language when I read that
> close enough to understand it.
>
> I bet you'd have a good few "Aha!" moments if you could do the same
> with Ruby.
>
> Conversely, if you could strip Ruby to a Ruby0 essence in which you
> could easily write a ruby0 in ruby0 interpreter... you'd learn what
> was the essence of the language and what was sugar.
>
>
> John Carter Phone : (64)(3) 358 6639
> Tait Electronics Fax : (64)(3) 359 4632
> PO Box 1645 Christchurch Email : john.carter@tait.co.nz
> New Zealand
>
>

Ryan Davis

2/9/2009 6:54:00 AM

0


On Feb 8, 2009, at 17:51 , Dylan Evans wrote:

> I see that squeak uses a C translator for it's implementation which is
> kinda cool, and the lisps use either a bootstrap implementation or a
> translator.I was just thinking of a plain ruby interpreter entirely
> in ruby,
> which really would be pointless.

there you go using that word ("pointless") again... As someone who
worked on smalltalk for many years and was working on metaruby before
I was professionally working on rubinius, I have to highly disagree.
I'm gonna leave it at that tho.