Forum: Ruby ruby interpreter written in ruby..

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
487138b6941ce92a8282ddd8d72d872a?d=identicon&s=25 Eelco (Guest)
on 2009-02-08 10:46
(Received via mailing list)
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
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2009-02-08 10:58
(Received via mailing list)
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://rubini.us/

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).
42773b24e0c3fb506a8a875c058a9dd7?d=identicon&s=25 Dylan Evans (Guest)
on 2009-02-08 12:42
(Received via mailing list)
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?
487138b6941ce92a8282ddd8d72d872a?d=identicon&s=25 Eelco (Guest)
on 2009-02-08 13:16
(Received via mailing list)
Dylan Evans schreef:
>> greetz Cat
>
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
3afd3e5e05dc9310c89aa5762cc8dd1d?d=identicon&s=25 Tim Hunter (Guest)
on 2009-02-08 14:27
(Received via mailing list)
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)
3131fcea0a711e5ad89c8d49cc9253b4?d=identicon&s=25 Julian Leviston (Guest)
on 2009-02-08 15:23
(Received via mailing list)
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.zenunit.com/
Learn rails: http://sensei.zenunit.com/
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2009-02-08 22:57
(Received via mailing list)
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
D812408537ac3a0fa2fec96eb8811559?d=identicon&s=25 John Carter (johncarter)
on 2009-02-08 23:44
(Received via mailing list)
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...

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
42773b24e0c3fb506a8a875c058a9dd7?d=identicon&s=25 Dylan Evans (Guest)
on 2009-02-09 02:53
(Received via mailing list)
On Mon, Feb 9, 2009 at 7:55 AM, Ryan Davis <ryand-ruby@zenspider.com>
wrote:

>> 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.
3131fcea0a711e5ad89c8d49cc9253b4?d=identicon&s=25 Julian Leviston (Guest)
on 2009-02-09 03:51
(Received via mailing list)
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.zenunit.com/
Learn rails: http://sensei.zenunit.com/
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2009-02-09 07:59
(Received via mailing list)
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.
42773b24e0c3fb506a8a875c058a9dd7?d=identicon&s=25 Dylan Evans (Guest)
on 2009-02-09 09:18
(Received via mailing list)
On Mon, Feb 9, 2009 at 4:54 PM, Ryan Davis <ryand-ruby@zenspider.com>
wrote:

> 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.
>
> Seriously? You understand what i'm saying is pointless right? I'm referring
to a ruby interpreter written in ruby yes, but then this interpreter is
interpreted by for example rubinius, or jruby, or any other ruby
interpreter. Ok as an exercise that might be an interesting project, or
perhaps it could be useful for some sort of sandboxing, but what about
day
to day use? What function would that serve? If you wanted you could keep
stacking interpreters on top of each other until you had an expensive
386.
D812408537ac3a0fa2fec96eb8811559?d=identicon&s=25 John Carter (johncarter)
on 2009-02-11 01:47
(Received via mailing list)
On Mon, 9 Feb 2009, Ryan Davis wrote:

> 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 strongly agree with you, what you have been doing _is_ very
interesting and valuable.

Which leads to some questions I have for you... you probably don't
have the answers to them, but your thoughts about what the answers may
be should be interesting.

1) The "lisp in lisp" / "joy in joy" / ... interpreters I have seen have
sort of glossed over the lexical / parsing issue by assuming that they
are interpreting an already internalised representation of the
program.

This is part of the classic basic data representation === the basic
program
representation ambiguity of these languages.

We can pretty much do this in Ruby too...  A ruby program can be
represented as an Array of Symbols, Numbers and Strings.

So assuming at least a lexical analyser that will chew on Ruby program
text and spit out an Array of Symbols, Numbers and Strings....

Q1a) What would be the Ruby0 language? ie. What is the smallest subset
  of Ruby that could be used to write a self-interpreting interpreter.

Q1b) Could there be a way of hijacking the Ruby internal lexer to
cough up such an Array of Objects?

Q1c) What would be the RubyLex0 definition? (The simplist subset of
Ruby lexical analysis that could be used as a front end to a Ruby0
interpreter)

2) A major gotcha is Regular Expressions are a "language within a
language".

2a) It would be a fun thing to do to create a Ruby Regex to Ruby
compiler - and then extend the semantics hugely.

2b) What would be the simplist Ruby0 in Ruby0 definition _including_
the lexical analysis from text?


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
This topic is locked and can not be replied to.