Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^6: A wholly inadequate reply to an Anonymous Monk

by Anonymous Monk
on Apr 23, 2010 at 10:40 UTC ( #836490=note: print w/replies, xml ) Need Help??

in reply to Re^5: A wholly inadequate reply to an Anonymous Monk
in thread A wholly inadequate reply to an Anonymous Monk

S01 says "we sure wish so".

As for it actually happening..

Perl 6 has drastically different calling conventions than Perl 5, and even now has characters in its standard library functions that are prohibited in Perl 5 ("-"). The only way I see them inter-operating is through some hairy foreign function interface. Let's take this example from S01:

use v6; # ...some Perl 6 code... { use v5; # ...some Perl 5 code... { use v6; # ...more Perl 6 code... } }
How would this work with some real code dropped in:
use v6; multi sub foo-bar(Str $a, Str $b) { "str/str" } multi sub foo-bar(Str $a, Int $b) { "str/int" } multi sub foo-bar(Str $a, Num $b) { "str/num" } multi sub foo-bar(Str $a, Array $b) { "str/num" } { use v5; # oh shit, what now? do I: foo-bar("1", "2"); # syntax error call_perl6_func("foo-bar", "1", "2"); # calls, but breaks sinc +e Perl5 has no types # Maybe this instead: call_perl6_func("foo-bar", Perl6cast("Str", "1"), Perl6cast("S +tr", "2"); { use v6; # now how do I call perl 5? } }
That's just the simple case of calling a subroutine. How about the totally incompatible object systems?

Does someone have a plan for getting this working?

Replies are listed 'Best First'.
Re^7: A wholly inadequate reply to an Anonymous Monk
by audreyt (Hermit) on Apr 23, 2010 at 13:36 UTC

    The dash syntax one was straightforward. This works in Perl 5:

    *{"foo-bar"} = sub { "Hello, @_!\n" }; print &{"foo-bar"}('world');

    It might work in Perl 4 or even Perl 3, but I had not verified yet... :-)

    As for object systems: Well, the very notion of "object systems" means "interfaces as types", and it's precisely across those interfaces we bridge between calling conventions.

    Please refer to William Cook's slides and essay for more rigorous explanations of the interface/OO link.

    So in that sense, there are really no totally incompatible object systems, since any two such systems can embed one another using cross-system meta-object protocol.

Re^7: A wholly inadequate reply to an Anonymous Monk
by audreyt (Hermit) on Apr 23, 2010 at 14:25 UTC

    And as for the type-based multi-dispatch case, we can observe below that Perl 5 does have the notion of runtime types:

    A:~ au$ perl -MDevel::Peek -e 'Dump 3' SV = IV(0x100827190) at 0x100827198 REFCNT = 1 FLAGS = (IOK,READONLY,pIOK) IV = 3 A:~ au$ perl -MDevel::Peek -e 'Dump "3"' SV = PV(0x100801258) at 0x1008271b0 REFCNT = 1 FLAGS = (POK,READONLY,pPOK) PV = 0x100207f60 "3"\0 CUR = 1 LEN = 16

    Note that the IV above refers to an integer type, and PV refers a stringish type. (cf. perlguts for details...)

    As for the casting functions, Perl 5 has them built-in:

    "".$x # to string 0+$x # to number int($x) # to integer

    Hope that helps! :-)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://836490]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2021-10-22 11:12 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (85 votes). Check out past polls.