Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by moritz (Cardinal)
on Apr 23, 2010 at 09:08 UTC ( #836474=note: print w/ replies, xml ) Need Help??

Comment on Re^5: A wholly inadequate reply to an Anonymous Monk
Re^6: A wholly inadequate reply to an Anonymous Monk
by Anonymous Monk on Apr 23, 2010 at 10:40 UTC
    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?

      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.

      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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2014-09-16 12:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (14 votes), past polls