This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

How do i convert this C if, elseif, else to Common Lisp?

2 posts · 2065 views

Here is the statement::
            if( frameCount < 30 ){
        accumulateBackground( frame );
    }else if( frameCount == 30 ){
        createModelsfromStats();
    }else{
        backgroundDiff( frame, mask1 );
i tried this:
      (if (< frame-count 30) (accumulate-background frame) 
      (if (equal frame-count 30) (create-models-from-stats))
      (background-diff frame mask-1))
but i get an invalid number of elements error:

i thought of doing progn but that doesnt represent the right condoitionals...and thought of cond but that will not eval the same way as a if, eleif, else statement...any help is appreciated..

Last edited by nuntius on , edited 1 time in total. Reason: added [code] tags

Re: How do i convert this C if, elseif, else to Common Lisp?

You had the parens wrong in your nested if. Here's a corrected version. Note how the indentation makes it easier to follow.
(if (< frame-count 30)
  (accumulate-background frame)
  (if (equal frame-count 30)
    (create-models-from-stats)
    (background-diff frame mask-1)))
Here's an equivalent COND version.
(cond
  ((< frame-count 30)
   (accumulate-background frame))
  ((equal frame-count 30)
   (create-models-from-stats))
  (t
   (background-diff frame mask-1)))
Disclaimer: neither of these are tested, but they look right.