scsh-users
[Top] [All Lists]

Re: cons!

To: Grant Miner <mine0057@mrs.umn.edu>
Subject: Re: cons!
From: Michael Sperber <sperber@informatik.uni-tuebingen.de>
Date: Mon, 11 Aug 2003 14:23:41 +0200
Cc: scsh@zurich.ai.mit.edu
>>>>> "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

<Prev in Thread] Current Thread [Next in Thread>
  • cons!, Grant Miner
    • Re: cons!, Michael Sperber <=