racket - Scheme's "expected a procedure that can be applied to arguments" -
i use drracket. have problem code:
(define (qweqwe n) ( (cond [(< n 10) #t] [(>= (lastnum n) (pochtilastnum n)) (qweqwe (quotient n 10))] [else #f] ) ) ) (define ( rty file1 file2 ) (define out (open-output-file file2 #:mode 'text #:exists 'replace)) (define in (open-input-file file1)) (define (printtofile q) (begin (write q out) (display '#\newline out) )) (define (next) (define n (read in)) (cond [(equal? n eof) #t] [else (begin ((if (qweqwe n) (printtofile n) #f)) ) (next)] ) ) (next) (close-input-port in) (close-output-port out)) but when start ( rty "in.txt" "out.txt" ) have error @ ((if (qweqwe n) (printtofile n) #f)) :
application: not procedure; expected procedure can applied arguments given: #f arguments...: [none] what's problem?
add: changedmy code to:
(cond [(equal? n eof) #t] [else (if (qweqwe n) (printtofile n) #f) (next)] ) but problem remains.
there unnecessary parenthesis, don't this:
((if (qweqwe n) (printtofile n) #f)) try instead:
(if (qweqwe n) (printtofile n) #f) also in here:
(define (qweqwe n) ((cond [(< n 10) #t] [(>= (lastnum n) (pochtilastnum n)) (qweqwe (quotient n 10))] [else #f]))) it should be:
(define (qweqwe n) (cond [(< n 10) #t] [(>= (lastnum n) (pochtilastnum n)) (qweqwe (quotient n 10))] [else #f])) in both cases problem if surround () expression, means you're trying invoke procedure. , given result of if , cond expressions above don't return procedure, error occurs. also, bothbegins in original code unnecessary, cond has implicit begin after each condition, same thing body of procedure definition.
Comments
Post a Comment