Phillip Whisenhunt
Phillip Whisenhunt

Reputation: 1305

Compound Conditional in Lisp

I'm new to lisp and I am simply trying to have two functions called at once if a conditional returns true.

(cond 
  ((equals (first expression) "+")
   (function1 parameter)
   (function2 parameter)))

In the above code, I just want function1 and function2 to be called. Any thoughts?

Upvotes: 1

Views: 309

Answers (2)

Doug Harris
Doug Harris

Reputation: 3379

Yes, progn like this:

(cond 
  ((equals (first expression) "+")
   (progn
     (function1 paramter)
     (function2 parameter))))

cond takes one expression to evaluate if true. In this use progn (with its arguments) is that one expression. progn, subsequently take n expressions and evaluates them.

Upvotes: -1

Rainer Joswig
Rainer Joswig

Reputation: 139411

Common Lisp

  • EQUALS does not exist, EQUAL does

  • COND already does what you want

COND allows several calls after the test:

(cond ((equal (first expression) "+")
       (do-something ...)
       (do-something-more ...)))

Upvotes: 4

Related Questions