4 ms·
> making Perl 6 not be compatible with Perl 5. Imo that's either inaccurate or misleading. In Perl 6, `use` followed by a module name followed by a `:from` ad
by raiph 9y ago
> making Perl 6 not be compatible with Perl 5.
Imo that's either inaccurate or misleading.
In Perl 6, `use` followed by a module name followed by a `:from` adverb leads Perl 6 to load the module, initialize it, and import its public functions, constants, variables, etc., AUTOMATICALLY BINDING THEM TO PERL 6, for any given supported other language the module is written in, provided someone has installed a suitable loader/binder (and the user has installed that plus the other language's interpreter, and the other language's module(s) that they wish to use).
I'll start with a toy example.
With a suitable "Perl 5" loader/binder in place, one could write the following and it would work as expected provided the user had installed the loader/binder, a compatible Perl 5 interpreter, and the Business::ISBN module (from https://metacpan.org/pod/Business::ISBN https://metacpan.org/pod/Business::ISBN):
use Business::ISBN:from<Perl5>;
my $isbn = Business::ISBN.new( '9781491954324' );
say $isbn.as_isbn10.as_string;
Stefan Seifert has written just such a Perl 5 loader/binder and steadily improved it over the last few years to the point it's a serious solution.
With Stefan's loader/binder, not only do toy examples like the above work, so do non-toy examples like writing controllers for the Catalyst MVC web framework even though Catalyst is large and complex, written in Perl 5 with XS (C lib) extensions, written without regard to Perl 6, and even though a controller has to be a subclass of a Perl 5 class provided by Catalyst.
- chromatic 9y agoThis argument is disingenuous. The same feature is available in any language with a decent FFI (must support loading an arbitrary shared library, marshalling/demarshalling data between languages, and invoking functions in the shared library). This is possible in Python, Ruby, Java, Racket, Rust, Perl, Go, and plenty of other languages I'm forgetting or haven't used. Yet who would seriously argue that "Python is compatible with Perl" because you can embed libperl in a Python program? You might as well argue that "Rakudo is compatible with libssl", for all the relationship Rakudo source code has with Perl source code.