From d00a51b2219e80e958d19af527c0e2334fb735ce Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 5 Oct 2014 17:28:42 -0700 Subject: [PATCH] when to unless --- csp/constraint.rkt | 6 +++--- csp/solver.rkt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/csp/constraint.rkt b/csp/constraint.rkt index 235d2532..79faf7d7 100644 --- a/csp/constraint.rkt +++ b/csp/constraint.rkt @@ -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)) diff --git a/csp/solver.rkt b/csp/solver.rkt index ac97e3e7..71ab5c4a 100644 --- a/csp/solver.rkt +++ b/csp/solver.rkt @@ -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)