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

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [EMAIL PROTECTED]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL <currently fluctuating>
 (;O/ \/ \O;)
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to