# Common Lisp: Recursive Call

Page 1 of 1

## 3 Replies - 992 Views - Last Post: 25 May 2011 - 06:29 PM

### #1 I X Code X 1

Reputation: 47
• Posts: 66
• Joined: 28-July 10

# Common Lisp: Recursive Call

Posted 25 May 2011 - 07:07 AM

Hello, I'm very new to Common Lisp and am trying to write a simple program that takes two numbers until you enter a number that is not one of the two.

```defun calc ()
(cond ((equal g 3) (calc)
(equal g 4) (calc))
(t '(nil)))))
```

It works as expected when I first enter a 3. However, if I enter a 4 to begin with it goes directly to the 'nil, and does not make the recursive call back to calc. Also, if I start with 3, enter some more 3's and 4's, it sometimes goes to the 'nil when I enter a 4. Here's some example output of what I am seeing:

[88]> (calc)

(NIL)

[89]> (calc)

(NIL)

Any tips? Thanks!

Is This A Good Question/Topic? 0

## Replies To: Common Lisp: Recursive Call

### #2 jon.kiparsky

• Beginner

Reputation: 11769
• Posts: 19,978
• Joined: 19-March 11

## Re: Common Lisp: Recursive Call

Posted 25 May 2011 - 09:38 AM

I don't have the capacity to test this from where I'm sitting right now, but I think I see a paren balancing problem after the first condition of your cond. I think it should be
```(cond ((equal g 3) (calc))
```

This may fix it, but as I say I don't have lisp on this machine.

This post has been edited by jon.kiparsky: 25 May 2011 - 09:39 AM

### #3 I X Code X 1

Reputation: 47
• Posts: 66
• Joined: 28-July 10

## Re: Common Lisp: Recursive Call

Posted 25 May 2011 - 11:29 AM

Thanks for the help. I had two instances of paren problems. This is the correct code for what I was trying to do:

``` defun calc ()
(cond ((equal g 3) (calc))
((equal g 4) (calc))
(t '(nil)))))
```

Thanks again!

### #4 jon.kiparsky

• Beginner

Reputation: 11769
• Posts: 19,978
• Joined: 19-March 11

## Re: Common Lisp: Recursive Call

Posted 25 May 2011 - 06:29 PM