y
永远不会被重置回0
. 您的代码将递增y
到35
,然后递增x
20 次,但是在每个后续递增时x
y
仍设置为35
。
如果您想查看 的值的每个组合,x
那么y
您将需要更像这样的代码:
(while (< x 20)
(set! y 0)
(while (< y 35)
(gimp-message (string-append (number->string x) "-" (number->string y)))
(set! y (+ y 1))
)
(set! x (+ x 1))
)
这是一个更完整的示例,因为我有时间使用 Gimp 解决这个问题(我使用的是print
不是gimp-message
因为我在控制台中工作,但它应该是可互换的)。首先,我定义了一个调用的函数SO
,它接受参数 ,x
,y
它们都表示成对的最小值和最大值:
(define (SO x y)
(let* ((x! (car x)) (y! (car y)))
(while (< x! (car (cdr x)))
(set! y! (car y))
(while (< y! (car (cdr y)))
(print (string-append (number->string x!) "-" (number->string y!)))
(set! y! (+ y! 1))
)
(set! x! (+ x! 1))
)
)
)
在这个函数中,我提取了 and 的第一个和最后一个值(然后x
我使用x! y! x y` 在调用函数后发生变化)。如果你这样调用这个函数:y
(car x)
(car (cdr x))
let* to create two inner variables called
and
that I will be altering the value of (to remove side effects of having
and
(SO '(15 20) '(30 35))
您会得到以下输出:
"15-30"
"15-31"
"15-32"
"15-33"
"15-34"
"16-30"
"16-31"
"16-32"
"16-33"
"16-34"
"17-30"
"17-31"
"17-32"
"17-33"
"17-34"
"18-30"
"18-31"
"18-32"
"18-33"
"18-34"
"19-30"
"19-31"
"19-32"
"19-33"
"19-34"