在球拍中使用停止时 [英] using stop-when in racket
本文介绍了在球拍中使用停止时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在搞这个程序.它需要一个数字并在其上加 1.我想知道你怎么能在这里使用 stop-when
?例如,让它停在 5 点?我想这里需要一个条件声明.谢谢.
I've been messing around with this program. It takes a number and adds 1 to it.
I am wondering how exactly could you use stop-when
here? For example, to make it stop at 5? I suppose a cond statement is necessary here. Thanks.
(require 2htdp/image)
(require 2htdp/universe)
(define (my-tick n)
(add1 n))
(define (my-render n)
(text (number->string n) 36 "silver"))
(big-bang 1 (on-tick my-tick 2) (to-draw my-render))
推荐答案
给 stop-when
一个谓词,它消耗一个世界并返回 true 或 false.
Give stop-when
a predicate that consumes a world and returns true or false.
有关更多信息,请参阅文档 这里.
For more info, see the docs here.
这是在 5 点停止的示例版本:
Here's a version of your example that stops at 5:
(require 2htdp/image)
(require 2htdp/universe)
(define (my-tick n) (add1 n))
(define (my-render n)
(text (number->string n) 36 "silver"))
(define (=5 n) (= n 5))
(big-bang 1 (on-tick my-tick 2) (to-draw my-render) (stop-when =5))
这篇关于在球拍中使用停止时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文