Lecture overview -- Keyboard shortcut: 'u'  Previous page: Symbolic expressions and improper lists -- Keyboard shortcut: 'p'  Next page: List functions -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home    Lecture 2 - Page 20 : 46
Functional Programming in Scheme
Expressions, Types, and Functions
Practical list construction

cons is the basic list constructor function - but it can be applied through a number of other means as well

  • List and S-expression construction:

    • Deep cons expressions

    • Using the list function

    • Using quote or quasiquote also known as backquote

Expression

Value

(cons 1 (cons 2 (cons (+ 1 2) '())))
(1 2 3)
(list 1 2 (+ 1 2))
(1 2 3)
(quote (1 2 (+ 1 2)))
(1 2 (+ 1 2))
'(1 2 (+ 1 2))
(1 2 (+ 1 2))
(quasiquote (1 2 (unquote (+ 1 2))))
(1 2 3)
`(1 2 ,(+ 1 2))
(1 2 3)

Examples of list construction by use of cons , list and quoted list expressions.

Go to exerciseEvery second element of a list