LISP – Case Construct

  • Post author:
  • Post category:LISP
  • Post comments:1 Comment
LISP - Case Construct
LISP – If Construct

This topic is about LISP – Case Construct.

The case construct implements multiple test-action clauses like the cond construct. However, it evaluates a key form and allows multiple action clauses based on the evaluation of that key form.

The syntax for case macro is −

The template for CASE is

(case  (keyform)
((key1)   (action1   action2 ...) )
((key2)   (action1   action2 ...) )
...
((keyn)   (action1   action2 ...) ))

Example

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

(setq day 4)
(case day
(1 (format t "~% Monday"))
(2 (format t "~% Tuesday"))
(3 (format t "~% Wednesday"))
(4 (format t "~% Thursday"))
(5 (format t "~% Friday"))
(6 (format t "~% Saturday"))
(7 (format t "~% Sunday")))

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

Thursday

To know more, Click Here.

This Post Has One Comment

Leave a Reply