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

Discussion of Common Lisp
Post Reply
joeish80829
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

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

Post by joeish80829 » Fri Sep 27, 2013 4:51 pm

Here is the statement::

Code: Select all

            if( frameCount < 30 ){
        accumulateBackground( frame );
    }else if( frameCount == 30 ){
        createModelsfromStats();
    }else{
        backgroundDiff( frame, mask1 );
i tried this:

Code: Select all

      (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 Fri Sep 27, 2013 6:50 pm, edited 1 time in total.
Reason: added [code] tags

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

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

Post by nuntius » Fri Sep 27, 2013 6:55 pm

You had the parens wrong in your nested if. Here's a corrected version. Note how the indentation makes it easier to follow.

Code: Select all

(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.

Code: Select all

(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.

Post Reply