Thursday, December 19, 2024

Scheme: Cons

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)

Previous article
Next article
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

LATEST REVIEWS

Recent Comments

error: Content is protected !!