On Sun, 8 Feb 2009, Dylan E. 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…
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.
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.
[ [ [ 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 ] ]
Yup. That was it. All of it.
Says something very very powerful about the simplicity of the Joy
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
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 C. Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : email@example.com