I'm trying to filter out a list based off of a predicate I wrote myself, but when I run the filter, I get
ERROR: Wrong value to apply: #f
The code of the predicate:
;;;Predicate for checking if a string is not empty or full of whitespaces
(define (notwhitespace? str)
(if (equal? str "") #F (
(call-with-current-continuation
(lambda (return)
(for-each
(lambda (c)
(if (not (char-whitespace? c)) #T #F))
(string->list str))
#F))
)
)
)
this is my implementation of the filter (it is in a let statement):
(updated-strlist(filter notwhitespace? strlist))
any ideas? thanks!
不要写(#f)
,应该是#f
。
So (call-with-current-continuation ...)
in your code is wrappen in extra parentheses which means that Scheme should take the result and run it as a procedure the moment it gets it.
Usually in a LISP evaluator apply
is the procedure that runs procedures. eg.
(define (test) (display "hello"))
(define (get-proc) test)
((get-proc)) ; ==> undefined, displays "hello"
You code however tries to do this (#f)
and since #f is not a procedure apply
cannot run it as if it were one.
A comment on the rest there. If you are not using return
you really shouldn't use call-with-current-continuation
at all and for-each
does sonething entirely different than you think. nowhitespace?
will always evaluate to #f
when you've fixed your problems because the last expression in the body of the continuation lambda is #f
(the returned value).
I guess you are looking for something like:
;; needs to import (srfi :1)
(define (notwhitespace? str)
(every (lambda (x) (not (char-whitespace? x)))
(list->string str)))
;; needs to import (srfi :13)
(define (notwhitespace2? str)
(not (string-index str char-whitespace?)))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.