How I can force scheme to return #f explicitly instead of just void? -
(define every-aux (lambda(status predicate lst) (cond((null? lst) status) ((cond((equal? (predicate (car lst)) #t) (set! status #t) (every-aux status predicate (cdr lst))) (else (set! status #f) status))))))
above procedure returns void if predicate not match every element in lst?
it not have problem returning #t though if predicate matches every element of lst.
changing last line
(else (set! status #f) status))))))
to
(else (set! status "#f") status))))))
returns "#f" procedure correct.
how can force scheme return #f explicitly instead of void?
your code messy:
you have
cond
inside another,cond
intended multiple tests/results.there no reason have
status
modified -- scheme uses call-by-value, not doing whatever think does.specifically, there no reason use
(else (set! status #f) status)
-- return#f
directly.the actual reason confusion weird
cond
nesting -- secondcond
used test, if make (the innercond
) return#f
, whole test of outercond
getting#f
, means (the outercond
) didn't true result, , resorts returning unspecified value (and if racket, value shown#<void>
). if flatten 2cond
s one, problem go away.finally, if you're having problems @ such level, should consider using textbook familiarize language. htdp intended give easy path getting familiar syntax.
Comments
Post a Comment