((- - -)(- - -)(- - -))
我希望访问此列表中的特定索引(例如0,1)并将其设置为1
((- 1 -)(- - -)(- - -))
怎么能在计划中完成?
在球拍中,您可以使用for/list
将结果累积到列表中。
e
是row
(列表)中的每个元素,而i
,j
跟踪l
中的索引位置。
;; [Listof [Listof Any]] Nat Nat Any -> [Listof [Listof Any]]
;; changes the element at (`x`, `y`) position in `l` to `to`
(define (change-at l x y to)
(for/list ([row l] [i (length l)])
(for/list ([e row] [j (length row)])
(if (and (= x i) (= y j))
to
e))))
(change-at '((- - -) (- - -) (- - -)) 0 1 1)
;; => '((- 1 -) (- - -) (- - -))