Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Perl 6 - Operator renaming

by BaldPenguin (Friar)
on Sep 01, 2005 at 19:59 UTC ( [id://488479]=note: print w/replies, xml ) Need Help??


in reply to Perl 6 - Operator renaming

I don't understand why the tilde has to be used for string concantenations, most languages (that I know) use the + for both, testing the object before performing concat or addition.

Don
WHITEPAGES.COM | INC
Everything I've learned in life can be summed up in a small perl script!

Replies are listed 'Best First'.
Re^2: Perl 6 - Operator renaming
by mirod (Canon) on Sep 01, 2005 at 20:35 UTC

    For the same reason Perl 5 has '+'and '.': because of the extremely convenient auto-conversion of strings to numbers:

    # in Perl 5 $i=10; # could be $i="10"; $j=1; # could be $j="1"; print $i + $j; # 11 print $i . $j; # 101
Re: Perl 6 - Operator renaming
by jonadab (Parson) on Sep 02, 2005 at 12:46 UTC
    most languages (that I know) use the + for both

    Yes, but other languages don't have Perl's notion of context. In Perl, the + operator supplies numeric context, but the concatenation operator supplies string context. The difference can be important.

    my $barcode_prefix = "25728"; for my $b (@series) { my $chkd = checkdigit($barcode_prefix . $b); }

    If you change the concatenation operator there to +, a completely different thing happens and the check digit comes out wrong. (And yes, I have written code that calculates barcode check digits in Perl5.)

Re^2: Perl 6 - Operator renaming
by lidden (Curate) on Sep 01, 2005 at 20:25 UTC
    In those languages you must do somthebg like int($a) + int($b) if you have read the numbers from a file, in Perl you can add them whitout telling them to be numbers first. It also means there must be a diffrent concat operator.
Re^2: Perl 6 - Operator renaming
by chester (Hermit) on Sep 01, 2005 at 20:20 UTC
    I'm not sure how it'd work what with Perl constantly auto-stringifying and auto-numberfying things. I'd think we need separate numeric-add and string-concatenate operators for the same reason we need separate == and eq.
Re^2: Perl 6 - Operator renaming
by Anonymous Monk on Sep 01, 2005 at 20:08 UTC
    That's an easy one...
    1. '+' should be associative (like in mathematics).
    2. Concatenation isn't associative.
    3. Therefore, concatenations shouldn't be denoted by '+'.
      Concatenation isn't associative.
      This is, of course, completely wrong. Mathematically, the set of all strings over an alphabet forms a (associative) monoid under the concatenation operator.

      Did you mean commutative?

      blokhead

        For those of us mere mortals.
        • Given a set A with members a, b, c, and an operator *, * is said to be an associative operation iff (a * b) * c = a * (b * c) for arbitrary a, b, c within A. Even plainer: the order in which you take operations doesn't matter.
        • Given a set A with members, a, b, and an operator *, * is said to be a commutative operation iff a * b = b * a for arbitrary a, b within A. Even plainer: operand order doesn't matter.

        thor

        Feel the white light, the light within
        Be your own disciple, fan the sparks of will
        For all of us waiting, your kingdom will come

        <

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found