Am 03.04.2012 11:24, schrieb Daniel Carrera:
Ok. I just scanned the Wikibook on NQP. Indeed, it is quite limited.
It lacks basic things like list context:
@a := (1,2,3,4); # Wrong.
It's a shame because lists is precisely what I wanted to work with.
But this "works":
@a := [1, 2, 3, 4]
Note that this will store a ResizablePMCArray in @a, so if you want to
know what kind of methods you can call on it, you have to consult
parrot's documentation of the ResizablePMCArray. You also get the
stringification behavior of a ResizablePMCArray etc.
If that's not what you want, use Rakudo.
Reading up on Parrot I stumbled on this bit of information:
"Native Library Support
Parrot has a robust system for interfacing with external native code
libraries, such as those commonly written in C, C++, Fortran and other
compiled languages.
*cough*
Parrot has some limited out-of-the-box support for calling C functions,
and if you have libffi installed (which doesn't work out of the box on
Windows), you get decent support for calling C functions.
I haven't seen a robust way to call C++ and Fortran functions yet,
mainly because both use non-standard name mangling schemes at the
bytecode level (I believe that newer Fortran versions have such a
standard, but the scientific computing world seems to be stuck with F77).
Where previously every interpreter would need to
maintain its own bindings and interfaces to libraries, Parrot enables
developers to write library bindings once and use them seamlessly from
any language executing on Parrot. Want to use Tcl's Tk libraries,
along with Python's image manipulation libraries in a program you are
writing in Perl? Parrot supports that."
Does that mean what I think it means? That I could, for example, get
super-fast matrix operations using LAPACK simply because Rakudo talks
to Parrot and Parrot talks to Fortran?
That's the theory.
In practice, it doesn't work like that. In practice, you have two
options when crossing a language boundary.
The first is to promote or wrap objects to types of the host language
(ie a parrot integer becoming a Perl 6 Int), which means it can't be
automated in the general case, and you get some performance penalty.
The second is to simply leave the objects as-is, but you can't really
call that "seamlessly". It means for example that your Perl 6 Int object
has a method called sqrt, but the Parrot integer does not.
The cross-language interoperability advertised in the parrot
documentation is mostly fiction. All attempts to get cross-language
interoperation to work have bitrotted, and I'm not aware of any working,
non-contrieved examples.
There are a lot of powerful
numerical libraries in C and especially Fortran, but last time I
checked I think I was told that getting Rakudo to talk to Fortran
would be very difficult.
NQP (and thus Rakudo) has its own mechanism for calling C libraries. In
Rakudo, this is available through NativeCall.pm in
https://github.com/jnthn/zavolaj/
(Note that currently NativeCall doesn't work together with precompiled
modules; should still work in the latest Rakudo Star release though).
Cheers,
Moritz