>>>>> "Grant" == Grant Miner <mine0057@mrs.umn.edu> writes:
Grant> This does not work...
Grant> (define cons! (lambda (item ls)
Grant> (set! ls (cons item ls))))
Grant> why?
Because Scheme passes procedure arguments by value rather than by
reference. (As most other programming languages, except FORTRAN.)
Calling CONS! creates a new variable binding for LS which disappears
again after the call, so modifications to it can't be seen on the
outside.
You probably want to define a macro (untested):
(define-syntax cons!
(syntax-rules ()
((cons! item ls) (set! ls (cons item ls)))))
--
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla
|