There are some routines in Maple's library which, when called the first time, redefine themselves.

One plausible explanation for this is that the new versions are session dependent (external calls, say) while also more efficient to call (repeatedly).

For example, consider StringTools:-Join which seems typical of that package. First, consider it before it's been called at all.

> restart:
> showstat(StringTools:-Join);
 
StringTools:-Join := proc()
   1   passign(procname,defun(convert(join,'string')));
   2   procname(args)
end proc

Now call it a first time. And examine it again.

 

> StringTools:-Join(["hi","bye"]):
> showstat(StringTools:-Join);
 
StringTools:-Join := proc()
   1   call_external(0,182946067904,true,args)
end proc

So the magic was in those calls to `passign` and `defun`, which can also be examined.

> kernelopts(opaquemodules=false):

StringTools:-defun := proc(nom)
local extsym, solib;
   1   solib := ExternalCalling:-ExternalLibraryName("mstring",'HWFloat');
   2   extsym := nprintf("mstring_%s",nom);
   3   userinfo(5,StringTools,nprintf("Defining %a",extsym));
   4   define_external(extsym,'MAPLE',('LIB') = solib)
end proc
 
> showstat(StringTools:-passign);
 
StringTools:-passign := proc(n::name, v)
   1   unprotect(n);
   2   assign(n,v);
   3   protect(n);
   4   NULL
end proc

A neat little technique.


Please Wait...