These are all bad tests and the implementation is totally wrong.
The only way to interact with a prolog expression is to call it with a
failure continuation and see what it does. For example, it is not the
case that all prolog expressions that succeed once are equal? (meaning
are the same source code) as =succeed.
Here are some real examples for =and2:
(define initial-fk (λ (_) (error 'fk "It failed")))
(test/exn ((=and2 =fail =fail) initial-fk)
"It failed")
(test/exn ((=and2 =succeed =fail) initial-fk)
"It failed")
(test/exn ((=and2 =fail =succeed) initial-fk)
"It failed")
(test/pred ((=and2 =succeed =succeed) initial-fk)
procedure?)
(test/exn (((=and2 =succeed =succeed) initial-fk) 'ignored)
"It failed")
Notice that the only way we "look" at the result of =and2 is by
calling it. Notice in the last case, where it succeeds once, it
returns a procedure? (which is a success continuation) and when we
call that, it fails, which means it succeeded one time.
In contrast, suppose that =succeed-twice is a prolog expression that
has two ways to succeed. Then, this is a test case:
(test/pred ((=and2 =succeed-twice =succeed) initial-fk)
procedure?)
(test/pred (((=and2 =succeed-twice =succeed) initial-fk) 'ignored)
procedure?)
(test/exn ((((=and2 =succeed-twice =succeed) initial-fk) 'ignored) 'ignored)
"It failed")
Jay
On Sun, Dec 15, 2013 at 1:02 PM, Reed Wilson <
reedc...@gmail.com> wrote:
> Jay,
>
> So, I can pass all of the test cases below using =succeed and =fail;
> however, I think that it needs to do more than this. ;) I am really lost
> though on how to bridge the gap between just checking for "true" and "false"
> and testing the prolog-expression's result.
>
> (define (=and2 e1 e2)
> (cond
> [(and (equal? e1 =succeed)
> (equal? e2 =succeed))
> =succeed]
> [else
> =fail]))
>
> ;; =and2 tests
> (test (=and2 =succeed =succeed) =succeed) ;; succeeds 1
> (test (=and2 =succeed =fail) =fail) ;; succeeds 0
> (test (=and2 =fail =fail) =fail) ;; succeeds 0
> (test (=and2 =fail =succeed) =fail) ;; succeeds 0
> (test (=and2 =fail (=and2 =succeed =succeed)) =fail) ;; succeeds 0
>
> Any light on this would be very appreciated.
>
> Thanks,
> Reed
--
Jay McCarthy <
j...@cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay
"The glory of God is Intelligence" - D&C 93