Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^10: Order of evaluation/interpolation of references

by BrowserUk (Patriarch)
on Mar 08, 2012 at 03:30 UTC ( [id://958418]=note: print w/replies, xml ) Need Help??


in reply to Re^9: Order of evaluation/interpolation of references
in thread Order of evaluation/interpolation of references

it's well defined that all arguments are evaluated before they are passed to a function.

If this is right:

C:\test>perl -E"$\"=''; {my@x; sub X{ push@x,'x';;\@x}}; say qq[@{X()} +@{X()}]" xxx

Then this is wrong:

C:\test>perl -E"{my$x; sub X{ $x.='x';\$x}}; say qq[${X()}${X()}]" xxxx

And vice versa.

From your other post:

it's a clear violation ...

Of what? Your sensibilities? Do you think the same about print "The price is: $obj->tostring()\n";?

Saying you don't like it, is not the same as it being illegal. And it has always been legal, so it should be consistent.

From my understanding, interpolating code references into strings is not just legal in Perl6, but further enhanced.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^11: Order of evaluation/interpolation of references
by LanX (Saint) on Mar 08, 2012 at 12:28 UTC
    > "The price is: $obj->tostring()\n";?

    Isn't evaled for me, could you please give me a complete and working snippet?

    Cheers Rolf

      > "The price is: $obj->tostring()\n";? Isn't evaled for me,

      I know. But wouldn't it be convenient if it was interpolated(*)?

      See http://szabgab.com/perl-6--scalar-array-and-hash-interpolation.html

      Just expressions: say "Take 1+4";

      will print: Take 1+4

      as expected but as I wrote you can put any expression in the curly braces, so you can also write: say "Take {1+4}";

      that will print: Take 5

      Isn't that nicer than print "Take " . ( 1 + 4 ) . "\n";?

      And remember, interpolation is not like string eval, more like block eval. It can be compiled at compile time, and just run on demand.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        Admittedly I'm pretty far off topic from the thread, but I prefer:

        print "Take ", 1 + 4, "\n";

        and like this even more:

        printf "Take %i\n", 1 + 4;

        But the prospect of a cleaner syntax to interpolate more... stuff than we currently can is interesting.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-18 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found