Saving a list of variables

Discussion of Common Lisp
Post Reply
samohtvii
Posts: 12
Joined: Thu Aug 23, 2012 11:49 pm

Saving a list of variables

Post by samohtvii » Fri Sep 21, 2012 6:39 pm

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

Konfusius
Posts: 62
Joined: Fri Jun 10, 2011 6:38 am

Re: Saving a list of variables

Post by Konfusius » Fri Sep 21, 2012 7:45 pm

Code: Select all

(setq allQuestions (list firstQuestion secondQuestion thirdQuestion))

Kohath
Posts: 61
Joined: Mon Jul 07, 2008 8:06 pm
Location: Toowoomba, Queensland, Australia
Contact:

Re: Saving a list of variables

Post by Kohath » Fri Sep 21, 2012 7:50 pm

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 :).

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: Saving a list of variables

Post by Goheeca » Sat Sep 22, 2012 3:05 am

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))
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Post Reply