Page 1 of 1

Saving a list of variables

Posted: Fri Sep 21, 2012 6:39 pm
by samohtvii
How can you get input from a user and save that data in a list. e.g.
(format t "First question?")
(let ((firstQuestion (read-line)))
//second question
(let ((secondQuestion (read-line)))
//third
(let ((thirdQuestion (read-line)))
(setq allQuestions '(firstQuestion secondQuestion thirdQuestion))))

so that just gives me a list of those words and not the actually valuse they hold.

Thanks

Re: Saving a list of variables

Posted: Fri Sep 21, 2012 7:45 pm
by Konfusius

Code: Select all

(setq allQuestions (list firstQuestion secondQuestion thirdQuestion))

Re: Saving a list of variables

Posted: Fri Sep 21, 2012 7:50 pm
by Kohath
A hint for posting. For code, please put your code between [­­­code] and [­­­/code] tags. For example type this into a post:

Code: Select all

[code]
(lisp (lisp (lisp that is)
            indented
            nicely))
[/code]
Just press the [­­­code] button when you're typing your post to insert the code tags. For more information, see http://lispforum.com/faq.php?mode=bbcode. Don't forget, semi-colon (;) is for Lisp comments, not //. Thanks for listening :).

Re: Saving a list of variables

Posted: Sat Sep 22, 2012 3:05 am
by Goheeca
Or you can do this:

Code: Select all

(defvar *Q* '("Foo?" "Bar?" "Baz?"))
(loop for question in *Q*
      do (format t "~a " question) (finish-output)
      collect (read-line))