Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
S06: Pairs as lvalues
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ingo Blechschmidt  
View profile  
 More options Feb 26 2005, 7:27 am
Newsgroups: perl.perl6.language
From: ibl...@web.de (Ingo Blechschmidt)
Date: Sat, 26 Feb 2005 12:27:19 +0000 (UTC)
Local: Sat, Feb 26 2005 7:27 am
Subject: S06: Pairs as lvalues
Hi,

quoting http://dev.perl.org/perl6/synopsis/S06.html:

> Pairs can be used as lvalues. The value of the pair is the
> recipient of the assignment:

>     (key => $var) = "value";

> When binding pairs, names can be used to "match up" lvalues
> and rvalues:

>     (who => $name, why => $reason) := (why => $because, who => "me");

that's really convenient, but what will the following code do?
  my $x = (a => 42); # $x is a Pair.
  $x = 13;           # Is $x now the Pair (a => 13) or
                     #           the Int 13?

When executing the second line, $x is a Pair. And it is used as a
lvalue. So, according to S06, the assignment will only change the
value of the Pair, not the Pair itself.

But I doubt this is what most programmers will expect -- example:
  sub foo (Any $x) {
    $x = 13; # Won't always make $x an Int.
    ...;
  }
  my $pair = (a => 42);
  foo($pair);

So, does this Pairs-as-lvalue rule only affect "real syntax-Pairs"?
If not, what would the sub unpairify in the following code have to
look like?
  my $x = (a => 42);
  unpairify($x, 13);
  # $x is now the Int 13.

  sub unpairify (Any $x is rw, Int $num) {
    ...; # fill in please
  }

--Ingo

--
Linux, the choice of a GNU | self-reference, n. - See self-reference  
generation on a dual AMD-  |
Athlon!                    |


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Uri Guttman  
View profile  
 More options Feb 26 2005, 9:33 am
Newsgroups: perl.perl6.language
From: u...@stemsystems.com (Uri Guttman)
Date: Sat, 26 Feb 2005 09:33:43 -0500
Local: Sat, Feb 26 2005 9:33 am
Subject: Re: S06: Pairs as lvalues

>>>>> "IB" == Ingo Blechschmidt <ibl...@web.de> writes:

  IB> Hi,
  IB> quoting http://dev.perl.org/perl6/synopsis/S06.html:
  >> Pairs can be used as lvalues. The value of the pair is the
  >> recipient of the assignment:
  >>
  >> (key => $var) = "value";
  >>
  >> When binding pairs, names can be used to "match up" lvalues
          ^^^^^^^
  >> and rvalues:
  >>
  >> (who => $name, why => $reason) := (why => $because, who => "me");

note the binding := which is not the same as =. binding is similar to
aliasing. in the above case it matches the names and assigns the new
values accordingly. i am not sure what happens if you have more pairs on
one side or the other (does it behave as hashes would and just overwrite
the common keys and assign new ones as needed?)

  IB> that's really convenient, but what will the following code do?
  IB>   my $x = (a => 42); # $x is a Pair.
  IB>   $x = 13;           # Is $x now the Pair (a => 13) or
  IB>                      #           the Int 13?

$x is 13 now as you assigned it. to assign the value of the pair as an
lvalue i think you would do:

        $x.value = 13 ;

uri

--
Uri Guttman  ------  u...@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ingo Blechschmidt  
View profile  
 More options Feb 26 2005, 9:49 am
Newsgroups: perl.perl6.language
From: ibl...@web.de (Ingo Blechschmidt)
Date: Sat, 26 Feb 2005 14:49:08 +0000 (UTC)
Local: Sat, Feb 26 2005 9:49 am
Subject: Re: S06: Pairs as lvalues
Hi,

Uri Guttman <uri <at> stemsystems.com> writes:

> note the binding := which is not the same as =. binding is
> similar to aliasing. in the above case it matches the names
> and assigns the new values accordingly.

that makes sense. But consider:

> >>>>> "IB" == Ingo Blechschmidt <iblech <at> web.de> writes:
>   IB> quoting http://dev.perl.org/perl6/synopsis/S06.html:
>   >> Pairs can be used as lvalues. The value of the pair is the
>   >> recipient of the assignment:

>   >> (key => $var) = "value";

     # Note: Simple assignment, no binding!

Here, there's a simple assignment, no binding. Is this a typo then,
and it should be read as C<< (key => $var) := "value" >>? If yes,
everything's clear.

If not, then consider:
  (key => $var) = "value"; # Example from S06
  my $value = "value";
  (key => $var) = $value;  # RHS replaced by a variable,
                           # should make not difference.
  my $pair = (key => 3);
  $pair    = $value;       # Former LHS (a Pair) replaced
                           # by a Pair variable, should
                           # make no difference, too...
  say $pair.value;         # Will print "value"...

--Ingo

--
Linux, the choice of a GNU | Mathematicians practice absolute freedom.
generation on a dual AMD-  | -- Henry Adams  
Athlon!                    |


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luke Palmer  
View profile  
 More options Feb 26 2005, 6:03 pm
Newsgroups: perl.perl6.language
From: l...@luqui.org (Luke Palmer)
Date: Sat, 26 Feb 2005 16:03:21 -0700
Local: Sat, Feb 26 2005 6:03 pm
Subject: Re: S06: Pairs as lvalues

Ingo Blechschmidt writes:
> that's really convenient, but what will the following code do?
>   my $x = (a => 42); # $x is a Pair.
>   $x = 13;           # Is $x now the Pair (a => 13) or
>                      #           the Int 13?

It's the Int 13.  Your example looks a lot like this one:

    my $x = [ 1, 2, 3 ];
    $x = 13;

And you could say that is an error because:

    [ 1, 2, 3 ] = 13;

Is an error, but you'd be wrong.  You see, in your example, the pair is
not "functioning as an lvalue".  The variable is the thing that is the
lvalue, not the pair.

I belive you could get the pair as an lvalue if you did:

    my (Pair $x) := (a => 42);
    $x = 13;

Because the variable x is now *fundamentally* a pair; it has no
container, so to speak.  But it would die, because you're trying to
change a constant value.

Luke


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ingo Blechschmidt  
View profile  
 More options Feb 27 2005, 4:33 am
Newsgroups: perl.perl6.language
From: ibl...@web.de (Ingo Blechschmidt)
Date: Sun, 27 Feb 2005 09:33:36 +0000 (UTC)
Local: Sun, Feb 27 2005 4:33 am
Subject: Re: S06: Pairs as lvalues
Hi,

Luke Palmer <luke <at> luqui.org> writes:

> Ingo Blechschmidt writes:
> >   my $x = (a => 42); # $x is a Pair.
> >   $x = 13;           # Is $x now the Pair (a => 13) or
> >                      #           the Int 13?

> You see, in your example, the pair is not "functioning as
> an lvalue".  The variable is the thing that is the lvalue,
> not the pair.

ah! That clears it up! Thanks! :)

--Ingo

--
Linux, the choice of a GNU | When cryptography is outlawed, bayl bhgynjf
generation on a dual AMD-  | jvyy unir cevinpl!  
Athlon!                    |


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google