0

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!

  • Have a look at [“application: not a procedure” in binary arithmetic procedures"](http://stackoverflow.com/q/19022704/1281433). The error message is slightly different, but it's the same issue: an extra set of parentheses around a form (e.g., `((call/cc …))` means that you're evaluating the form (in this case, `(call/cc …)`) to produce a value (in this case `#f`), and then trying to call it as a function. I.e., `((call/cc …)) => (#f) => error`. When you look at that question, check out the "Linked" questions on sidebar; there are lots of similar questions with the same issue. – Joshua Taylor Jul 25 '14 at 03:36

2 Answers2

0

Don't write (#f), it should be #f.

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
  • i've updated the OP; i still get the error, however. Any ideas? –  Jul 24 '14 at 22:59
  • You still have too many parentheses. Remove the extra ones just after the first `#f`. – C. K. Young Jul 24 '14 at 23:05
  • that seemed to help, but the list actually prints empty. out of scope with this question, but do you know why? –  Jul 24 '14 at 23:24
0

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?)))
Sylwester
  • 47,942
  • 4
  • 47
  • 79
  • i removed the extra parentheses, and that seemed to work. However, the list returns empty (probably something wrong with predicate). Would you happen to know what is causing it to do this? –  Jul 24 '14 at 23:39
  • @NelsonLiu It evaluates to `#f`. empty is `()`.see edit. – Sylwester Jul 24 '14 at 23:48