tags:

views:

68

answers:

2

Hi, I am a beginner in Clojure, and I have a simple (stupid) question. I am trying to to read 4 user input , and then storing those inputs into a List

this is my code:

(def in1 (read-line)) (def in2 (read-line)) (def in3 (read-line)) (def in4 (read-line))

(def mylist '(in1 in2 in3 in4))

However, when i print the list, it gives me "in1 in2 in3 in4". How do i get it to put the value of the variables in1 in2 in3 and in4 into the List?

Thank you

+2  A: 
(def mylist (list in1 in2 in3 in4))
Pavel Minaev
Thank you, .
+3  A: 

The single-quote in Clojure (and most Lisps) tells the system to not evaluate the expression. Thus

'(in1 in2 in3 in4)

is the same as

(quote (in1 in2 in3 in4)

They both end up with, as you have seen, a list of symbols.

If instead you want a list of the values represented by those symbols, you can use the list form. This evaluates all of its arguments and returns a list of the results. It would look something like this:

(def mylist (list in1 in2 in3 in4))
Steve Rowe