Scheme: Cons

Posted October 14, 2006 by admin in Computer programming

Last Updated on

In Scheme, cons adds the first item supplied into the first position of the list supplied in the second position, no matter what it may be. This will be useful for streams later on. This Tech-Recipe provides a simple demostration of the cons feature in Scheme.

(define a (list 1 2 3))
(write (cons a (list 4 5)))
;writes ((1 2 3) 4 5)

Notice that since a was listed first, the entire list was added as a single element of the list (4 5).

Questions/Comments: [email protected]
-William. ยง (marvin_gohan)

The Conversation

Follow the reactions below and share your own thoughts.