Product Documentation
Cadence SKILL Language Reference
Product Version IC23.1, November 2023

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:

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

l_clause1

Each clause should be of the form (g_condition g_expr1 ...) where if g_condition evaluates to non-nil then all the succeeding expressions are evaluated.

Value Returned

g_result

Value of the last expression of the satisfied clause, or nil if no clause is satisfied.

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

Flow Control Functions


Return to top
 ⠀
X