我试图创建一个程序,将接受两个颜色列表。因为这个过程是在另一个过程(本地)。我需要在传递参数时转换image->color-list。我尝试了不同的方式来声明它们,但编译器错误提示:
发现一个变量被使用了不止一次:image->color-list
或
期望一个变量,但是找到了一个部分
(define (colourLists image->color-list bg image->color-list fg))
(define (colourLists (image->color-list bg) (image->color-list fg)))
(define (colourLists (image->color-list bg image->color-list fg)))
是否有办法做到这一点,或者是不可能的?
看看我写的对不对。在另一个过程中有一个过程,它必须接收两个列表,但是在传递它们之前必须对它们进行转换。也许是这样的?
(define (outerProcedure)
(define (colourLists color-lst1 color-lst2)
<inner body>)
<outer body>
; colourLists is called at some point in the outer body
(colourLists (image->color-list bg) ; bg and fg were defined somewhere else
(image->color-list fg)))
关键是:在将列表传递给内部过程之前,必须先转换列表。或者,您可以在内部过程中执行转换:
(define (outerProcedure)
(define (colourLists bg fg)
(let ((color-lst1 (image->color-list bg))
(color-lst2 (image->color-list fg)))
<inner body>))
<outer body>
; colourLists is called at some point in the outer body
(colourLists bg fg)) ; bg and fg were defined somewhere else
"我正在尝试创建一个程序,它将接受两个颜色列表。"
你甚至不需要再想太多。此时,您知道要编写的函数的形状必须符合以下格式:
;; some-procedure: (listof color) (listof color) -> ???
(define (some-procedure colour-list-1 colour-list-2)
<fill-me-in>)
也就是说,在其他地方处理image->color
列表。该函数应该只关心它获得的颜色列表。它的定义根本不应该关心它输入的颜色列表是否来自image->color
的使用。