tags:

views:

210

answers:

1

If I have a list of 0's, how would I modify, for example, the 16th 0 in the list?

+3  A: 

You have to write it yourself. It is not built in to Scheme because it's not idiomatic and it can be built easily from set-car!.

(define (list-set! l k obj)
  (cond
    ((or (< k 0) (null? l)) #f)
    ((= k 0) (set-car! l obj))
    (else (list-set! (cdr l) (- k 1) obj))))

If you are doing this a lot, you should probably look at using vectors and vector-set! instead.

Nathan Sanders
ok, I will look into that.
Jonno_FTW