LISP – When Construct

  • Post author:
  • Post category:LISP
  • Post comments:2 Comments
LISP - When Construct
LISP – If Construct

This topic is about LISP – When Construct.

The when macro is followed by a test clause that evaluates to t or nil. If the test clause is evaluated to nil, then no form is evaluated and nil is returned, however the test result is t, then the action following the test clause is executed.

Syntax for when macro −

(when (test-clause) (<action1) )

Example

Create a new source code file named main.lisp and type the following code in it.

(setq a 100)
(when (> a 20)
   (format t "~% a is greater than 20"))
(format t "~% value of a is ~d " a)

When you click the Execute button, or type Ctrl+E, LISP executes it immediately and the result returned is −

a is greater than 20
value of a is 100 

To learn more, Click Here.

This Post Has 2 Comments

Leave a Reply