how to create a list in LISP and accepting elements of list from user?
+4
A:
Use the read
function to read user input. For example:
[6]> (list (read) (read))
joe
moe
(JOE MOE)
joe
and moe
are my input lines, terminated by a newline (pressing Enter). The list
function creates a new list.
Eli Bendersky
2010-04-08 11:20:50
+1
A:
If you want to read the elements of a list of unknown length, you could do it like this (takes input until NIL) [CL]:
(loop for read = (read)
while read collect read)
Alternatively, the easiest possibility actually is:
(read)
Because the user may enter (foo bar baz 1 2 3) here, too.
danlei
2010-04-08 15:11:22