Short Circuit?

14 views
Skip to first unread message

Andrew

unread,
Dec 5, 2012, 12:40:06 AM12/5/12
to byu-cs-330...@googlegroups.com
I'm a little confused on the short circuiting nature, or McCarthy evaluation (hah, you learn something every day - thanks Wikipedia), of the 'and' and 'or' - I would have thought this meant the 'and' ceases to continue checking after the first failure in one of its expressions, and the 'or' stops after the first successful expression it encounters.

However, in the documentation it states:

<quote>
For instance,
succeeds in six ways. The first =or succeeds in three ways, the second =or succeeds in two ways, and the =and combines them in all possible ways. Likewise,
(=or (=and =succeed =succeed)
     (=and =fail =succeed =succeed)
     (=and =succeed))
succeeds in two ways. The first and third =ands each succeed in one way, and the =or explores both of them.
</quote>
This description of the =and and =or behavior seem to contradict short circuiting behavior (at least my understanding of the descriptions and what it means to short circuit).
Help?

Brian Kingery

unread,
Dec 5, 2012, 12:55:55 AM12/5/12
to BYU CS 330 Fall 2012
I hope it's okay for me to share this information.  But seeing how Jay is offline, and it doesn't have any implementation specific information I feel okay with sharing the information.  Here is what Jay told me when I asked basically the same question.

"short-circuiting means it doesn't EVALUATE the rhs until it needs to.
that's the normal definition of short-circuiting, just like...
(or #t (begin (printf "Hey") #t))
...doesn't print anything.

The difference is that with prolog you can ask for the next #t, and therefor get it to print eventually."


I hope that helps.



--
 
 



--
Brian Kingery
BYU - OIT Core Services
Desk: 801-422-5811
Location: ITB 2226L

Jay McCarthy

unread,
Dec 5, 2012, 9:03:48 AM12/5/12
to BYU CS 330 Fall 2012
But, the print won't happen until you tell Prolog to get the next answer. In Prolog you can always get all the answers, but they are only /evaluated/ until they are needed.

Jay


--
 
 



--
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
Reply all
Reply to author
Forward
0 new messages