[plt-scheme] how to test for optional requirements in nondeterministic programming

From: Sigrid Keydana (keydana at gmx.de)
Date: Tue Jan 20 04:13:05 EST 2009

Hi,

like in the SICP "puzzles", I am using amb to choose people from a list
and then verify that requirements are fulfilled with an assert method.
Now, in addition to the requirements, I also want to make the result
satisfy some "optional" requirements or "nice-to-have"s if possible, but
in contrast to the "hard requirements" the program may not fail if this
doesn't work out.

The only thing I could think of so far was: when "hard requirements" are
fulfilled, get the current continuation with call/cc, call some
"optional-assert" method which would look like

(define optional-assert
  (lambda (condition current-result cont)
    (if (not condition)
        (if (eq? fail 'TOTAL-FAIL) (cont current-result) (fail))
        #t)))

[where fail is the global variable which holds amb's saved continuation]

I haven't tried this yet, but anyway it's surely not an elegant solution.

Perhaps someone has a suggestion for me how to better handle this?

Thanks a lot in advance,
Sigrid



Posted on the users mailing list.