[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] redefining cons,car,cdr in SICP

From: Kon Lovett
Subject: Re: [Chicken-users] redefining cons,car,cdr in SICP
Date: Fri, 03 Dec 2010 09:45:48 -0800

On Dec 3, 2010, at 9:33 AM, David Steiner wrote:

i'm reading SICP and practicing in chicken. in the book they redefine
cons, car and cdr using procedures:

(define (cons x y)
  (define (dispatch m)
    (cond ((= m 0) x)
          ((= m 1) y)
          (else (error "Argument not 0 or 1 -- CONS" m))))
(define (car z) (z 0))
(define (cdr z) (z 1))

however it produces an error in chicken:
   Error: (caar) bad argument type: #<procedure (dispatch m)>

why doesn't it work?

Chicken defines 'caar' and the other routines in terms of direct references rather than thru the current bindings. So 'caar' is not '(lambda (x) (car (car x)))' but something much more specific to the implementation.

In general it is not possible to just redefine a few primitives and run arbitrary programs with the expectation of success. One must redefine those routines used by the program.

Chicken-users mailing list

Best Wishes,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]