How are lists represented?


How are lists represented?



Last modified on June 14, 2001
by rpj@cs.rit.edu.
LAST SLIDE UP NEXT SLIDE PREVIOUS HERE NEXT



















































How are lists represented?
Quiz1 solution
is here.

Last modified on June 14, 2001
by rpj@cs.rit.edu.
LAST SLIDE UP NEXT SLIDE PREVIOUS HERE NEXT


















































How are lists represented?
Quiz1 solution
Ultimately
all lists are built using cons.


Last modified on June 14, 2001
by rpj@cs.rit.edu.
LAST SLIDE UP NEXT SLIDE PREVIOUS HERE NEXT


















































How are lists represented?
Quiz1 solution
Ultimately
(cons a b)
creates a new node, called a consbox:


Last modified on June 14, 2001
by rpj@cs.rit.edu.
LAST SLIDE UP NEXT SLIDE PREVIOUS HERE NEXT


















































How are lists represented?
Quiz1 solution
Ultimately
(cons a b)
"dot" is the infix cons operator
Technically, this consbox is written as (a . b)


Last modified on June 14, 2001
by rpj@cs.rit.edu.
LAST SLIDE UP NEXT SLIDE PREVIOUS HERE NEXT


















































How are lists represented?
Quiz1 solution
Ultimately
(cons a b)
"dot" is the infix cons operator
Scheme pretty-prints lists if it can
> (cons 1 (cons 2 (cons 3 ())))
(1 2 3)


Last modified on June 14, 2001
by rpj@cs.rit.edu.
LAST SLIDE UP NEXT SLIDE PREVIOUS HERE NEXT


















































How are lists represented?
Quiz1 solution
Ultimately
(cons a b)
"dot" is the infix cons operator
Scheme pretty-prints lists if it can
But reverts to dot notation if it can't
> (cons 1 2)
(1 . 2)


Last modified on June 14, 2001
by rpj@cs.rit.edu.
LAST SLIDE UP NEXT SLIDE PREVIOUS HERE NEXT


















































How are lists represented?
Quiz1 solution
Ultimately
(cons a b)
"dot" is the infix cons operator
Scheme pretty-prints lists if it can
But reverts to dot notation if it can't
Or does a combination of the two notations
avoiding the dot as much as it can:
> (cons 1 (cons 2 (cons 3 4)))
(1 2 3 . 4)

Last modified on June 14, 2001
by rpj@cs.rit.edu.
LAST SLIDE UP NEXT SLIDE PREVIOUS HERE NEXT