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-joyjoy.html
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 : (e-mail address removed)
New Zealand