Implementation of cons
Conceptually, cons is implemented by removing a pair cell from the heap or free storage list and replacing its car and cdr pointers with the desired values. The following is a simple implementation of cons:
(define (cons x y)
(if (null? *freelist*)
(or (garbage-collect)
(get-more-memory)
(error "out of space") ) )
(let ((pair *freelist*))
(set! *freelist* (cdr *freelist*))
(set-car! pair x)
(set-cdr! pair y)
pair))
Contents    Page-10    Prev    Next    Page+10    Index