Dave Storrs writes: > > Good point. I volunteered to be keeper of the glossary a while ago, > but I never actively started creating one. That said, let's make this > the first entry. Comments and constructive criticisms welcomed from > all comers. >
I tryed to "cut in stone" ( but this is very far from it being so ) the answers to my many annoying questions. This is just summary of the answers to my questions . ( though I myself feel that "fomulated" they became less clear than in the form of questions and answers . ) anyway hope this may be of help . =Refernces I provide the references : Apo3, Exe3, =ref Topic http://www.perl.com/pub/a/2002/10/30/topic.html http://archive.develooper.com/perl6-language%40perl.org/msg12362.html http://archive.develooper.com/perl6-language%40perl.org/msg12412.html http://archive.develooper.com/perl6-language%40perl.org/msg12425.html =ref Variables, assign, bind http://archive.develooper.com/perl6-language%40perl.org/msg12393.html =ref sigil http://archive.develooper.com/perl6-language%40perl.org/msg12480.html =begin Glossary =------------------------------------------------- =section variables , containers , values =------------------------------------------------- variable provides a "view" of the value. By itself it is an association between a ( variable ) name and ( variable ) container . * name is entry in one of symbol-tables . it is subject to scope and lifetime restrictions enforced by symbol-table . Its first character may be a *sigil* , in that case it is subject to additional ... magic. * container is a "box" that contain a value (??? it cannot contain nothing -- at worse it contain value undef ???). Container's life-circle , its life or death question is controlled by only one RULE: "Be referred by something" : container is dead as soon as it is not referred by anybody. There are several basic classes of "variable containers" in perl . Scalar Array Pair Hash ???Code??? ???Class??? * value is ... value -- some ( scalar ) number that is of value to you . Similar to containers , value is alife till it is referenced by ( contained in ) at least one container . it is important to note : perl manipulate the values only *through* associated with them containers. ( pictorially -- it can "view" values only through the "spectacles" of the container ). hence if several "variable names" happen to be bound to ( reffering ) *the same* container ( as it may be enforced using := operator , see *aliasing* ) then operations on any of the bound names will affect the value . examples : $a = 5 can be pictorially described as name '$a' | V container (.) | V value (number 5) ??? here have to be a lot more of *good* examples ???? =------------------------------------------------- =section sigil =------------------------------------------------- in perl several classes of variables containers have to be associated with (directly bound to ) a varable name that begin with a special character corresponding to a container type . This speial character is called *sigil*. Currently perl have 4 different sigils. Sigil is user extensible in the sence that it is possible to define new user defined fully functional sigil. The "standart sigil characters are '$scalar' - name for all scalar containers '@array' - array containers '%hash' hash containers '&closure' code # but in program & may be omitted from the point of view of functionality the sigil do the following : * every variable declared or first used is marked by perl by additional property "is Scalar" . these two are equivalent my $a ; my $a is Scalar ; so perl *notice* the sigil and add additional property "is Scalar" to the variable container associated with name '$a' , which ( the prperty ) from that on controll all the functionality of *variable container*. * =------------------------------------------------- =section symbol-tables =------------------------------------------------- symbol-table is table ( actually implemented as a named hash, see below ) that lists (subset of) known *symbols* also known as variable/subroutine/class/... *names*. everything in the text of a program except *keywords* and *operators* and ( ??? ) are *symbols* in the above sense. perl has several types of symbol tables. Every name in the symbol-table is *bound* to *variable container* ( of the type corresponding to its sigil if there is a sigil ). In particular there are the following classes of symbol-tables: * special global symbol-table named "*" . many built-in functions live there , e.g. *print is fully qualified name of "core" print function ( ???may this is a bad example ???? ) * every lexical scope , including outmost lexical scope - the file scope - have associated with it symbol-table that list lexical variables declared ( or first used ??? use/no strict ??? ) in that scope. This symbol-table is named "MY" . new names are introduced into that symbol-table by keyword "my" . my $a ; introduce new entry '$a' in the symbol-table associated with innermost enclosing lexical scope. its value can be alternatively accessed as %MY::{'$a'} . the scope of the name ( where it is "visible" ) is below the declaration up to the end of the scope. its lifetime is same of the lexical scope itself . * ???? every class/package have associated symbol-table . So name in the class/package symbol table can be accessed in any of this ways : class MyPackage{ our $thing ; print $thing ; ???? print $MyPackage::thing ; #???? print %MyPackage{'$thing'} ; } * "our" keyword. it is special in the sense that it declares *lexical* variable ( in the innermost enclosing lexical scope ) while binding it to the variable of the same name in the current package it is important to note , that symbol-table list names of variables not the containers themselves. containers are inherently anonymous . =------------------------------------------------- =section properties (as a concept) =------------------------------------------------- perl have two types of properties : * compile-time properties : attached to container . they are introduced with operator "is" . they restrict/enrich/divert the *view of content* of the container by perl - in other words , they change give additional properties/information/behavior to a *container* . * run-time properties : they are introduced with operator "but" . they are attached to values and provide some additional information/behavior to the *value* object itself . it is very important to note in particular : properties are *not* attached to names -- they are attached to containers ( compile-time properties ) or to values ( run-time properties ) . examples: #here perl will not allow ( throw exception ) to change the content of #the container associated with '$a' my $x is constant ; my $x is Scalar is type(returns int) ; my Scalar $x returns int ; my $x is Scalar of int ; my &foo is Code returns int (int $x ) { ... } ; my &foo is Code returns int is sig(int $x ) is block { ... } ; # ??? here the container associated with *package variable* $s ( see # *symbol-tables -> our keyword * ) is marked "is private" which cause # perl interpreter to throw exception any time somebody *in addition* # to the package symbol-table entry '$s' tries to refer or be bound to # that container ( not to speak of seeing or changing its value ) sub foo{ our $s is private ; } ??? a lot more examples ??? =------------------------------------------------- =section assignment vs binding =------------------------------------------------- * A = B ; "assign" means : evaluate the *value* on the right hand side and *distribute* it ( value ) among the containers ( which if needed should be created/changed ) on the left . * A := B ; *alias* or *bind* variable containers to names : take a hold of containers on the right hand side and *distribute* them (containers ) among ( bind them to ) *names* on the left. there is a special binding operator ::= that is same as := but force binding to happen at compile time . so , again , * after the assignment ( variables at ) left and right hand sides refer to the same values through different ( independent ) containers. ( modulo some Copy on Write magic ) . * after the binding -- ( names at ) right and left hand sides refer to the same containers. as a consequence, run-time properties are "passed" ( from the variable on the right side to variables on the left ) in both cases , since they are attached to values . compile-time properties are "passed" only at binding since they are attached to containers . =------------------------------------------------- =section $_ , and other special variables . =------------------------------------------------- * $_ is always lexical * every lexical scope , including the outmost lexical scope -- file scope have implicit "my $_ ; " at the top ; =------------------------------------------------- =section topic =------------------------------------------------- * topic is current value of lexical variable $_ ; * it may be set or aliased explicitly or * there are special constructs that ( possibly among other things ) sets or bind $_ to something *in associated with them lexical scope* for you . those constructs are called "topicalizers" because they set or bind $_ . they are also called *explicit* topicalizers because they certainly set $_ to something. ???? From that point of view all other lexical scopes are *implicit* topicaliers because they do not touch $_ , although you can or $_ from outer scope can be visible . ???? examples of topicalizers : * given given $x { ... $_ is bound to $x here ( but is read only ) ... } bind $_ to $x ( $_ := $x ) inside { ... } lexical scope * -> given $x -> $y { ... $_ is bound to $y ( but is read only ) ... } now the closure belongs to -> topicalizer . -> among other things binds $_ inside the closure to the first argument to the closure ( $y ) . * for * CATCH * method the *only* additional ( apart from manipulating $_ ) difference between explicit and implicit topicalizers is that block ( closure ) associated with explicit topicalizer can be "break"ed out by something like {... leave topic ; ...} so in some sense "topic" is one of the names of that block . =------------------------------------------------- =section topicalizer scope ( explicit/implicit ) =-------------------------------------------------