SELECT Function

Material prepared from `M Programming Book`_ [WALTERS1997] and `GT.M Programmer’s Guide`_

Page 92-94.


The $SELECT or $S function receives as input a list of paired expression arguments. It returns the first (and only the first) truth expression it encounters. For example:

GTM>WRITE $SELECT(0:"False",1:"True",1:"Also True")


If there is no true value within the input list, the function generates a run-time error. For example:

%GTM-E-SELECTFALSE, No argument to $SELECT was true

To avoid this behavior, it is a common practice to include a literal ‘1’ as the truth value of the last pair of the input list. Doing so is like defining a “default” value for the function.

Below there is an example of use of the function:

GTM>W $S(X>10:"X is bigger than 10",X<10:"X is smaller than 10",1:"X is 10")

X is smaller than 10

$SELECT page at GT.M Programmer’s Guide

Table Of Contents

Previous topic

RANDOM Function

Next topic


This Page

inserted by FC2 system