racket - Scheme - application: not a procedure error -
racket - Scheme - application: not a procedure error -
i'm coding function in scheme i'm getting "application: not procedure; expected procedure can applied arguments" error. assume haven't used conditional statements correctly:
(define find-allocations (lambda (n l) (if (null? l) '() (cons ((if (<=(get-property (car l) 'capacity) n) (cons (car l) (find-allocations (- n (get-property (car l) 'capacity)) (cdr l))) '())) (if (<=(get-property (car l) 'capacity) n) (cons (car l) (find-allocations (n (cdr l)))) '())))))
if can point out error that'd much appreciated.
try this:
(define find-allocations (lambda (n l) (if (null? l) '() (cons (if (<= (get-property (car l) 'capacity) n) (cons (car l) (find-allocations (- n (get-property (car l) 'capacity)) (cdr l))) '()) (if (<= (get-property (car l) 'capacity) n) (cons (car l) (find-allocations n (cdr l))) '())))))
it's mutual error when learning scheme: writing unnecessary parentheses! remember: in scheme pair of ()
means function application, when write - this: (f)
, scheme tries apply f
if procedure, in code had couple of places happening:
((if (<=(get-property (car l) 'capacity) n) ; see extra, wrong ( @ origin (find-allocations (n (cdr l)))) ; n not function, ( mistaken
scheme racket
Comments
Post a Comment