Re: prolog =and2, =or2

6 views
Skip to first unread message

Jay McCarthy

unread,
Dec 15, 2013, 5:10:15 PM12/15/13
to Reed Wilson, BYU CS 330 Fall 2013
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

Jay McCarthy

unread,
Dec 17, 2013, 8:29:51 PM12/17/13
to Willard Hagen, BYU CS 330 Fall 2013
No. =fail is a Prolog expression that fails. All Prolog expressions
take a failure continuation that they call when they fail. So, =fail
calls it's failure continuation. In my example, I use a failure
continuation that errors, but it is not correct to say that =fail
throws an error when called.

On Tue, Dec 17, 2013 at 6:23 PM, Willard Hagen <willar...@gmail.com> wrote:
> So if =fail is called it throws an error? What I mean by error is using
> racket's erring system.
>> --
>> You received this message because you are subscribed to the Google Groups
>> "byu-cs-330-fall-2013" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to byu-cs-330-fall-...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
> --
> -Willard

Willard Hagen

unread,
Dec 17, 2013, 8:49:14 PM12/17/13
to Jay McCarthy, BYU CS 330 Fall 2013
Thanks.  I have another question.  

The documentation says: 

"A failure-continuation? is a function that accepts a value (which it ignores) and fails; failure may mean aborting the entire Prolog search (meaning it returns nothing), or it may mean backtracking to an earlier point and trying something different (meaning it returns a success-continuation?)."

How do I determine if the search should be aborted or should be backtracked?

--
-Willard

Jay McCarthy

unread,
Dec 17, 2013, 8:50:25 PM12/17/13
to Willard Hagen, BYU CS 330 Fall 2013
That depends on the semantics of the function you're implementing.
When you write failure continuations (as you must when you call prolog
expressions) you have to decide.

Willard Hagen

unread,
Dec 17, 2013, 8:54:25 PM12/17/13
to Jay McCarthy, BYU CS 330 Fall 2013
Ah, so the function doesn't have to be called "failure-continuation".  It is just the type of function.
--
-Willard

Jay McCarthy

unread,
Dec 17, 2013, 10:16:37 PM12/17/13
to Willard Hagen, BYU CS 330 Fall 2013
Correct. That name is not used anywhere in the assignment text. 

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages