Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

on Topic

2 views
Skip to first unread message

fear...@figaro.weizmann.ac.il

unread,
Nov 7, 2002, 9:09:35 AM11/7/02
to Allison Randal, perl6-language

I just want to be sure I understand correctly :

In your article at perl.com you describes various ways and situations
when perl creates a topic and this is described as perl making the
following binding on my behalf:

$_ := $some_var ; *1*

and probably marking $_ with some additional properties (e.g. is
read-only ...) .

questions:

???

if I will write that explicitly myself will that have *the same*
effect ? in other words, is *1* _all_ that topic is about ? Or there
is some additional magic. particularly , will "when" work as before ,
What will happen if I will _override_ $_ explicitly inside
e.g. "given" construct or other topicalizers:

my $x,$z;
given $x->$y {
$_ := $z ;
when 2 { ... } #checks against $z ???
}


???

methods topicalize their invocant. Is $self aliased to $_ inside the
method in this ex. ?

method sub_ether ($self: $message) {
.transmit( .encode($message) );
}

will it be an error to write
method sub_ether ($self: $message, $x is topic) {...}

what happens if I write
method sub_ether ($self: $message) {
$_ := $message ;
}
or

method sub_ether ($self: $message) {
$_ = $message ;
}

is $_ always lexical variable. Or I can have $MyPackage::_ ?


and just on the related topic :

* can I alias $something to $_ ?
$something := $_

(it seems that I can , because $_ is just another variable )

also , is this valid ?

$b := $a ;
$c := $b ;

( now changing value of one variable will change other two ??? )


or e.g.

$a = 1 ;
$Z = 10 ;

$b := $a ;
$c := $b ;

print $c # prints 1
$a := $Z ;
print $c # prints 10
$a = 5;
print $Z # prints 5

am I wrong ?

also

@a := ( $a, $b)
$b := $c
@a[1] = 10 ;
print $c # prints 10

???

thanks
Arcadi


Me

unread,
Nov 7, 2002, 2:36:07 PM11/7/02
to fear...@figaro.weizmann.ac.il, Allison Randal, perl6-language
In the hope this saves Allison time, and/or
clarifies things for me, I'll attempt some
answers.

> In your article at perl.com you describes
> various ways and situations when perl
> creates a topic and this is described as
> perl making the following binding on my behalf:
>
> $_ := $some_var ; *1*

Well, $_ might not be bound to a named variable
but instead be just set to a value, or it might
be bound to an array cell or some other unnamed
container.


> is *1* _all_ that topic is about ?

Sorta. To quote an excellent summary:

"Topic is $_".


> my $x,$z;
> given $x->$y {
> $_ := $z ;
> when 2 { ... } #checks against $z ???
> }

Yes.


> methods topicalize their invocant. Is $self
> aliased to $_ inside the method in this ex. ?
>
> method sub_ether ($self: $message) {
> .transmit( .encode($message) );
> }

Yes.


> will it be an error to write
> method sub_ether ($self: $message, $x is topic) {...}

No.


> what happens if I write
> method sub_ether ($self: $message) {
> $_ := $message ;
> }
> or
>
> method sub_ether ($self: $message) {
> $_ = $message ;
> }

Both Ok. $_ is "it" and has the value $message;
in the former case $_ and $message are bound.


> is $_ always lexical variable.

Yes.


> Or I can have $MyPackage::_ ?

You can copy or alias any value.


> * can I alias $something to $_ ?
> $something := $_

Sure. Because...

> (it seems that I can , because $_ is just
> another variable )

> $b := $a ;

> $c := $b ;
>
> ( now changing value of one variable will
> change other two ??? )

Yes.


> or e.g.
>
> $a = 1 ;
> $Z = 10 ;
>
> $b := $a ;
> $c := $b ;
>
> print $c # prints 1
> $a := $Z ;
> print $c # prints 10
> $a = 5;
> print $Z # prints 5

Yes.


> also
>
> @a := ( $a, $b)

Er, I don't think (it makes sense that) you
can bind to a literal.

> $b := $c
> @a[1] = 10 ;
> print $c # prints 10

Lost you there, even ignoring the literal issue.

--
ralph

fear...@figaro.weizmann.ac.il

unread,
Nov 7, 2002, 4:31:59 PM11/7/02
to Me, fear...@figaro.weizmann.ac.il, Allison Randal, perl6-language
Me writes:
> In the hope this saves Allison time, and/or
> clarifies things for me, I'll attempt some
> answers.
>

Thanks .

> > In your article at perl.com you describes
> > various ways and situations when perl
> > creates a topic and this is described as
> > perl making the following binding on my behalf:
> >
> > $_ := $some_var ; *1*
>
> Well, $_ might not be bound to a named variable
> but instead be just set to a value,

sure , I forgot , e.g.

given $x+1 {
when 2 { ... }
}

or it might
> be bound to an array cell or some other unnamed
> container.
>

>
>

> > is $_ always lexical variable.
>
> Yes.
>
>
> > Or I can have $MyPackage::_ ?
>
> You can copy or alias any value.

no, I mean is '$_' a valid name to live in package namespace ?
$main::_ = 1 ;
$::_ = 1;
our $_ ;

???

or variable with name '$_' is always implicitly "my" ??

> > also
> >
> > @a := ( $a, $b )
>
> Er, I don't think (it makes sense that) you
> can bind to a literal.

I think I meant this :

*@a := ( $a, $b )

although , to be true , I dont understand why the first version is
wrong. Do you mean that @a := expect 1 array variable and I give it
2 scalars ?

but if :

$ref = ( $a, $b ) ;
@a := $ref ;

this , probably is OK, but now changing $a or $b will not affect @a
and vice-versa.

so , anyway,

*@a := ( $a, $b )
> > $c := $b

> > @a[1] = 10 ;
> > print $c # prints 10

???


and also , one more question.
is this correct :

$x is constant = 1;
$y = 5;
$y := $x ;
$y = 1 # ERROR cannot change constant value

or in words, are (all) compile - time properties passed automatically
upon binding ?

thanks ,

arcadi .

Larry Wall

unread,
Nov 7, 2002, 5:56:34 PM11/7/02
to Me, fear...@figaro.weizmann.ac.il, Allison Randal, perl6-language
On Thu, Nov 07, 2002 at 01:36:07PM -0600, Me wrote:
: > is *1* _all_ that topic is about ?

:
: Sorta. To quote an excellent summary:
:
: "Topic is $_".

A "real" topicalizer also sets a topicalizer scope that can be broken out of.

: > also

: >
: > @a := ( $a, $b)
:
: Er, I don't think (it makes sense that) you
: can bind to a literal.

Well, it makes as much sense as binding it in a function parameter. In this
case it'd be equivalent to

@a := [ $a, $b ]

That is, it's bound to a temporary.

: > $b := $c

: > @a[1] = 10 ;
: > print $c # prints 10

No, the [...] copies values upon composing the anonymous array.

Larry

fear...@figaro.weizmann.ac.il

unread,
Nov 13, 2002, 8:11:32 AM11/13/02
to Me, Allison Randal, perl6-language
Me writes:
> Sorta. To quote an excellent summary:
>
> "Topic is $_".
>
> ........

>
> > is $_ always lexical variable.
>
> Yes.
>
>
> > Or I can have $MyPackage::_ ?
>
> You can copy or alias any value.
>

so if I understand correctly ,

Every topicalizer defines a topicalizer scope in which there is
implicit declaration

my $_ ;

and then lexical $_ ( implicitely ) is bound to ( or assigned to )
whatever it should in this particular topicalizer. And from that on $_
is just another lexical variable .

Question(s) :

with no "use strict vars" any "just another variable" is taken by perl as
being global -- it is implicitly "our $just_another_var;" (???)
about any lexical veriable ( just_another_variable ) Perl have to be
explicitly informed as being such . is $_ just_another_variable in
that respect too ???

in other words , what happens if I just use $_ ( that is , without
previous declaration ) *outside any topicalizer* ?

* will it be implicitly "our $_" ( probably not , because it is
always lexical )
or * will it be implicitely "my $_" -- class/package lexical
or * will it be error to just use it without declaration
* with "use strict vars"
* with "no strict vars "

will it be an error to declare it as "our $_" ;

and to repeat the question from previous post ,
what will perl do when it see

$My_Package::_ = 1 ;


???


thanks , arcadi .

Larry Wall

unread,
Nov 13, 2002, 2:21:50 PM11/13/02
to fear...@figaro.weizmann.ac.il, Me, Allison Randal, perl6-language
On Wed, Nov 13, 2002 at 03:11:32PM +0200, fear...@figaro.weizmann.ac.il wrote:
: so if I understand correctly ,
:
: Every topicalizer defines a topicalizer scope in which there is
: implicit declaration
:
: my $_ ;
:
: and then lexical $_ ( implicitely ) is bound to ( or assigned to )
: whatever it should in this particular topicalizer. And from that on $_
: is just another lexical variable .

Yes.

: Question(s) :

:
: with no "use strict vars" any "just another variable" is taken by perl as
: being global -- it is implicitly "our $just_another_var;" (???)
: about any lexical veriable ( just_another_variable ) Perl have to be
: explicitly informed as being such . is $_ just_another_variable in
: that respect too ???

$_ is always a lexical. Every file scope has an implicit "my $_" at the top.
Every nested scope either sets up its own lexical $_ or aliases to an outer $_.

: in other words , what happens if I just use $_ ( that is , without


: previous declaration ) *outside any topicalizer* ?

There is no "outside any topicalizer" from that standpoint. However,
$_ does start off undefined in an implicit topicalizer, and we may
well disallow "break" to such an implicit topicalizer at file scope,
and maybe at subroutine scope.

: * will it be implicitly "our $_" ( probably not , because it is
: always lexical )

Correct, $_ is always lexical. But...

: or * will it be implicitely "my $_" -- class/package lexical

There's no such thing as a "class/package lexical". I think you
mean file-scoped lexical here.

: or * will it be error to just use it without declaration

: * with "use strict vars"
: * with "no strict vars "
:
: will it be an error to declare it as "our $_" ;

No, in this case, $_ is still considered a lexical, but it just happens
to be aliased to a variable in the current package.

: and to repeat the question from previous post ,

: what will perl do when it see
:
: $My_Package::_ = 1 ;

It'll set the $My_Package::_ variable to 1, I presume. Whether that
has any influence on the value of $_ depends on how $_ is currently
aliased. But the name $_ will always be interpreted according to the
lexical definitions set up by "my" and "our" (including the implicit
outer "my").

Larry

fear...@figaro.weizmann.ac.il

unread,
Nov 13, 2002, 9:28:17 PM11/13/02
to Larry Wall, Me, Allison Randal, perl6-language
Larry Wall writes:
> Correct, $_ is always lexical. But...
>
> : or * will it be implicitely "my $_" -- class/package lexical
>
> There's no such thing as a "class/package lexical". I think you
> mean file-scoped lexical here.

ooo, now I understand : *scope* is orthogonal concept to class/module
symbol-tables . scope is related only to ( current ) lexical
symbol-table. and the outmost scope is file scope . all other ( inner
) lexical scopes are enclosed by closure braces wheither it is a
definition of class , subroutine or loop .

>
> : will it be an error to declare it as "our $_" ;
>
> No, in this case, $_ is still considered a lexical, but it just happens
> to be aliased to a variable in the current package.
>

which variable ? it seems that "our $_" is something like that (???)

my $_ # implicit -- at the beginning of file ( or actually any other
# lexical scope
..
..
..
our $_ ; # translated to : our $Main::_ := $_ ;
.. # or $_ := $Main::_
..
..
???

( i have in mind that "our $thing " is something like this : "dont
worry , $thing is variable from current package )

but that would be strange , because I thaought that my/our manipulate
names in symbol-table , while aliasing is compleatly orthogonal to
that. or "our $_" is just special case with perl making additional
magic .

> aliased. But the name $_ will always be interpreted according to the
> lexical definitions set up by "my" and "our" (including the implicit
> outer "my").
>


arcadi

Larry Wall

unread,
Nov 13, 2002, 9:09:45 PM11/13/02
to fear...@figaro.weizmann.ac.il, Me, Allison Randal, perl6-language
On Thu, Nov 14, 2002 at 04:28:17AM +0200, fear...@figaro.weizmann.ac.il wrote:
: >
: > : will it be an error to declare it as "our $_" ;
: >
: > No, in this case, $_ is still considered a lexical, but it just happens
: > to be aliased to a variable in the current package.
: >
:
: which variable ? it seems that "our $_" is something like that (???)
:
: my $_ # implicit -- at the beginning of file ( or actually any other
: # lexical scope
: .
: .
: .
: our $_ ; # translated to : our $Main::_ := $_ ;

No, that's backwards.

: . # or $_ := $Main::_

More like that, except a new lexical name is introduced as with "my".

: ( i have in mind that "our $thing " is something like this : "dont


: worry , $thing is variable from current package )

Well, it has that effect, but it does so by pretending it's a lexical.

: but that would be strange , because I thaought that my/our manipulate


: names in symbol-table , while aliasing is compleatly orthogonal to
: that. or "our $_" is just special case with perl making additional
: magic .

No special magic. For any variable, saying

package P;
our $foo;

is very much like

my $foo ::= $P::foo

Larry

0 new messages