Syntax

Syntax wise, they are formed from a single LISP expression. Apart from the tests, there is only the special function cond, and two terminals:

  • #t for true.

  • #f for false.

The LISP cond function accepts an arbitrary number of arguments. Each argument is a list of two elements: a condition and a result.

(cond
    (condition1 result1)
    (condition2 result2)
    ...
    (conditionN resultN)
)
  

The conditions are evaluated in order, and for the first being true, the result is returned:

if condition1 is true return result1, else if condition2 is true return result2, else if ...; else if conditionN is true return resultN.

If none of the conditions is true, then false is returned for the whole expression, as a convenience.

Usually in call merging algorithms, the conditions are tests and the results are terminals:

(cond
    (test1 #t)
    (test2 #t)
    (test3 #f)
    (test4 #t)
)
  

But the result does not have to be a terminal. For example, this is a possible AND statement:

(cond
    (test1 test2)
)
  

The result part can also be another cond expression for providing nested tests:

(cond
    (test1 (cond
                (test2 #t)
                (test3 #t)
           )
    )
    (test4 #t)
)
  

The above example translates in the following pseudo-code:

if test1:
    if test2:
        return True
    elif test3:
        return True
    else:
        return False
elif test4:
    return True
else:
    return False
  

The tests can accept an arbitrary number of parameters which have to be provided right after the test name, for example:

(cond
    (test1 param1 param2)
)
  

translates to:

if test1(param1, param2):
    return True
else:
    return False
  

The parameters can be strings, integers, or list of strings:

(test "string" 12 ("list" "of" "parameters"))
  

Line comments can be inserted by using the semicolon symbol:

; this is a comment