Reputation: 821
Definitions:
(define-struct Cell (x y))
(define (count-in cell cells)
(cond
[(member? cell cells) 1]
[else 0]))
(define (touches cell cells)
(+
(count-in
(cell (Cell-x cell) (+ (Cell-y cell) 1)) (list cells))
(count-in
(cell (Cell-x cell) (+ (Cell-y cell) -1))(list cells))
(count-in
(cell (+ (Cell-x cell) -1) (Cell-y cell))(list cells))
(count-in
(cell (+ (Cell-x cell) 1) (Cell-y cell))(list cells))))
The check-expect and where the error occurs:
(check-expect (touches (make-Cell 2 30)
(list
make-Cell 2 31
make-Cell 1 29
make-Cell 1 30
make-Cell 2 30)) 2)
It is giving me an error saying:
function call: expected a function after the open parenthesis, but received (make-Cell 2 30)
Why is this happening? And how would I go about fixing this?
What the code does: Checks if a cell (with its values adjusted by 1) is presently in the list. So make-cell 2 30, the adjusting values would be 2 31, 2 29, 1 30, 3 30. And if the one of the cells is inside the list, itll produce a 1, if not it'll produce a 0. Then if the code just adds all them up telling me how many of the adjusted cells are in the list.
Upvotes: 0
Views: 6999
Reputation: 236122
You forgot to surround the calls to make-cell
with parentheses, and the touches
procedure looks wrong. Assuming that the member?
procedure is correctly implemented and works for a list of structures, this should work:
(define (touches cell cells)
(+
(count-in
(make-Cell (Cell-x cell) (+ (Cell-y cell) 1))
cells)
(count-in
(make-Cell (Cell-x cell) (+ (Cell-y cell) -1))
cells)
(count-in
(make-Cell (+ (Cell-x cell) -1) (Cell-y cell))
cells)
(count-in
(make-Cell (+ (Cell-x cell) 1) (Cell-y cell))
cells)))
(check-expect
(touches (make-Cell 2 30)
(list
(make-Cell 2 31)
(make-Cell 1 29)
(make-Cell 1 30)
(make-Cell 2 30)))
2)
Upvotes: 1