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

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -