Scheme 添加不同的股票代码时间

Scheme 添加不同的股票代码时间,scheme,racket,ticker,Scheme,Racket,Ticker,您好,您能帮我添加一种方法,使每个灯有不同的定时器长度。我正在做一个世界之州/大爆炸计划,它创造了一个交通灯,在绿色、黄色和红色之间循环,如果你点击空格键,它会立即变为绿色。我所有的东西都在运行,但我无法调整股票行情以使其不同——它总是一个固定的时间 (require 2htdp/image) (require 2htdp/universe) ;; ================= ;; Constants: (define WIDTH 600) (define HEIGHT 350) (

您好,您能帮我添加一种方法,使每个灯有不同的定时器长度。我正在做一个世界之州/大爆炸计划,它创造了一个交通灯,在绿色、黄色和红色之间循环,如果你点击空格键,它会立即变为绿色。我所有的东西都在运行,但我无法调整股票行情以使其不同——它总是一个固定的时间

(require 2htdp/image)
(require 2htdp/universe)

;; =================
;; Constants:

(define WIDTH 600)
(define HEIGHT 350)
(define MTS (empty-scene WIDTH HEIGHT))
(define RAD 50)
(define WIDTH_2 (/ WIDTH 2))
(define CTR-Y (/ HEIGHT 2))

;; =================
;; Functions:

;; trafficLightNext Tests
(check-expect (trafficLightNext "red") "green")
(check-expect (trafficLightNext "yellow") "red")
(check-expect (trafficLightNext "green") "yellow")

;; Traffic Light -> Boolean
;; Find the current-state of a Traffic Light (red, yellow or green)
(define (isRed? current-state)
  (string=? "red" current-state))
(define (isYellow? current-state)
  (string=? "yellow" current-state))
(define (isGreen? current-state)
  (string=? "green" current-state))

;; Traffic Light -> Traffic Light
;; Finds the next state for the Traffic Light
(define (trafficLightNext current-state)
   (cond
    [(isRed? current-state) "green"]
    [(isYellow? current-state) "red"]
    [(isGreen? current-state) "yellow"]))

;; Render Tests
(check-expect (bulb "red" "red") (circle RAD "solid" "red"))
(check-expect (bulb "green" "green") (circle RAD "solid" "green"))
(check-expect (bulb "yellow" "red") (circle RAD "outline" "red"))

(define (light=? current-state color)
  (string=? current-state color))

;; Traffic Light -> Image
;; Renders the the light
(define (bulb on c)
  (if (light=? on c) (circle RAD "solid" c) (circle RAD "outline" c)))


;; Traffic Light -> Image
;; Takes a Traffic Light places the image on the scene
(define (trafficLightRender current-state)
 (place-image
   (bulb current-state "red")   
   WIDTH_2
   52
   (place-image
    (bulb current-state "yellow")
    WIDTH_2
    CTR-Y
     (place-image
      (bulb current-state "green")     
     WIDTH_2
     298
      MTS))))

;; TrafficLight -> TrafficLight
;; Traffic Light changes every second
(define (traffic-light-simulation initial-state)
  (big-bang initial-state (on-tick trafficLightNext 1) (to-draw trafficLightRender) (on-key ambulance)))

;; Key -> TrafficLight
;; Changes light to green everytime key is touched
 (define (ambulance initial-state key)
  (cond [(key=? key " ") "green"]
        (else initial-state)))

(check-expect (ambulance "yellow" " ") "green")
(check-expect (ambulance "red" " ") "green")
(check-expect (ambulance "yellow" "d") "yellow")

因为这看起来像是一个学校作业,我不会给你一个完整的解决方案,只有线索

如果宇宙大爆炸的速率表达式是一个以当前状态为输入的函数,那就容易多了,但事实并非如此,因此需要一种函数方法

一种可能是使您的世界状态更复杂:它可以是灯光加上倒计时值,而不仅仅是当前灯光。在每次滴答声中,您不会立即更改灯光,而是从状态计数器中减量减去1。当倒计时达到0时,更改灯光并将倒计时重新初始化为取决于新灯光的值。 主要更改是trafficLightNext功能和测试,但由于状态不同,程序的其余部分也必须修改