when to unless

main
Matthew Butterick 10 years ago
parent 05a763b9b5
commit d00a51b221

@ -123,13 +123,13 @@
(return-k)]))
(when (and forward-check? (not (equal? singlevalue _unassigned)))
(for ([variable (in-list variables)])
(when (not (variable . in? . assignments))
(unless (variable . in? . assignments)
(set! domain (hash-ref domains variable))
(when (not (singlevalue . in? . (domain)))
(unless (singlevalue . in? . (domain))
(set! return-value #f)
(return-k))
(for ([value (in-list (domain))])
(when (not (equal? value singlevalue))
(unless (equal? value singlevalue)
(send domain hide-value value))))))
(set! return-value #t)
(return-k))

@ -49,8 +49,8 @@
(set! pushdomains
(if _forwardcheck
(for/list ([(var domain) (in-hash domains)]
#:unless (and (hash-has-key? possible-solution var)
(equal? variable var)))
#:unless (and (equal? variable var)
(hash-has-key? possible-solution var)))
domain)
null))
variable))
@ -62,7 +62,7 @@
(let/ec exit-k
;; mix the degree and minimum-remaining-values (MRV) heuristics
(let main-loop ()
(when (not (get-next-unassigned-variable))
(unless (get-next-unassigned-variable)
(yield (hash-copy possible-solution)) ; if there are no unassigned variables, solution is done.
(if (null? variable-queue) ; if queue isn't empty, return to previous variable, otherwise all done.
(exit-k)

Loading…
Cancel
Save