On 25/06/2008, Roland Mainz <[EMAIL PROTECTED]> wrote:
> "I. Szczesniak" wrote:
>  > On 6/25/08, Cedric Blancher <[EMAIL PROTECTED]> wrote:
>  > > Does ksh have a way to copy shell functions? I have to write a script
>  > >  which has to add a discipline function to variables loaded from a file
>  > >  via . (which is the output of another application and can't be
>  > >  changed) and the number goes into the tens of thousands.
>  > >  I'm using eval "function ${var}.get { $function }" but this is slow
>  > >  and uses much memory per variable ($function contains 400 bytes of
>  > >  script code) and the system has only memory for 128MB.
>  >
>  > Try this:
>  >
>  > function function_common
>  > {
>  > $function
>  > }
>  >
>  > eval "function ${var}.get { function_common \"[EMAIL PROTECTED]" }"
>
>
> IMO it may be nice to think about the old idea  for "nameref for
>  functions", e.g. "nameref -f funcptr = myfunction" or "function -n
>  funcptr = myfunction". The case above (and many other complex issues
>  related to get/set/unset functions and other cases where C/C++/JAVA code
>  would use function pointers) could be reduced to a simple "function
>  pointer (or better: nameref) assignment".
>
>  The example above could then be reduced to:
>  -- snip --
>  function function_common
>  {
>     $function
>  }
>
>  eval "function -n ${var}.get = function_common"
>  -- snip --
>
>  ... and this would even be faster since we could replace the whole {
>  argument expansion pass for "$@" + the function call itself } with a
>  direct function call through the function nameref... and it may save
>  some memory since no wrapper functions (e.g. the wrapper which calls
>  "function_common" in Irek's example) need to be created.

Do you have an example which works?


function x
{
print x
}
nameref -f y=x
y


returns:


Usage: typeset [-bflnprstuxACHS] [-a[type]] [-i[base]] [-E[n]] [-F[n]]
[-L[n]] [-R[n]] [-X[n]] [-h string] [-T tname] [-Z[n]]
[name[=value]...]
   Or:[name[=value]...]
typeset[name[=value]...]
[[name[=value]...]
options[name[=value]...]
] -f [name...]

(ksh 20080624, Fedora 8, i586)

-- 
Cedric Blancher <[EMAIL PROTECTED]>
Institute Pasteur
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to