| Allegro CL version 8.2 Unrevised from 8.1 to 8.2. 8.1 version | ||||||||||
Arguments: (test-form {then then-form+ | thenret} {elseif else-test-form {then else-then-form+ | thenret}}* [else else-form+])
This form consists of a series of clauses introduced by the symbols
then, elseif,
else, and thenret.
First the predicate test-form is
evaluated.
If it is true,
the then-forms are evaluated, and the
value of the last such form is returned.
If test-form evaluates to nil,
any remaining clauses are processed.
If no clauses remain, if*
returns nil.
When a thenret clause is
encountered no further evaluation takes place,
and the value of the most recently evaluated
test-form is returned.
When an elseif clause is encountered,
the predicate else-test-form
is evaluated. If it is true,
the else-then-forms are evaluated,
and the value of the last such form is returned;
otherwise any remaining clauses are
processed. If no clauses remain, if*
returns nil. And lastly,
when an else clause is encountered, the
else-forms are evaluated,
and the value of the last such form is returned.
;; The basic format of a IF* expression is:
;;
;; (if* [test] then [do this 1] [do this 2] else [do other 1] [do other 2])
;;
;; When [test] is true, the forms after the THEN are evaluated and the
;; result of the last returned; if [test] if false, the forms after the
;; ELSE are evaluated and the result of the last is returned.
;; So:
cl-user(18): (if* (> 3 2) then "three is bigger" 3
else "three is smaller" 2)
3
;; Your do not need an ELSE form:
cl-user(19): (if* (> 3 2) then "three is bigger" 3)
3
cl-user(19): (if* (> 2 3) then "two is bigger" 2)
nil
;; You can have multiple fors after THEN or ELSE:
cl-user(21): (defun foo (x) (if* x then (setq y 2) (print x)
else (setq y -2) "no"))
foo
cl-user(22): (foo 2)
2
2
cl-user(23): (foo "hello")
"hello"
"hello"
cl-user(24): (foo nil)
"no"
cl-user(25):
;; There are two more special symbols: THENRET and ELSEIF.
;; THENRET says when the test is true just return the value of the test
;; form just evaluated:
cl-user(25): (if* (+ 4 5) thenret)
9
cl-user(26):
;; ELSEIF introduces a new test, so you can have compound tests:
cl-user(27): (setq score 77)
77
cl-user(28): (if* (< score 60) then "F"
elseif (< score 70) then "D"
elseif (< score 80) then "C"
elseif (< score 90) then "B"
else "A")
"C"
cl-user(29): (setq score 55)
55
cl-user(30): (if* (< score 60) then "F"
elseif (< score 70) then "D"
elseif (< score 80) then "C"
elseif (< score 90) then "B"
else "A")
"F"
cl-user(31): (setq score 92)
92
cl-user(32): (if* (< score 60) then "F"
elseif (< score 70) then "D"
elseif (< score 80) then "C"
elseif (< score 90) then "B"
else "A")
"A"
cl-user(33):
Copyright (c) 1998-2016, Franz Inc. Oakland, CA., USA. All rights reserved.
This page was not revised from the 8.1 page.
Created 2010.1.21.
| Allegro CL version 8.2 Unrevised from 8.1 to 8.2. 8.1 version | ||||||||||