Change list in place : scheme/impromtu


/ Published in: Scheme
Save to your folder(s)

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...


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.