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
2009-11-19 03:03:34
ok, I will look into that.
Jonno_FTW
2009-11-19 05:28:55