Ron Marchant
Ron Marchant

Reputation: 61

application: not a procedure mismatch error

I'm trying to implement a sort of read-write to cell function.

(define (read-write-get cell) (cell (list)))
(define (read-write-set cell x) (cell (list x)))

(define (read-write-cell x)
   (let ((cell '()))
       (read-write-set cell x)))

(define w1 (read-write-cell 10))
(check-equal? 10 (read-write-get w1))

I keep getting the error

application: not a procedure; expected a procedure that can be applied to arguments given: '() arguments...: errortrace...:

Upvotes: 2

Views: 97

Answers (1)

Renzo
Renzo

Reputation: 27424

In Scheme (x y) means apply the function x to the argument y. So

(define (read-write-set cell x) (cell (list x)))

defines a function read-write-set that, when called with the first parameter which is a function, applies that function, cell, to the result of evaluating (list x) (which build a list with the unique element the second parameter).

Then, in:

(define (read-write-cell x)
   (let ((cell '()))
       (read-write-set cell x)))

You call read-write-set with the first argument which is not a function, but an empty list (since cell is assigned to '() in the let).

So, “not a procedure; expected a procedure” refers to the value of the first argument to read-write-set, which is not a procedure but a list. It is not clear to me the intended behaviour of read-write-get and read-write-set, so I cannot suggest how to correct them.

Upvotes: 3

Related Questions