How D addresses the problem of Extending and/or Embedding other languages ?

via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 25 13:34:06 PDT 2014


On Monday, 25 August 2014 at 19:26:59 UTC, Brost wrote:
> It's really strange the fact that no one seems to feel about 
> this
> the same way I do, I mean you are happy with a C based bridge
> between 2 languages, you are ok at throwing away all the good
> stuff that both languages ( your X and your Y ) are offering ?
>
> Thank you for posting various scripts and libraries but this is
> not my point, I think that the game changer will be some kind of
> support for this extensions and foreign languages built right
> into the language itself.

So, which language(s) do you have in mind in particular? Whether 
it's practicable surely depends on the type of language you want 
to bind to.

Take Ruby as an example: Ruby is a scripting language that cannot 
be compiled to native code (though it can be JITted). This means 
that there is no ABI, which would be required if you want to link 
against the language. It would theoretically be possible to 
somehow link against the interpreter, but that would require 
cooperation from it, i.e. it would have to expose an interface to 
do that. But there isn't only one implementation of Ruby: There 
is MRI (the most widespread one), JRuby (running on the JVM), 
Rubinius (with LLVM as a JIT backend), and probably others. All 
of them have different interfaces. There is however a FFI 
(foreign function interface) that is used to call native 
extensions from Ruby. This would be the only realistically usable 
interface between D and Ruby. And guess which ABI it uses...

Direct interfacing is more practicable for compiled languages. 
And indeed, there is already surprisingly good support for 
linking against C++, which is currently being extended even more. 
There's also Objective-C, for which there's this proposal [1]. I 
believe Jacob Carlborg even has a proof-of-concept 
implementation. But beyond these languages (and C, of course), 
there aren't even many natively compiled languages in widespread 
use. Pascal? The newer ones like Go and Rust? I guess for those 
there just isn't a great need.

[1] http://wiki.dlang.org/DIP43


More information about the Digitalmars-d mailing list