Posted By

magicrebirth on 02/04/10


Tagged

macro scheme impromptu set-car set-cdr


Versions (?)

Change list in place : scheme/impromtu


 / Published in: Scheme
 

set-car! and set-cdr! change a list 'in-place'.

But, if you like the pointer metaphore... you could use macro's instead of procedures...

stupidly simple example...

  1. (define-macro (change-list lst)
  2. `(set! ,lst (map (lambda (i) (+ i 1)) ,lst)))
  3.  
  4.  
  5. (define mylist '(1 2 3 4 5))
  6.  
  7.  
  8. (change-list mylist)

Report this snippet  

You need to login to post a comment.