Saving a list of variables

Discussion of Common Lisp

Saving a list of variables

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

Posts: 12
Joined: Thu Aug 23, 2012 11:49 pm

Re: Saving a list of variables

Postby Konfusius » Fri Sep 21, 2012 7:45 pm

Code: Select all
(setq allQuestions (list firstQuestion secondQuestion thirdQuestion))
Posts: 62
Joined: Fri Jun 10, 2011 6:38 am

Re: Saving a list of variables

Postby 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
(lisp (lisp (lisp that is)

Just press the [­­­code] button when you're typing your post to insert the code tags. For more information, see Don't forget, semi-colon (;) is for Lisp comments, not //. Thanks for listening :).
User avatar
Posts: 60
Joined: Mon Jul 07, 2008 8:06 pm
Location: Toowoomba, Queensland, Australia

Re: Saving a list of variables

Postby 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.
User avatar
Posts: 271
Joined: Thu May 10, 2012 12:54 pm

Return to Common Lisp

Who is online

Users browsing this forum: Bing [Bot] and 4 guests