1

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?

0

2 Answers 2

4

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 ...)))
-1

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.

2
  • 3
    But but but...cond provides an implicit progn in every branch, so the use of progn here is superfluous. Well, I'm talking about Common Lisp, anyway. Who knows about other dialects of Lisp. :-P Oct 14, 2009 at 2:16
  • The body of a COND expression is wrapped in an implicit PROGN, so there is no need to explicitly provide one.
    – Vatine
    Nov 24, 2009 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.