Changeset 3537

Show
Ignore:
Timestamp:
05/20/05 23:16:21 (4 years ago)
Author:
putter
svk:copy_cache_prev:
5107
Message:

Edited quickref/namespace.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • docs/quickref/namespace

    r3492 r3537  
     1THIS IS VERY VERY DRAFTY (so lots of bugs flew in) 
     2 
    13Package-like things (they are namespaces) 
     4 
     5[todo - rationalize when to say "namespace" vs "package"] 
    26 
    37Where's the beef: 
     
    711   module    export/import, version 
    812    role     methods, attributes, inheritance, parameterized 
    9      class   instantiation, _not_ parameterized 
    10       enum   weird methods 
     13    class    methods, attributes, composition, instantiation 
     14     enum    weird methods 
     15 
    1116 
    1217Name and duration: 
     18 
    1319                   Name:   Name-Visibility: Package Duration: 
    1420     package P   top-level     global      until exit or deletion 
    15   my package P   top-level     lexical        dynamic 
     21  my package P   top-level     lexical        dynamic? 
    1622 our package P   relative to   same as        same as  ...current package. 
    1723     package     anonymous       n/a          dynamic 
     
    2632But grammars and rules have a separate system. 
    2733 
    28 Hierarchical naming: 
    2934 
    30  symbol example meaning 
    31   ::*    ::*A    root; begins absolute names. 
    32   ::     ::A     begins relative names 
    33   ::  ...::A     separator 
    34   ($expr)        a subpath expanded at runtime. 
    35                   ..::($expr)::.. but not ..::($expr)baz::.. 
    36   ::*Main        The user's default namespace. 
     35Names 
     36 
     37Names are hierarchical, like filesystem path names. 
     38They start with :: . The separator is also :: .  Just like / in unix. 
     39Strings can be interpolated into names by ($expr) , but must begin and 
     40end at separator boundaries. 
     41 
     42Some notable namespaces are: 
     43  ::*        global (root) 
     44  ::MY       current lexical 
     45  ::*::Main  the user default 
     46 
     47A name N can be used: 
     48  N              by itself 
     49  %N::           as a hash (symbol table) 
     50  $N @N %N &N    to name variables 
     51 
     52The beginning of a name can be abbreviated, to make short names even simpler. 
     53  example shorter  rule 
     54  %::A     %A    the starting :: can be dropped if it's not at the word beginning 
     55  ::*::A   ::*A  root doesn't need a separator 
     56  ::A      A     a declared name doesn't need the starting :: 
     57  ::*A     *A    root's starting :: can be dropped where there is no confusion 
     58                  with unary * (such as declarations). 
     59 
     60There are a bunch of examples below. 
    3761 
    3862A single hierarchy is shared by modules, classes, roles, enums, and 
     
    4266separate system. 
    4367 
    44 Names are searched for from innermost scopes to outermost. 
    45 # Which names?  relative names?  names without separators? 
     68Relative package names are searched for 
     69  from inner lexical scopes to outer, then 
     70  from inner packages to outer, then 
     71  in the global namespace. 
    4672 
    47 Symbol table: 
     73[this deserves elaboration] 
    4874 
    49   %Name      symbol table 
    50   %Name<$x>  lookup 
    51   %::*       global symbol table 
    52   %::*P      symbol table of top-level P 
    53   %P::       symbol table of some P 
     75 
     76Autoloading: 
     77 
     78The presense of names in a namespace can be faked.  Or implemented 
     79lazily.  If a user inquires about (defined(...)), or tries to use a 
     80variable, which is not in the symbol table, hooks are called. 
     81 
     82For SCALAR ARRAY HASH SUB METH ...: 
     83 
     84AUTO...    predicates test the existance of a variable, 
     85             returning undef or _any_ ref of the right type. 
     86AUTO...DEF accessors actually fetch the requested variable. 
     87 
     88[Can a package or role AUTOMETH?] 
     89 
     90 
     91Binding: 
     92 
     93:= ::= 
     94# todo 
     95 
     96 
     97 
     98Here are assorted examples of names: 
     99 
     100 ::A               namespace name, relative 
     101 ::A::B 
     102 ::A::B::C 
     103 ::*               namespace name, absolute (::* is root) 
     104 ::*A                (root doesn't need a separator) 
     105 ::*A::B 
     106 ::*A::B::C 
     107 %A::              namespace as hash; relative name 
     108 %A::B:: 
     109 %*::              namespace as hash; absolute name 
     110 %*A:: 
     111 %*A::B:: 
     112 %x                variable name, lexical   ("%" could be any sigil $@%& etc) 
     113 %A::x             variable name, relative  ("%" could be any sigil $@%& etc) 
     114 %A::B::x                                   ("%" could be any sigil $@%& etc) 
     115 %*x               variable name, absolute  ("%" could be any sigil $@%& etc) 
     116 %*A::x                                     ("%" could be any sigil $@%& etc) 
     117 %*A::B::x                                  ("%" could be any sigil $@%& etc) 
     118Abbreviations used above: 
     119 ::*::A            ::*A   (root doesn't need a separator) 
     120 %::A::            %A::   (the leading :: is only needed if it starts the word) 
     121                              (::A::B could NOT be abbreviated A::B) 
     122 %::A::x           %A::x 
     123 %::*::x           %*x    (using both) 
     124 %::*::A::         %*A:: 
     125Notable namespaces: 
     126 ::MY              current lexical namespace 
     127 %MY::                 as hash 
     128 %MY::x                a variable in        ("%" could be any sigil $@%& etc) 
     129 ::*Main           default user namespace 
     130 %*Main::              as hash 
     131 %*Main::x             a variable in        ("%" could be any sigil $@%& etc) 
     132Runtime interpolation: 
     133 ::("A")           ::A 
     134 ::("A::B")        ::A::B 
     135 ::("A::")B   # ILLEGAL 
     136 ::("A")::B        ::A::B 
     137 ::A::("B")        ::A::B 
     138 ::A::("B")::C     ::A::B::C 
     139 ::("*")           ::* 
     140 ::("*A")          ::*A 
     141 ::("*::A")        ::*A 
     142 %::("A")::        %A:: 
     143 %::("A::")   # ILLEGAL 
     144 %::("A::x")       %A::x                    ("%" could be any sigil $@%& etc) 
     145 ::($expr)         a namespace name 
     146 ::($e1)::($e2)    a namespace name 
     147 %::($expr)::      a namespace used as a hash 
     148 %::($expr)        a variable name          ("%" could be any sigil $@%& etc) 
     149Using a namespace hash (a symbol table): 
     150  %P::       namespace P as a hash (a symbol table) 
    54151  %P::<$s>   lookup $s 
    55152  %P::<@a>   lookup @a 
     
    57154  %P::{$sym} lookup some symbol specified at runtime 
    58155 
    59 Traits/properties: 
    60156 
    61 Autoloading: 
    62157 
    63 Version: 
    64  
    65 Export/import/inheritance(is/does): 
    66  
    67 Types: 
    68  
    69 Parameterization: 
    70  
    71 Dispatch: 
    72  
    73 Instantiation/Objects: