up previous next

make a top level variable accessible

TopLevel X;
 is the name of a top level variable or function.

This command makes a top-level variable accessible from inside a function. It is useful for making QQ and ZZ visible, and also if a top-level function is to be passed as a parameter (e.g. to the function SortBy ).

The command may be used with any top-level variable, but it is poor style to use it for purposes other than those mentioned above.

NOTE: Package variables should be accessed directly (via the fully qualified name); the TopLevel command does not recognise them.

/**/  define BeautifulRing(N)
/**/    TopLevel QQ;
/**/    R ::= QQ[b[1..N]];
/**/    return R;
/**/  enddefine;

/**/  Define CompareLen(X,Y) Return len(X) < len(Y); EndDefine;

/**/  Define LongestName(ListOfNameAndValue)
/**/    TopLevel CompareLen;  --> to pass it as paremeter to SortBy
/**/    names := [entry[1] | entry in ListOfNameAndValue];
/**/    SortBy(ref names, CompareLen);
/**/    Return last(names);
/**/  EndDefine;

/**/  L := [["ABC",1],["XYZT",2]];
/**/  LongestName(L);

See Also