Scheme - cons

Contributor Icon Contributed by William_Wilson Date Icon October 14, 2006  
Tag Icon Tagged: Computer programming

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: william_a_wilson@hotmail.com
-William. § (marvin_gohan)

Previous recipe | Next recipe |
 

 
close Reblog this comment
blog comments powered by Disqus