Compatibility with perl 5

2004-04-13 Thread David Cantrell
A few days ago I briefly discussed with Nicholas Clark (current perl 5.8
pumpking) about making perl5 code forward-compatible with perl6.  A
quick look through the mailing list archives didn't turn up anything
obvious, and I don't recall any mechanism being presented in any of the
Apocalypses, so ...

Perl 6, we are promised, will try to run "legacy" code unchanged.  How
will it spot such legacy code?  Doing this reliably is a hard problem,
but we can make it easier.  I suggest that people put:

  use perl5;

near the top of their perl programs, scripts and modules.  This would be
a clear indicator to the perl6 compiler that this is a perl5 program
without it having to do any complicated and error-prone heuristics.  And
it could be implemented really easily in perl5 with no changes to the
core at all:

package perl5;
"i don't do anything yet";

If such a null-op pragma were to go into the next perl 5.8.x release
people could start preparing their existing code for perl 6 right now.
Which is surely a Good Thing.  And of course if the pragma were to also
be available to download seperately from the CPAN people still using
older 5.x releases could still use it.

-- 
David Cantrell


Re: Compatibility with perl 5

2004-04-13 Thread Mark J. Reed
On 2004-04-13 at 13:16:02, David Cantrell wrote:
> Perl 6, we are promised, will try to run "legacy" code unchanged.  How
> will it spot such legacy code?  

My understanding has been that perl6 will assume a program is Perl 5 unless
it sees a Perl 6 keyword such as 'module' or 'class'.


-- 
Mark REED| CNN Internet Technology
1 CNN Center Rm SW0831G  | [EMAIL PROTECTED]
Atlanta, GA 30348  USA   | +1 404 827 4754


Re: Compatibility with perl 5

2004-04-13 Thread Matthew Walton
Mark J. Reed wrote:
On 2004-04-13 at 13:16:02, David Cantrell wrote:

Perl 6, we are promised, will try to run "legacy" code unchanged.  How
will it spot such legacy code?  


My understanding has been that perl6 will assume a program is Perl 5 unless
it sees a Perl 6 keyword such as 'module' or 'class'.
That could be problematic, because if Perl 6 sees something like:

my %myhash;
%myhash{'foo'} = 'bar';
Is it going to think 'ahah, perl 6' or 'perl 5 with errors'?

That's assuming my understanding of hash subscripting and variable 
declarations in Perl 6 is even slightly correct, of course.



Re: Compatibility with perl 5

2004-04-13 Thread Juerd
David Cantrell skribis 2004-04-13 13:16 (+0100):
> Perl 6, we are promised, will try to run "legacy" code unchanged.  How
> will it spot such legacy code?  Doing this reliably is a hard problem,
> but we can make it easier.  I suggest that people put:
>   use perl5;

Why change what already works?

use 5;
no 6;

It could be a special case: not throwing a fatal exception, but instead
changing the grammar to a Perl 5 compatible one.


Juerd


Re: Compatibility with perl 5

2004-04-13 Thread David Cantrell
On Tue, Apr 13, 2004 at 02:27:08PM +0200, Juerd wrote:
> David Cantrell skribis 2004-04-13 13:16 (+0100):
> > Perl 6, we are promised, will try to run "legacy" code unchanged.  How
> > will it spot such legacy code?  Doing this reliably is a hard problem,
> > but we can make it easier.  I suggest that people put:
> >   use perl5;
> Why change what already works?
> use 5;
> no 6;

But "no VERSION" does not work, at least in 5.8.3:

  [EMAIL PROTECTED]:~$ cat foo
  use 5;
  no 6;
  print "version 5, not version 6\n";
  [EMAIL PROTECTED]:~$ perl foo
  syntax error at foo line 2, near "no 6;"
  Execution of foo aborted due to compilation errors.

and my discussion with Nicholas didn't lead me to believe that it would
work in the upcoming 5.8.4 either.

-- 
David Cantrell | http://www.cantrell.org.uk/david

  All principles of gravity are negated by fear
-- Cartoon Law V


Re: semantic and implementation of pairs

