Le 28/05/2013 12:41, Roland Mainz a écrit :
Can anyone explain why the code below behaves differently (in
ast-ksh.2013-05-24 on SuSE 12.3/AMD64/64bit) when function "f" has an
own scope ? Are function-local variables not subject to be part of a
namespace ? What will happen to function-static variables vs.
namespaces ?
-- snip --
$ ksh -c 'f() { namespace nam1 { integer i2=5 ; } ; print ${.nam1.i2} ; } ; f'
5
$ ksh -c 'function f { namespace nam1 { integer i2=5 ; } ; print
${.nam1.i2} ; } ; f'

Hi,

well, the answer is in the question, from man :

-----
Functions.
...
Functions  defined  by the function name syntax and called by name exe‐
...
after the function completes.  Ordinarily, variables are shared between
the  calling  program  and  the function.  However, the typeset special
                                                    ^^^^^^^^^^^^^^^^^^^
built-in command used within a function defines local  variables  whose
                                        ^^^^^^^^^^^^^^^^^^^^^^^^
scope  includes  the current function.  They can be passed to functions
...
Functions defined with the name() syntax and functions defined with the
function  name syntax that are invoked with the .  special built-in are
executed in the caller's environment and share all variables and  traps
                                         ^^^^^^^^^^^^^^^^^^^
with  the  caller.   Errors  within these function executions cause the
script that contains them to abort.
-----
Name Spaces.
Commands and functions that are executed as  part  of  the  list  of  a
namespace  command  that  modify variables or create new ones, create a
                                                               ^^^^^^^^
new variable whose name is the name of the name space as given by iden‐
^^^^^^^^^^^^
tifier  preceded  by  ..
-----

so, namespace seems to be a kind of typeset,
however, maybe the Function chapter could say that namespaces are handled as typeset.

Regards,

Cyrille Lefevre
--
mailto:[email protected]

_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to