如何更新球拍(宇宙)中的另一个结构内的结构列表

问题描述:

这是一项家庭作业,所以我不要求代码只是指导。 我是新来的球拍语言和使用没有拉姆达的ISL。 我不能使用lambda或任何其他库。如何更新球拍(宇宙)中的另一个结构内的结构列表

我正在使用bigbang。我有一个struct struct-abc。在struct-abc里面,我有一个名为list-abc的列表。在list-abc里面,我有一个struct-xyz的集合。我需要更新每个tick中struct-abc内的list-abc里面的所有struct-xyz。

这是我到目前为止有:

; my main struct - struct-abc 

    (define-struct struct-abc (list-abc)) 

; my struct - struct-xyz 

    (define-struct struct-xyz (pos1 pos2 pos3 radius)) 

; my list - list-abc which adds instances of struct-xyz to the list 

    (define (list-abc struct-xyz-instance lst) 
     (cond 
     [(empty? lst) (cons struct-xyz-instance empty)] 
     [else (cons struct-xyz-instance lst)])) 

与上面的代码片段,我能添加结构-XYZ的新实例列出abc的鼠标事件或按键事件。现在如何在每次打勾时自动更新list-abc中的所有struct-xyz?

这里是我的BIGBANG功能(不包括所有参数):

(define (main rate) 
    (big-bang (initial-world rate) 
      (on-tick world-after-tick rate) 
      (on-draw ...))) 

这里是我的世界后,蜱功能,我传递参数的世界和列表农行的辅助功能:

(define (world-after-tick-recursive world) 
    (update-world-recursive world (world-list-abc world))) 

现在,在这个帮助函数中,我想将list-abc中的第一个struct-xyz传递给另一个帮助函数,该函数更新值并递归传递list-abc中的每个结构。我如何调用递归函数以及更新值的函数?我无法弄清楚这一部分:

(define (update-world-recursive world abc-list abc-rest-list) 
    (cond 
    [(empty? abc-list) #false] ; If empty end bigbang 
    [else 
    (update-world world (first abc-list) (rest abc-list))] 
; Where and how do I call the update-world-recursive function? 


(define (update-world world abc-list) ; This takes the first struct from list 
... update pos1 of abc-list 
... update pos2 of abc-list) 
+0

您是否了解过“地图”? – molbdnilo

这些名字让我无法控制,我会建议您将主要功能分解为多个层次。每个级别都与提供给它的信息做了不同的事情。您可以根据每个任务需要访问哪个级别来决定哪个级别。像molbdnilo说,地图将解决您的问题的一个很大的部分。