2004-04-13 Thread Stéphane Payrard
I have confused assignement and initialisation in my previous
mail. Because they are two different operations, there is no
problem they have different semantics. A6 described both
operations. It described pairs as arguments used to initialize
parameters and pairs in assignement.

--
  stef


Re: Compatibility with perl 5

2004-04-13 Thread Thomas A. Boyer
Matthew Walton wrote:

Mark J. Reed wrote:

On 2004-04-13 at 13:16:02, David Cantrell wrote:

Perl 6, we are promised, will try to run "legacy" code unchanged.  How
will it spot such legacy code?  


My understanding has been that perl6 will assume a program is Perl 5 
unless
it sees a Perl 6 keyword such as 'module' or 'class'.


That could be problematic, because if Perl 6 sees something like:

my %myhash;
%myhash{'foo'} = 'bar';
Is it going to think 'ahah, perl 6' or 'perl 5 with errors'?
It's going to think 'ahah', perl 5'. Because it doesn't contain any Perl 
6 keyword (such as 'module' or 'class'), as Mark said.

=thom
Reality is that which, when you stop believing it, doesn't go away. 
-Philip K. Dick





Re: Compatibility with perl 5

2004-04-13 Thread Matthew Walton
Thomas A. Boyer wrote:

Matthew Walton wrote:
That could be problematic, because if Perl 6 sees something like:

my %myhash;
%myhash{'foo'} = 'bar';
Is it going to think 'ahah, perl 6' or 'perl 5 with errors'?


It's going to think 'ahah', perl 5'. Because it doesn't contain any Perl 
6 keyword (such as 'module' or 'class'), as Mark said.
But then trying to process that as Perl 5 will result in an error. This 
doesn't seem particularly sane to me. Will we have to say

use 6;

on all Perl 6 programs to avoid this kind of thing?

Forgive me if I'm missing something obvious here.




Re: Compatibility with perl 5

2004-04-13 Thread Luke Palmer
David Cantrell writes:
> A few days ago I briefly discussed with Nicholas Clark (current perl 5.8
> pumpking) about making perl5 code forward-compatible with perl6.  A
> quick look through the mailing list archives didn't turn up anything
> obvious, and I don't recall any mechanism being presented in any of the
> Apocalypses, so ...

Well, there is one, as far as I understand it.  Your "use perl5;" is
spelled "package".  That is, perl will assume Perl 6 unless it sees
"package SomethingOrOther;" (since Perl 6 calls them "module"s).  So, to
force Perl 5 interpretation, use:

package main;

Luke


Re: Compatibility with perl 5

2004-04-13 Thread Dan Sugalski
At 4:07 PM +0100 4/13/04, Matthew Walton wrote:
Thomas A. Boyer wrote:

Matthew Walton wrote:
That could be problematic, because if Perl 6 sees something like:

my %myhash;
%myhash{'foo'} = 'bar';
Is it going to think 'ahah, perl 6' or 'perl 5 with errors'?


It's going to think 'ahah', perl 5'. Because it doesn't contain any 
Perl 6 keyword (such as 'module' or 'class'), as Mark said.
But then trying to process that as Perl 5 will result in an error. 
This doesn't seem particularly sane to me. Will we have to say

use 6;

on all Perl 6 programs to avoid this kind of thing?

Forgive me if I'm missing something obvious here.
You're not, and there is no guaranteed universal heuristic. Being 
explicit, via command line switches or executable names, is the 
prudent way to go.
--
Dan

--"it's like this"---
Dan Sugalski  even samurai
[EMAIL PROTECTED] have teddy bears and even
  teddy bears get drunk


Re: Compatibility with perl 5

2004-04-13 Thread Thomas A. Boyer
Matthew Walton wrote:

Thomas A. Boyer wrote:

Matthew Walton wrote:

That could be problematic, because if Perl 6 sees something like:

my %myhash;
%myhash{'foo'} = 'bar';
It's going to think 'ahah', perl 5'. Because it doesn't contain any 
Perl 6 keyword (such as 'module' or 'class'), as Mark said.
But then trying to process that as Perl 5 will result in an error. 
This doesn't seem particularly sane to me. Will we have to say

use 6;

on all Perl 6 programs to avoid this kind of thing?

Forgive me if I'm missing something obvious here.

