我想要一个这样的列表......
'((0 1 2) (3 4 5) (6 7 8) (0 3 6) (1 4 7) (2 5 8) (0 4 8) (2 4 6))
并替换所有出现的特定数字。
例如,在运行时
(replace 4 "x" '((0 1 2) (3 4 5) (6 7 8) (0 3 6) (1 4 7) (2 5 8) (0 4 8) (2 4 6)))
所需的输出是
'((0 1 2) (3 x 5) (6 7 8) (0 3 6) (1 x 7) (2 5 8) (0 x 8) (2 x 6)))
到目前为止我尝试过的是
(define (replace var player list)
(if (null? list)
'()
(if (list? (car list))
(replace var player (cdr list))
(if (equal? var (car list))
(cons player (replace var player (cdr list)))
(cons (car list) (replace var player (cdr list)))
))))
当我用x替换所有1时,输出为'(0 "x" 2)