what ?- Re: Latest scheme sources and documentation

Patrick Premont premont@cs.toronto.edu
Sat, 3 Feb 1996 18:19:22 -0500


> 
> 
> > > ; --- lists as stacks ---
> > > (define (push! x y) (set! x (cons y x)))
> > > (define (pop! x) (set! x (cdr x)))
> 
> i don't understand, is this an error? or are you changing 'define' to be 
> a macro definer? i'm just confused about the scope of 'x'.

I suspect he did not test it and did not consider the required macro status.

I've havn't tested my version but it should work :

; Stacks
(define (new-stack) (cons '() #f)) ; The car is the list of the contents
                                   ; of the stack. The cdr is unused.
(define (push! s x) 
  (set-car! s (cons x (car s))) 
  x)

(define (pop! s) 
  (let ((x (caar s)))
    (set-car! s (cdar s)))
    x))

(define (empty-stack? s) (null? (car s)))


> the reason for my message is to make a small lobbying effort for the 
> removal of cdr and car as function names. if you could use something else 
> like 'first' and 'rest', i would be appreciative. if you use a scheme 
> proper, this could be a function indirection.

I don't think this introduces an additional indirection as car and cdr
are already names for variables. You can just do (define first car)
(define rest cdr) and first will be just like car (unless the compiler
does some name-specific optimisations, which would surprise me).

Personnaly, I'm used to car and cdr and I use from time to time the
"cXXXXr" where X is a or d. We'll of course keep these names out of
the HLL however. Keeping them in the Scheme sources could help tell us
that these ARE Scheme constructs. We may end up having first and rest
or head and tail to represent similar constructs in the HLL.

It is easy to switch (except that I've used rest as a variable name
in numerous places so I'd have to search&replace that too).
I don't think we're loosing anything by not switching though and there
are many other ways to use even small bits of our time to gain something.

Patrick