Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Scheme > simple cond loo...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 4604 of 4788
Post > Topic >>

simple cond loop won't build list as intended

by sean_forester@[EMAIL PROTECTED] Jul 14, 2008 at 01:27 PM

The following code is intended to build a list of numbers for a stat
package:

(define (buildList)
  (define inputList ())
  (display "Please enter a number or simply press return when done: ")
  (let ((inputElement (read)))
    (cond ((eq? inputElement 'done )
          (display "Finished building list.")
          (newline))
         (#t
          (display "inputElement: ")(display (list inputElement))
          (newline)
          (display "inputList: ")(display inputList)(newline)
          (append inputList (list inputElement))
          (newline)
          (display "The appended list: ")(display inputList)(newline)
          (buildList))))            ;tail recursion
  (display inputList))

(buildList)

---------------------------------------
Here is the output...

Please enter a number or simply press return when done: 1
inputElement: (1)
inputList: ()

The appended list: ()
Please enter a number or simply press return when done: 2
inputElement: (2)
inputList: ()

The appended list: ()
Please enter a number or simply press return when done: 3
inputElement: (3)
inputList: ()

The appended list: ()
Please enter a number or simply press return when done: done
Finished building list.
()()()()
----------------------------
I want it to read...
(1 2 3)

Any help would be appreciated.

Kindly,

Sean
 




 2 Posts in Topic:
simple cond loop won't build list as intended
sean_forester@[EMAIL PROT  2008-07-14 13:27:24 
Re: simple cond loop won't build list as intended
pjb@[EMAIL PROTECTED] (P  2008-07-15 00:26:12 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 22:24:40 CDT 2008.