cond
cond(l_clause1... ) =>g_result
Description
Examines conditional clauses from left to right until either a clause is satisfied or there are no more clauses remaining. This is a syntax function.
cond clauses can have one of the following forms:
-
(g_condition g_expr1... )where g_condition is any expression -
(g_condition) -
Alternate clause, “
=>clause”where g_condition => u_expression -
Else clause of the form (else g_expr ...), where the condition is replaced by the symbol
else. This form is applicable only in SKILL++/Scheme mode.
Each clause is considered in succession. If g_condition evaluates to non-nil then processing stops and the value of the clause is used for the whole cond form. If one or more g_expr forms are given, they are evaluated in order and the value of the final g_expr is used as the value of the whole cond form. If no g_expr forms are given, the value of g_condition is used.
If the clause uses the alternate clause form, "=> clause", u_expression must evaluate to a function, which is called with the value of g_condition as a single argument. The value returned by this function is used as the value of the whole cond form.
If an else clause is encountered, its g_expr forms are evaluated unconditionally and the value of the final g_expr is used as the value of the whole cond form.
Arguments
|
Each clause should be of the form (g_condition g_expr1 ...) where if g_condition evaluates to non- |
Value Returned
|
Value of the last expression of the satisfied clause, or |
Examples
procedure( test(x)
cond(((null x) (println "Arg is null"))
((numberp x)(println "Arg is a number"))
((stringp x)(println "Arg is a string"))
(t (println "Arg is an unknown type"))))
test( nil )
=> nil; Prints "Arg is null".
test( 5 )
=> nil; Prints "Arg is a number".
test( 'sym )
=> nil; Prints "Arg is an unknown type".
Related Topics
Return to top