1

首先,我正在浏览HtDP 第 2 版并使用BSL语言包。

我目前正在练习 131,这就是它所说的:

Exercise 131: Design two functions: col and row.

The function col consumes a natural number n and an image i. It produces a column—a vertical arrangement—of n copies of i.

The function row consumes a natural number n and an image i. It produces a row—a horizontal arrangement—of n copies of i

Use the two functions to create a rectangle of 8 by 18 squares, each of which has size 10 by 10.

除此之外,我正在查看地点图像,但在如何执行此操作方面没有任何突出之处。这些函数不获取图像列表,而是获取单个图像。例如:(除了 rect1 rect2 rect3)而不是(除了(列表 rect1 rect2 rect3))。另外,如果我按照函数的定义方式进行定义,似乎我会在图像上重叠,因为函数本身是独立的。基本上我所说的重叠是在每一行的第一张图片上。

我不是在寻找答案(尽管如果你得到它,我会接受它),而是在正确方向上的暗示、标志、神圣干预。

4

1 回答 1

3

这是一个让你开始的例子:

; images->row : list-of-images -> image
(define (row->image row)
  (cond
     [(empty? row) empty-image]
     [else         (beside (first row) 
                           (row->image (rest row)))]))

(row->image (list (square 20 "solid" "red")
                  (square 20 "solid" "blue")
                  (square 20 "solid" "green")))
于 2013-02-23T18:42:18.210 回答