Glad it helped!

Reordering of conde clauses (that is, re-ordering of disjuncts) is
always "safe" in terms of divergence/looping versus finite
failure/finite termination, although the running time could change
dramatically (milliseconds vs. billions of years).  This isn't true of
conjuncts in miniKanren (top-level goals in a fresh or run, and goals
within an individual conde clause); reordering conjuncts can change a
run* that terminates into one that loops forever, or vice versa.  In
general, you want goals that have the possibility of "failing fast" to
come first.  For example, calls to == or =/= should always come before
calls to recursive goals that might produce an unbounded number of
answers.

The canonical example is something like:

(run 1 (q) (== 5 6) (fooo q))

where 'fooo' is a goal that succeeds an unbounded number of times.
This run 1 will immediately return (), indicating that there are no
answers.  However, the logically equivalent program

(run 1 (q) (fooo q) (== 5 6))

will loop forever, looking for the non-existent first answer.  This is
because the call to fooo will succeed, (== 5 6) will fail, fooo will
be tried again and will succeed, (== 5 6) will fail again, ...

Does that make sense?

On Tue, Feb 25, 2014 at 3:11 PM, Steve Olsen <[email protected]> wrote:
> Thanks a lot, this is very helpful!
>
> The reordering of goals makes a lot of sense. I wasn't thinking about
> efficiency and was mostly operating under the assumption that the order of
> rules didn't matter. I guess in practice of course that is important.
>
> During my development I was running into some problems where I knew there
> was only one answer and I would get it if I did run 1 but when I did run* it
> would run forever. I'm guessing that had something to do with rule order
> too. I'm not sure exactly what the situation was though.
>
> I also still feel like there must be a way to do it with only one
> environment var. If there was a way to say, this is a member of this list or
> something like that.
>
> This is actually a preliminary step in a weird game Idea I'm hacking out
> where you write some first-order logic rules that fly rocket ships around. I
> think I'll need to write a meta interpreter around this that will let me
> return some error messages to the user when there's more than one solution
> or two rules conflict or whatever. I'll have to tackle that when I'm a bit
> further on though.
>
>
> On Tuesday, February 25, 2014 4:14:02 PM UTC-5, William Byrd wrote:
>>
>> Take a look at this:
>>
>> https://gist.github.com/webyrd/9217893
>>
>> On Tue, Feb 25, 2014 at 1:56 PM, Steve Olsen <[email protected]> wrote:
>> > Either of those would be great. Whichever you prefer.
>> >
>> >
>> > On Tuesday, February 25, 2014 3:38:40 PM UTC-5, William Byrd wrote:
>> >>
>> >> Okay, I understand all of the code.  What would be the best way to
>> >> give you feedback?  Show you the changes I'd make to the code?
>> >> High-level text?
>> >>
>> >> On Tue, Feb 25, 2014 at 12:24 PM, Steve Olsen <[email protected]>
>> >> wrote:
>> >> >> Your environment associates symbols to logic variables representing
>> >> >> truth values?  Is that correct?
>> >> >
>> >> >
>> >> > Yes
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "minikanren" group.
>> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> > send
>> >> > an
>> >> > email to [email protected].
>> >> > To post to this group, send email to [email protected].
>> >> > Visit this group at http://groups.google.com/group/minikanren.
>> >> > For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "minikanren" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to [email protected].
>> > To post to this group, send email to [email protected].
>> > Visit this group at http://groups.google.com/group/minikanren.
>> > For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> You received this message because you are subscribed to the Google Groups
> "minikanren" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/minikanren.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"minikanren" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/minikanren.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to