The original question was "how do I label my code as Perl 5?" The 
correct answer, according to Apocalypse 1, is to start your source with 
"package." If you didn't want to put your code in a package, then start 
it with "package main".

The other question was "how do I label my code as Perl 6?" The correct 
answer, according to Apocalypse 1, is to start your source with "module" 
or "class".

Here is the relevant paragraph from the apocalypse:
 I hereby declare that a |package| declaration at the front of a
 file unambiguously indicates you are parsing Perl 5 code. If
 you want to write a Perl 6 module or class, it'll start with
 the keyword |module| or |class|. I don't know yet what the exact
 syntax of a module or a class declaration will be, but one
 thing I do know is that it'll set the current global namespace
 much like a |package| declaration does.
=thom
A lot of people become pessimists from financing optimists.


Re: Compatibility with perl 5

2004-04-13 Thread Matthew Walton
Thomas A. Boyer wrote:
The original question was "how do I label my code as Perl 5?" The 
correct answer, according to Apocalypse 1, is to start your source with 
"package." If you didn't want to put your code in a package, then start 
it with "package main".

The other question was "how do I label my code as Perl 6?" The correct 
answer, according to Apocalypse 1, is to start your source with "module" 
or "class".

Here is the relevant paragraph from the apocalypse:
  I hereby declare that a |package| declaration at the front of a
  file unambiguously indicates you are parsing Perl 5 code. If
  you want to write a Perl 6 module or class, it'll start with
  the keyword |module| or |class|. I don't know yet what the exact
  syntax of a module or a class declaration will be, but one
  thing I do know is that it'll set the current global namespace
  much like a |package| declaration does.
Righty-ho then. That's not actually all that bad, I'm used to starting 
files with 'module' in Haskell (where it's not always compulsory but is 
a good idea) so I'm sure I can cope with a similar thing in Perl 6.

Thanks



Re: Compatibility with perl 5

2004-04-13 Thread Aaron Sherman
On Tue, 2004-04-13 at 11:16, Thomas A. Boyer wrote:

> Here is the relevant paragraph from the apocalypse:
>   I hereby declare that a |package| declaration at the front of a
>   file unambiguously indicates you are parsing Perl 5 code. If
>   you want to write a Perl 6 module or class, it'll start with
>   the keyword |module| or |class|. I don't know yet what the exact
>   syntax of a module or a class declaration will be, but one
>   thing I do know is that it'll set the current global namespace
>   much like a |package| declaration does.

So, there are many ways that Perl 6 could tell. Here's a pseudo-code
(because I don't fully know what Perl 6 will look like yet) example that
is disambiguated in many ways:

#!/usr/bin/perl6
# Use binary "perl6" which defaults to Perl 6 instead of Perl 5.
# This is easy, costs us nothing and does not affect Perl 5
use 6; # Force Perl 6 mode, no need for "no 6" in Perl 5,
# as Perl 6 can safely read "use 5" as "force Perl 5 mode"
class myprog { # encapsulate my program as a class Java-style
# Might need some kind of property to force mainishness
method main([EMAIL PROTECTED]) {
print "Hello world\n";
}
}


Or, if you prefer Perl 5 style:

#!/usr/bin/perl6

use 6;
class null {} # Just for the keyword
print "Hello world\n";

Or, if you prefer C style:

#!/usr/bin/perl6

use 6;
stdout.print("Hello world\n"); # not sure if the invocant will do it

-- 
Aaron Sherman <[EMAIL PROTECTED]>
Senior Systems Engineer and Toolsmith
"It's the sound of a satellite saying, 'get me down!'" -Shriekback




Re: Compatibility with perl 5

2004-04-13 Thread David Cantrell
On Tue, Apr 13, 2004 at 09:16:21AM -0600, Thomas A. Boyer wrote:
> The original question was "how do I label my code as Perl 5?" The 
> correct answer, according to Apocalypse 1, is to start your source with 
> "package." If you didn't want to put your code in a package, then start 
> it with "package main".

This is something that should be brought to a wider audience cos then
you won't get more people like me wandering in and asking silly
questions.  I shall write something up for perlmonks tomorrow.

-- 
David Cantrell | Official London Perl Mongers Bad Influence