How to create a list in LISP and accept list items from the user?

How to create a list in LISP and accept list items from the user?

+6
list lisp
source share
2 answers

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 new line (pressing Enter). The list function creates a new list.

+4
source share

If you want to read list items of unknown length, you can do it like this (accepts input before NIL) [CL]:

 (loop for read = (read) while read collect read) 

Alternatively, the easiest option is:

 (read) 

Since the user can enter (foo bar baz 1 2 3) here too.

+2
source share

All Articles