Mike Oliver did elaborate in private e-mail to the below included e-mail.
There is another difference with non-POSIX functions 
in Solaris ksh vs. ksh93, in addition to that mentioned in item #1 
of the COMPAT file of Solaris ksh vs. ksh93 compatibility differences.

This incompatibility is really only relevant to the future case
to replace /usr/bin/ksh with ksh93, but it does involve a diff to the 
COMPAT file in the case materials.

David & Glenn,
Unless this is a Solaris ksh fork from ksh88, 
item #1 in the AT&T COMPATIBILITY file may need
to be updated, since it currently states that "Functions defined
with the function name syntax, maintain compatibility."


In Solaris ksh, local variables declared in 
non-POSIX functions are local to the current function
and all functions it calls.  In ksh93, local variables declared
in non-POSIX functions are local to the current function but that scope
does not include functions it calls.

See Mike's example, below.

In ksh93, if I do:

     function l2 {
         print "in l2, inherited fruit is $fruit"
     }

     function nonposix {
         print "in nonposix, inherited fruit is $fruit"
         typeset -r fruit=nectarine
         print "in nonposix, local fruit is $fruit"
         l2
     }

     fruit=mango
     nonposix

I get the result:

     in nonposix, inherited fruit is mango
     in nonposix, local fruit is nectarine
     in l2, inherited fruit is mango

So function 'l2' did not inherit the 'fruit' variable from the
'nonposix' function. 

If I run that under Solaris /bin/ksh, I get:

     in nonposix, inherited fruit is mango
     in nonposix, local fruit is nectarine
     in l2, inherited fruit is nectarine

>From the Solaris ksh(1) manpage for /usr/bin/ksh
(refers to both "function func" and "func()" functions):

      However, the typeset special  built-in  command  used
      within  a  function  defines  local  variables  whose  scope
      includes the current function and all  functions  it  calls.

>From the manpage for ksh93:

     Functions defined by the function _n_a_m_e syntax and called  by
     name execute in the same process as the caller and share all
     files and present working directory with the caller.
     ...
     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 that they
     call  in  the variable assignment list the precedes the call
     or as arguments passed as name  references.  

Thanks,
        April


> X-Unix-From: April.Chin at eng.sun.com  Wed Sep 20 16:43:01 2006
> Date: Wed, 20 Sep 2006 16:36:15 -0700 (PDT)
> From: April Chin <April.Chin at eng.sun.com>
> Subject: Re: Korn Shell 93 Integration [PSARC-EXT/2006/550 Timeout:  
09/27/2006]
> To: don.cragun at Sun.COM, Mike.Oliver at Sun.COM
> Cc: PSARC-EXT at sac.sfbay.sun.com, April.Chin at eng.sun.com, 
ksh93-integration-discuss at opensolaris.org, roland.mainz at nrubsig.org
> MIME-Version: 1.0
> Content-MD5: ASFuaRaIHelt/zhlhKo0nw==
> 
> 
> > Date: Wed, 20 Sep 2006 14:15:02 -0700
> > From: Mike Oliver <Mike.Oliver at Sun.COM>
> > 
> > BTW, the second paragraph in item 1 of the COMPAT summary:
> > 
> >     In ksh93, local variables only exist for POSIX-style
> >     (func()) functions.  In non-POSIX-style functions, variables
> >     declared with "typeset var" remain global in scope, and are shared
> >     between the calling program and the function.
> > 
> > is incorrect.  It's the POSIX-style functions that always operate on
> > global variables.  Non-POSIX functions retain the ability to create
> > local variables via 'typedef'.
> 
> Thanks for the correction.  Yes, what it should say is:
>      
>    In ksh93, local variables only exist for non-POSIX-style 
>    (function func) functions.  In POSIX-style functions (func()), 
>    variables declared with "typeset var" remain global in scope, 
>    and are shared between the calling program and the function.
> 
> Sorry about that.
> > 
> 
<http://www.opensolaris.org/os/project/ksh93-integration/docs/ksh93r/general/com
> patibility/>
> > gets this right, although it's wrong about non-POSIX functions
> > maintaining backwards compatibility.  For one thing, the behaviour
> > of a local variable in ksh93 is incompatible with the existing
> > Solaris ksh because the semantics of a variable's "readonly"
> > ('typeset -r') attribute are very different.
> 
> Can you elaborate, please?  It sounds like something else to be
> added to the compatibility list.
> 
> Thanks,
>       April
> 
> > 
> > Mike.
> > -- 
> > mike.oliver at sun.com
> 


Reply via email to