问题
Is it possible to embed Ruby into Erlang? Would Yecc be the correct tool for that? If it is possible how many man hours would it take, rough estimate?
回答1:
There is something called Elixir by Jose Valim url http://elixir-lang.org/ this lets you write code that is ruby like and run it on erlang VM.
So code looks similar in many places like:
iex> name = "world"
iex> "hello #{name}"
"hello world"
in many is more Erlang'y:
# function
iex> x = fn(a, b) -> a + b end
#Fun<erl_eval.12.111823515>
iex> x.(1, 2)
3
and modules =) :
iex> defmodule Math do
...> def sum(a, b) do
...> a + b
...> end
...> end
iex> Math.sum(1, 2)
3
It that helps you in any way. I know Jose recently started again massive work on it after he stopped to focus so much on Rails. Probably he will get Riak integration and some sort of a web framework. That could be interesting!
回答2:
Erlectricity exposes Ruby to Erlang and vice versa:
http://github.com/mojombo/erlectricity
回答3:
You need to explain in a little more detail what you want to do. "Embed" is a rather vague word in this context.
Yecc would be appropriate if you intended to implement a Ruby-parser/interpreter in Erlang, but I'm guessing this is not what you want to do.
If you want to call Ruby-code from Erlang, this can be done in a manner similar to how Erlang's jinterface application is used to talk to Java. (You can also google on the subject.)
You cannot expect to get any sort of realistic estimate without putting in a week or two of work, figuring out exactly what should be done and how. Otherwise, you'll end up with "anything from 2 months to two years", which probably isn't very helpful.
回答4:
Depending on exactly what your task is, you could could do something as simple as spawning a ruby process to talk to via STDIN/OUT.
回答5:
If you wish to evaluate some ruby code inside Erlang, you should prepare to spend about one year to launch simple code.
Ruby syntax is very complicated and erlang has a veeery different VM.
来源:https://stackoverflow.com/questions/436418/ruby-in-erlang