On Sun, Jul 28, 2013 at 6:17 AM, Roland Mainz <[email protected]> wrote:
> On Fri, Jul 12, 2013 at 4:42 AM, Wendy Lin <[email protected]> wrote:
>> On 12 July 2013 04:35, David Korn <[email protected]> wrote:
>>> cc: [email protected]
>>> Subject: Re: [ast-users] ksh -c 'namespace a.c.b { integer i=5 ; } ;  ' => 
>>> a.c.b: is not an identifier?
>>>> How do I create a nested namespace?
[snip]
> The following test patch "fixes" the problem:
> -- snip --
> diff -r -u original/src/cmd/ksh93/sh/xec.c
> build_i386_64bit_debug/src/cmd/ksh93/sh/xec.c
> --- src/cmd/ksh93/sh/xec.c     2013-07-25 02:37:26.000000000 +0200
> +++ src/cmd/ksh93/sh/xec.c       2013-07-28 05:36:31.827214685 +0200
> @@ -2710,8 +2710,10 @@
>                                 Namval_t *oldnspace = shp->namespace;
>                                 int offset = stktell(stkp);
>                                 int     
> flag=NV_NOASSIGN|NV_NOARRAY|NV_VARNAME;
> +#if 0
>                                 if(cp)
>
> errormsg(SH_DICT,ERROR_exit(1),e_ident,fname);
> +#endif
>                                 sfputc(stkp,'.');
>                                 sfputr(stkp,fname,0);
>                                 np =
> nv_open(stkptr(stkp,offset),shp->var_tree,flag);
> -- snip --
>
> If this gets applied then the following sample code finally works:
> -- snip --
> # the next three lines are placeholders for the parent namespaces
> namespace com { true ; }
> namespace com.att  { true ; }
> namespace com.att.research { true ; }
>
> # test namespace for AT&T Research
> namespace com.att.research.hello
> {
>         function print_hello
>         {
>                 print 'Hello World'
>         }
> }
>
> # do somthing
> .com.att.research.hello.print_hello
> -- snip --
>
> IMO this would finally a major step forward towards a common
> function/type library where each party has it's own namespace which is
> organised like DNA (see java why this is a good idea)
>
> * Notes:
> - At some point namerefs to functions, e.g. typeset -f -n would be
> usefull... e.g. nameref -f hello=.com.att.research.hello.print_hello #
> would map the function .com.att.research.hello.print_hello to the
> short name "hello" without requiring a wrapper function (saving
> execution name)
>
> - Known bugs:
> $ ksh -c 'namespace a { true ; } ; namespace a.sp1 { integer i=5 ;
> function inc { let i++ ; } ; } ; print ${.a.sp1.i} ; .a.sp1.inc ;
> print ${.a.sp1.i} ' # print $'5\n5' but should print $'5\n6'
>
> Comments/feedback/rants/etc. wecome...

As requested here are two more bugs:

1. User-defined types cannot be defined in a nested namespace:
-- snip --
$ ksh -o nounset -c 'namespace org { true ; } ; namespace org.nrubsig
{ true ; } ; namespace org.nrubsig.util { integer i=5 ; typeset -T
x_t=( integer i ; ) ; } '
./arch/linux.i386-64/bin/ksh: .sh.type.org.nrubsig.util: no parent
-- snip --

2. The "enum" builtin lists a enumeration declared in a nested
namespace without namespace prefix (AFAIK it shouldn't be printed at
all because the call to "enum" to list all enumerations is done
outside the namespace... right ?):
-- snip --
$ ksh -o nounset -c 'namespace org { true ; } ; namespace org.nrubsig
{ true ; } ; namespace org.nrubsig.util { integer i=5 ; enum x=( 1 2 3
) ; } ; enum'
enum _Bool=(
        false
        true
)
enum x=(
        1
        2
        3
)
-- snip --

3. Accessing integer variables in (( )) within the namespace dosn't
work (already reported... but listing it here since it's a nasty bug
which maks further testing with real-world code much harder):
-- snip --
$ ksh -o nounset -c 'namespace a { true ; } ; namespace a.sp1 {
integer i=5 ; function inc { (( i++ )) } ; } ; print ${.a.sp1.i} ;
.a.sp1.inc ; print ${.a.sp1.i} '
5
./arch/linux.i386-64/bin/ksh: .a.sp1.inc: line 1: i: parameter not set
5
-- snip --
... this should print $'5\n6' ...

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to