REDUCE

4.2 Identifiers and the Id Hash Table

The method used by PSL to retrieve information about an id makes use of a symbol table. PSL uses a technique called hashing to implement this table (id hash table is another name for the symbol table).

The process of putting an id into the symbol table is called interning. The PSL reader interns ids as they are read. Consider what happens after the name of an id is read. The symbol table is examined to see if it contains an identifier with the same name. If there is a match then a reference to the matching id is returned. Otherwise, a new id is created, it is added to the symbol table, and a reference to it is returned.

4.2.1 Identifier Functions

The following functions deal with identifiers and the symbol table.

(gensym): id expr
An id is created which is not interned. Since it is not interned it is not eq to any other id. The id is derived from a string of the form ”G0000”. The numeric suffix is incremented upon each call to gensym.

(interngensym): id expr
Similar to gensym but returns an interned id.

(stringgensym string): expr
Similar to gensym but returns a string of the form ”L0000” instead of an id.

(remob U:id): id expr
If U has been interned in the symbol table then it is removed. The values associated with U will not be affected. U is returned. It is not possible to remove from the symbol table an identifier whose name consists of a single character.
1 lisp> (setq what (intern "THIS"))  
THIS  
2 lisp> (set what "SOMETHING")  
"SOMETHING"  
3 lisp>  % Remove the id whose name is "THIS".  
3 lisp> (remob what)  
THIS  
4 lisp>  % Although the id whose name is "THIS"  
has been removed from  
4 lisp>  
% the symbol table, it remains in  
%existance and its value % cell  
4 lisp>  % is still defined as "SOMETHING".  
4 lisp> (eval what)  
"SOMETHING"

(newid U:string): id expr
Creates an uninterned identifier with the specified name. The string is used as the print name without being copied. See section 2.3 for the full definition. This function makes it possible to create a number of distinct ids which have the same name. To illustrate the use of this function, the implementation of a package system (see Chapter [packages]), requires a function like newid.

(internp U:id,string): boolean expr
Returns t if U is interned.

(mapobl FNAME:function): Undefined expr
Mapobl applies function FNAME to each interned id. The following expression will print each id which is flagged global. Note that there should be only one formal parameter to FNAME.
(mapobl '(lambda (item) (if (flagp item 'global)  
(print item))))

Find

These functions take a string or id as an argument, and scan the symbol table to collect a list of ids whose names contain a prefix or suffix which matches the argument. These functions are defined in the library module find.

(findprefix KEY:id, string): id-list expr
Each interned id whose name contains a prefix which matches the KEY is added to the result. The ids are sorted alphabetically. The expression
    (findprefix '⋆)

will return a list of all of the interned ids whose name begins with *.

(findsuffix KEY:id, string): id-list expr
Each interned id whose name contains a suffix which matches the KEY is added to the result. The ids are sorted alphabetically. The expression
    (findsuffix "STRING")

will return a list of all of the interned ids whose name ends with STRING.