Replies: 2 comments 8 replies
-
Not in your example.
The last query shows that there is another textual representation for the number one, in fact there are infinitely many. On the other hand the query above which asks about two-character representations for one is denied. So
And then there are cases of unexpected non-termination
This is particularly problematic as we commonly assume that if a query does terminate, also every instance of it will terminate. People have searched for better ways of expressing such relations, and this is still an open area. Think of just queries consisting of a sequence of |
Beta Was this translation helpful? Give feedback.
-
Syntax errors behave a bit odd. Think of
In both cases there is no substitution for |
Beta Was this translation helpful? Give feedback.
-
One thing that is often really useful to have in a Prolog program is to make a predicate work in all directions. Making a predicate monotonic is quite easy, but usually that means it will "not work" in some modes, and by this I mean non-termination or instantiation errors, which while not actually wrong aren't really a useful answer. This problem is a great part of why I started making the constraint predicates in constrained.pl. The predicate I will be using here is an real use case I stumbled into of relating a list to a string representation of it's length.
Making constraints like
length_c/2
helps a lot to make code look more idiomatic and logical, but is not as general as thevar/1
and friends approach because you will probably not have all constraints that you need implemented, and implementing a constraint is in general much harder, low level and error prone than usingvar/1
and(->)/2
.I feel that the
var/1
approach is a bit mechanical and can be implemented in a predicate usingterm_expansion/2
or even just a normal predicate. I will call this hypothetical predicatepermute_predicates
here, not sure about the arity. The problem with this is that it probably wouldn't skip the hardest part of ensuring that the instantiation conditions of the arguments make sense with the permutations.An idea is to give a description of valid modes of all the predicates that are used in a section, and so
permute_predicates
could generate an ideal(->)/2
chain so that the resulting section is the most general possible. A problem with that is that I think it would be ambiguous what the "best" general configuration would be in many cases, and that not every predicate's behavior can be easily described with just modes (for example, a predicate that gives a differently instantiated second argument based on the value (not instantiation) of the first argument). On the positive side, it seems that it's planned for Scryer to have a mode annotation system for predicates in the future, and sopermute_predicates
could maybe integrate with that.Have I missed an obvious way to do this currently?
Beta Was this translation helpful? Give feedback.
All reactions