up previous next
TopLevel

make a top level variable accessible

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

Description
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 their fully qualified names); the TopLevel command does not recognise them.

Example
/**/  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);
XYZT

See Also