Not all objects can be saved to .m and retrieved sucessfully in a restarted or new session. This is the case not only for "escaped" locals, but also for some objects implemented as function calls of a module member.

> restart:

> t := ScientificConstants:-Constant('c'):

> type(t, specfunc(anything,ScientificConstants:-Constant));
                                     true
 
> ScientificConstants:-GetValue(t);
                                   299792458
 
> save t, "temp.m":

> restart:

> read "temp.m";

> t;
                     Constant([speed_of_light_in_vacuum])
 
> type(t, specfunc(anything,ScientificConstants:-Constant));
                                     false
 
> ScientificConstants:-GetValue(t);
Error, (in ScientificConstants:-GetValue)
`Constant([speed_of_light_in_vacuum])` is not a scientific constant object

This behaviour also limits how such objects get passed through the context-sensitive menu system. Consider the following code, as run in say the Standard GUI.

> restart:

> newCM:=ContextMenu:-New():
> newCM[Entries][Add]("get constant's value",
>                    "ScientificConstants:-GetValue(%EXPR)",
>                    specfunc(anything,ScientificConstants:-Constant)):
> ContextMenu:-Install(newCM);

> t := ScientificConstants:-Constant('c');
                              t := Constant(c)

> type(t, specfunc(anything,ScientificConstants:-Constant));
                                    true

So far, so good. One can even test that the Library-side code of the system would work correctly to produce the new entry for t.

> ContextMenu:-Test:-GetGeneratedMenu(t);
                          ["get constant's value"]

The fact that the above test-action worked means that the specfunc type-check worked properly. But if one now right-clicks on the output of t, the new entry does not appear.

> t; # right-click on the output below.
                                 Constant(c)

So, checks against specfunc(..., foo:-bar) will not work as intended when used in the type-check of a context-menu item.

What would work, however, is a menu item with the type-check of specfunc(anything,:-Constant), where the global function call is being queried instead. But that would be problematic if the module function call were of some name which was also in other use. For example, if there were calls like :-Constant(..) or foo:-Constant(..) then they would also get picked up undesirably by that global function call type-check.

acer


Please Wait...