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"