Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Of course I can :)

In perl6 the opening paren (() of a function cannot be separated from the function by whitespace:

Legal in perl5: my $foo = foo( 1 ); # A my $foo = foo(1); # B my $foo = foo (1); # C my $foo = foo ( 1 # D );

For reasons I explain in my style guide MY preference is C. Perl6 only supports A and B.

This is only an example. The syntax rules go deeper than that, causing the dot (.) to be special too, so that

my $foo = $object->method (1) ->method (2) ->method (3);

chaining as allowed in perl5 (break to a newline wherever you like), would NOT translate to

my $foo = $object.method(1) .method(2) .method(3);

This is bad (IMHO), see:

$ cat t.pl use v6; class C { has Int $.x is rw = 0; method foo (Int $i) { $!x += $i; return self; } method bar (Int $i) { $!x -= $i; return self; } } C.new().foo(1).bar(2).say; $ perl6 t.pl C.new(x => -1) $ cat t.pluse v6; class C { has Int $.x is rw = 0; method foo (Int $i) { $!x += $i; return self; } method bar (Int $i) { $!x -= $i; return self; } } C.new() .foo(1) .bar(2) .say; $ perl6 t.pl ===SORRY!=== Error while compiling t.pl Two terms in a row at t.pl:11 ------> ⏏.foo(1) expecting any of: infix stopper infix or meta-infix statement end statement modifier statement modifier loop

This is because a leading dot (after whitespace) will see the next word as method on the current topic ($_) instead of as a method on the previvious "thing". As the previous line has no trailing semi-colon, I would prefer the default to be different. The perl6 core dev people state it is possible with a backslash:

cat t.pl use v6; class C { has Int $.x is rw = 0; method foo (Int $i) { $!x += $i; return self; } method bar (Int $i) { $!x -= $i; return self; } } C.new()\ .foo(1)\ .bar(2)\ .say; $ perl6 t.pl C.new(x => -1)

But do you want your code to look ugly like that? I do not!


Enjoy, Have FUN! H.Merijn

In reply to Re^2: Porting (old) code to something else by Tux
in thread Porting (old) code to something else by Tux

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-23 17:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found