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

Requested changes to R4RS




    Note, however, that this would preclude an implementation from
    implementing CADR in Scheme in the obvious way:

	    (define (CADR lis) (car (cdr lis)))

    It instead would have to be:

	    (define (CADR lis)
	      (let ((car `,car)
		    (cdr `,cdr))
		(car (cdr lis))))

Why would this help?  Unless I'm very confused, the above is
completely equivalent to

	    (define (CADR lis)
	      (let ((car car)
		    (cdr cdr))
		(car (cdr lis))))

which does not solve the problem.

Maybe you meant

	    (define CADR
	      (let ((car car)
		    (cdr cdr))
		(lambda (lis)
		  (car (cdr lis)))))

Which depends on "loading" order.

To be safe, the implementation would have to define CADR, et al. in an
implementation dependent manner which does not depend on standard
bindings.  A way to achieve this is to have (at least) two different
environments (or top-levels or whatevers).  One of them is the
"system" environment, whose bindings can be depended on.  The other is
the "user" environment, with initial copies of some bindings from the
system environment.  In this way redefining/setting CAR in the "user"
environment will affect user procedures, but not CADR which was closed
in the "system" environment, although initially accesible from the
"user" environment.

In other words, implementations could create their "user" environments
doing something like

;; In the "system" environment

(define car ...)			; The barber of Seville
(define cdr ...)			; The barber of Cordoba
(define cadr				; Shaven by at least two others
  (lambda (p)
    (car (cdr p))))

(define user-initial-environment
  (make-new-environment
   the-empty-environment		; parent
   (CAR car)				; bind CAR in user to the current value of car in system
   (CDR cdr)				; etc.
   (CADR cadr)
   ...))

The read-eval-print loop would then use user-initial-environment
rather than the system environment.