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 articleScheme: Using cdr
Next articleScheme: Exponents
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments

Cleveland Furia on How to Clear Google Activity
Sid Wohlfarth on How to Clear Google Activity
Riley Magsayo on How to Clear Google Activity
สมัครรับเครดิตฟรี ทันที on How to improve Remote Desktop Protocol Performance
Neal Wangstad on How to Clear Google Activity
Slavcho Andov on How to install Ubuntu
Slavcho Andov on How to fix bad sectors
Sheraz Ali on How to Backup Android