Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

With reference to features in languages like ruby (and javascript), which allow

ID: 648155 • Letter: W

Question

With reference to features in languages like ruby (and javascript), which allow a programmer to extend/override classes any time after defining it (including classes like String), is it theoretically feasible to design a language which can allow programs to later on extend its semantics.

ex: Ruby does not allow multiple inheritance, yet can I extend/override the default language behaviour to allow an implementation of multiple inheritance.

Are there any other languages which allow this? Is this actually a subject of concern for language designers? Looking at the choice of using ruby for building rails framework for web application development, such languages may be very powerful to allow designing frameworks(or DSLs) for wide variety of applications.

Explanation / Answer

"Is it theoretically feasible?*

Of course, it is. One can always write an interpreter in a language (L) for another language (S), and write programs in the new language. People do not often do this because it might involve a lot of work to write such an interpreter and there will be a performance hit (a factor of 10-100) for the additional layer of interpretation.

Both the problems have solutions. The language L can be designed with powerful metaprogramming facilities so that it is easy to implement interpreters. Languages like Scheme have this.

One can implement a partial evaluator so that the interpreter can be turned into a compiler (from S to L). Then you don't get the performance hit because the additional interpretation layer is eliminated.

The new language might still run slowly if its run-time model is significantly different from the implementation language. In that case, bits of the interpreter will show up in the translated code and it will continue to run slow. However, if the new language is mostly the same as the original language, with only a few tweaks, then it should be possible to eliminate most of the interpreter bits in the target code by careful tuning of partial evaluation. Then the performance hit will be there for only the new features.

In effect, this is the "virtualization" technology for programming languages.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote