How to Create a List in Lisp Coding

Lisp, at its very base, is a list-oriented programming language. Unlike languages such as C++, you do not need to create new objects in order to use lists; you simply need to use parentheses. Lisp uses prefix notation within lists and functions; the operator comes directly before its operands. Lisp uses singly-linked lists, so you can use the operations "car" and "cdr" (or "rest") to move parts of the list around. While "car" refers to the first item in a list, "cdr" refers to every other item.

Instructions

    • 1

      Set parentheses around the list items, and separate the list items with spaces. For example, (1 2 4 51 2) creates a list with five elements.

    • 2

      Use the "cons" operation to add items to a list. For example, (cons 1 (2 3 4) ) creates the list (1 2 3 4).

    • 3

      Create a variable for a list to save the list for later use. For example, (setf test (1 2 3 4) ) creates a variable called "test." When you type "test" into the Lisp command line and hit "Enter," the screen will display "(1 2 3 4)."

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured