On Fri, Jul 12, 2013 at 4:42 AM, Wendy Lin <wendlin1...@gmail.com> wrote:
> On 12 July 2013 04:35, David Korn <d...@research.att.com> wrote:
>> cc: wendlin1...@gmail.com
>> 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?
>>>
>>> I tried this but it fails:
>>> ksh -c 'namespace a.c.b { integer i=5 ; } ; '
>>> /home/wlin/bin/ksh: a.c.b: is not an identifier
>>>
>>> Wendy
>>>
>>
>> namespace a
>> {
>>         namespace c
>>         {
>>                 namespace b
>>                 {
>>                         integer i=5
>>                 }
>>         }
>> }
>
> I still get an error for this:
> ksh -c 'namespace a { namespace b { integer i=5 ; } ; } ; printf "%d\n" 
> .a.b.i'
> /home/wlin/bin/ksh: printf: .a.b.i: no parent
>
> I don't think this is the right way (semantically) because you can't
> switch from namespace a.b.c to namespace b.g.y on the fly.

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...

----

Bye,
Roland

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

Reply via email to