Details of Icon Functions K through O


kbhit () : n -- check for keyboard character

Succeeds if a character is available for getch() or getche() but fails otherwise.
See also: getch() and getche()

key (T) : x1,x2,...,xn -- generate keys from table

Generates the keys in table T.

left (s1,i,s2) : s3 -- position string at left

Produces a string of size i in which s1 is positioned at the left, with s2 used for padding on the right as necessary.
Defaults:
i       1
s2      " " (blank)

See also: center() and right()

list (i,x) : L -- create list

Produces a list of size i in which each value is x.
Defaults:
i       0
x       &null

loadfunc (s1,s2) : p -- load external function

Loads the function named s2 from the library file s1. s2 must be a C or compatible function that provides a particular interface expected by loadfunc().

log (r1,r2) : r3 -- compute logarithm

Produces the logarithm of r1 to the base r2.
Default:
r2      e

See also: exp()

many (c,s,i1,i2) : i3 -- locate many characters

Succeeds and produces the position in s after the longest initial sequence of characters in c in s[i1:i2]. It fails if s[i1] is not in c.
Defaults:
s       &subject
i1      &pos if s defaulted, otherwise 1
i2      0

See also: any() and match()

map (s1,s2,s3) : s4 -- map characters

Produces a string of size *s1 obtained by mapping characters of s1 that occur in s2 into corresponding characters in s3.
Defaults:
s2      string(&ucase)
s3      string(&lcase)

match (s1,s2,i1,i2) : i3 -- match initial string

Produces i1 + *s1 if s1 == s2[i1+:*s1], but fails otherwise.
Defaults:
s2      &subject
i1      &pos if s2 defaulted, otherwise 1
i2      0

See also: =s, any(), and many()

member (X,x) : x -- test for membership

If X is a set, succeeds if x is a member of X, but fails otherwise. If X is a table, succeeds if x is a key of an element in X, but fails otherwise. Produces x if it succeeds.
See also: delete() and insert()

move (i) : s -- move scanning position

Produces &subject[&pos:&pos + i] and assigns i + &pos to &pos, but fails if i is out of range; reverses assignment to &pos if resumed.
See also: tab()

name (x) : s -- produce name

Produces the name of the variable x. If x is an identifier or a keyword that is a variable, the name of the identifier or keyword is produced. If x is a record field reference, the record name and field name are produced with a separating period. If x is a string, the name of the string and the subscript range are shown. If x is a subscripted list or table, the type name followed by the subscripting expression is produced.
See also: variable()

numeric (x) : N -- convert to numeric

Produces an integer or real number resulting from converting x, but fails if the conversion is not possible.
See also: integer() and real()

open (s1,s2) : f -- open file

Produces a file resulting from opening s1 according to options in s2, but fails if the file cannot be opened. The options are:
        "r"   open for reading
        "w"   open for writing
        "a"   open for writing in append mode
        "b"   open for reading and writing
        "c"   create
        "t"   translate line termination sequences to linefeeds
        "u"   do not translate line termination sequences to linefeeds
        "p"   pipe to/from a command -- UNIX
The default mode is to translate line termination sequences to linefeeds on input and conversely on output. The untranslated mode should be used when reading and writing binary files.
Default:
s2      "rt"

See also: close()

ord (s) : i -- produce ordinal

Produces an integer (ordinal) between 0 and 255 that is the internal representation of the single character in s.
See also: char()