[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Of growing code and diminishing hacks...
(define (overloaded-cdr val)
(if (null? val) nil (cdr val)))
(overloaded-cdr (assq key a-list))
In other words, if you want a cdr that horribly overloads nil, then
write one. As for me, I think of a cons cell as an object with car and
cdr fields in it, just as a point is an object with x and y fields in
it. How about:
(define (overloaded-x point)
(if (null? point) nil (x point)))
So now we have a proliferation of functions. You could just as well think
of CAR and CDR as operations, and NIL as an object that handles them by
returning NIL. Much cleaner. Well, maybe not; I guess that's debatable. I
think the code is cleaner even though the semantics that the compiler must
implement may become a little hairier. But that's what compilers are for
:-).
-------