User-Defined Elements

Home, Up: Insert Files and User Defined Elements

 

On this page:

What are User-Defined Elements?, Using UDEs for Data, Using UDEs for User-Defined Operators, Using UDEs for Commands, UDE Management Commands

 

What are User-Defined Elements?

A user defined element (UDE) looks like a variable, but works like an insert file -- without a file, though.

Like an insert file, a user defined element can contain anything that can be written into an input line -- data, operators, or (probably used less often) commands.

While names of variables begin with $, names of user defined elements begin with @.

Like the names of variables, those of user defined elements can not contain spaces. @ on its own is a valid name.

Like variables, user defined elements are created with an assignement command (spaces before and after the equal sign are needed):

@myude = ...

While a variable is always a number, a user defined element is always a text, though this text can consist of, or contain, numbers.

When a UDE exists, its content can be overwritten with a new assignment command.

To use a UDE, you write its name into the input line -- like the name of a variable or an insert file, it will be replaced by its content.

 

User-defined elements can contain commands (see below), but can not be used within command lines (for instance, a UDE can not stand for a file name in an EDIT or SAVE command).

 

For showing, deleting, saving and retrieving user defined elements, see "UDE Management Commands" below.

 

Using UDEs for Data

Like insert files, user defined elements can consist of data. You can enter a list of values manually, like this:

? @mydata = 3 8 4 9 5 2 7 11 6

or you can assign the data to the UDE from a file (read that data into the UDE), and then use this UDE instead of the insert file:

? @mydata = (somefile)

 

You can then use n-argument operators on the data stored in the UDE:

? @mydata MEAN

? @mydata MEDIAN

? @mydata SDEV

 

Reading data from a file into a user defined element will make loops faster, when that data is used in a loop hundreds or thousands of times.

(Loops will be discussed later. In a loop, elements from a data list can be addressed individually.)

There is no hard limit for the amount of data that can be contained in a user-defined element.

 

Using UDEs for User-Defined Operators

This is a main purpose of user-defined elements: they let you create your own operators.

While user-defined operators cannot do anything that could not also be done with Hypatia'a buit-in operators, they can make things a lot easier.

For more about them see the next page, "User Defined Operators".

 

Using UDEs for Commands

Since a user-defined element can contain anything that can be typed into the input line, this can also be a command.

For example, we have seen in chapter "The Basics", page "Editing Files" that the command EXTEDITOR lets you replace the default notepad.exe editor with an editor of your choice.

You can make that editor default by adding the appropriate line to hy.ini, but what if you want to be able to easily switch between two editors?

For this, you can use two user-defined elements -- add these lines to hy.ini (as always, you can write everything in lower case characters):

@ed1 = EXTEDITOR notepad.exe

@ed2 = EXTEDITOR C:\Program Files (x86)\IDM Computer Solutions\UltraEdit\Uedit32.exe

(notepad.exe does not need the path specified, because its location is included in the system path.)

You can now switch between the editors by entering @ed1 or @ed2.

 

UDE Management Commands

The commands to create, show, delete, save and retrieve user-defined elements closely resemble those for variables.

 

@ude = ... -- assign any content to a user-defined element, creating it if it doesn't yet exist.

DEL@ @ude -- delete the user defined element.

SHOW@ -- display all user defined elelements.

SHOW@ @ude1 @ude2 ... -- display these user defined elements.

SAVE@ filename comment -- save all current user-defined elements to the specified file, the optional comment text after filename will be included as a comment line.

_filename -- retrieve saved user-defined elements from the specified file.

 

SAVE@ is followed by a file name, everything that follows it is a comment -- you cannot specify which UDEs will be saved.

 

A file in which user-defined elements are stored has one line for each UDE:

$ude = content

You can edit this file to change, add or delete user-defined elements it contains before you next retrieve them from the file.

 

There are no corresponding UDE commands to the variable commands STO and PROMPT.

 

Home, Up: Insert Files and User Defined Elements, Prev: Insert Files, Next: User-Defined Operators