decode
decode(
g_keyForm
l_clause1
[ l_clause2 ... ]
)
=> g_result / nil
Description
Branches to one of the clauses depending on the value of the given expression. decode() evaluates g_keyForm and matches the resulting value sequentially against the clauses until it finds a match. Once a match is found it stops searching the clauses, evaluates the forms in the matching clause, and returns the resulting value.
Arguments
|
g_keyForm
|
An expression whose value is evaluated and tested for equality against the key in each clause.
A match occurs when either the selector is equal to the key. If a match is found, the expressions in that clause and that clause only (that is, the first match) are executed.
|
|
l_clause1
|
A list of the form (g_keys g_expr1 [g_expr2 ...]) in which the first element, that is g_keys, is an atom (that is, a scalar) of any data type. If any of the keys matches the value from g_keyForm, the clause that contains it is selected. Keys are always treated as constants and are never evaluated.
|
|
l_clause2
|
Any other clauses in the same form as l_clause1.
|
Value Returned
|
g_result
|
The value of the last expression evaluated in the matched clause.
|
|
nil
|
If there is no match.
|
Examples
v = "test"
decode(v
(1 nil)
("test" printf("test found\n"))
(2 t)
(t nil)
)
=> 2
Related Topics
Flow Control Functions
case
caseq
Return to top