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 -- second cond used test, if make (the inner cond) return #f, whole test of outer cond getting #f, means (the outer cond) didn't true result, , resorts returning unspecified value (and if racket, value shown #<void>). if flatten 2 conds 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

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -