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
condinside another,condintended multiple tests/results.there no reason have
statusmodified -- scheme uses call-by-value, not doing whatever think does.specifically, there no reason use
(else (set! status #f) status)-- return#fdirectly.the actual reason confusion weird
condnesting -- secondcondused test, if make (the innercond) return#f, whole test of outercondgetting#f, means (the outercond) didn't true result, , resorts returning unspecified value (and if racket, value shown#<void>). if flatten 2conds 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