views:

17

answers:

1

Hi all, I am just confused with a concept. I have been hearing about Ruby as a programing language. Now, many companies/individuals have developed JRuby, which is Ruby implementaion for Java and Jython, which is Ruby implemtation for Python. Can anyone please explain me, how exactly one programming language can be implemented in another programming language? If I am making any sense?

Is it possible to develop Ruby implementaiton for any other systems like Prolog?

Can anyone please explain?

Thanks in advance.

A: 

A programming language is just a translator between you, the programmer, and the machine, to varying degrees of abstraction. For example, Ruby itself is written in C (as most languages are, before they go self-building, ie. where the language is powerful enough to build itself), where the C code is compiled to machine code that can understand Ruby code. What it does is simply to translate from one paradigm into another; Ruby -> C -> Assembler -> processor instructions and back up again, also to varying degrees of dynamics (some code is hard-coded, ie. does not change or can't deal with a change in structure, whilst others are designed to exclusively deal with dynamic structures, like the JVM). But it all ends up as machine code. Ruby is machine code. JRuby is byte code running on the JVM which is machine code. An String in Ruby is a String in JRuby is a char[] array in C is a structured line of memory positions in machine code. You can have a set of machine code (abstractly known as 'Ruby') understand other machine code (abstractly known as 'Ruby code').

The higher the abstraction, the less the paradigms will rely on the technical platform it is on, and the lower the more it relies on it. Porting software relies on various parts of the stack also being available on various platforms. I'm sure there's platforms which hasn't got Ruby on it, but if they've got C on it (or, more specifically, ANSI C, one of the first languages any platform really tries to create a compiler for) then it's possible to compile one (or any other language) for it (with some tweaks). It all comes down to converting your abstractions down to instructions the computer itself can understand and act on.

Java, for example, uses a middle-tier system (the JVM) which is a translator between Java code (same for all platforms) and the platform (mostly different for all). Writing a Ruby parser for the JVM is just re-using the JVM as a middle-tier instead of using ANSI C, and is therefore probably a bit simpler to do; if it runs on the JVM, it can run everywhere the JVM can run, and JRuby can let the people who make the JVM worry about the more platform specific stuff (and I believe the JVM itself is written in C).

There's another way of looking at this, too, for example with something like JS.Class which takes some paradigms from one language and makes them available in another, because they're good / cool / trendy.

AlexanderJohannesen
Thanks for the info. It is really interesting to see the implementation. Looking for more answers.
JPro