functor_spec/3, a generalization of functor/3 that works in all modes #2021
Replies: 10 comments 18 replies
-
It would be nice to give such predicates a good general suffix. Think of the Apart from bakaq/constrained.pl#1, it is not clear how and what kind of consistency should be maintained. Think of
And it is not clear if this should be the sole responsibility of
All of this is quite close to CHRs.
Annoying they are only if there is an
At first it seems that constraints/delayed goals are the answer. But if you look at the development of Prolog systems this is not that evident. One of the first systems in that direction was MU/NU-Prolog with it's wait declarations. Even SICStus adopted them early on as Another approach worth mentioning is Prolog III and even more so Prolog IV. There are some such constraints that are maintained automatically. |
Beta Was this translation helpful? Give feedback.
-
Just for completeness, labeling (that is |
Beta Was this translation helpful? Give feedback.
-
I agree, I just didn't think of anything good and wanted to implement it before thinking about names. Some things that come to mind:
|
Beta Was this translation helpful? Give feedback.
-
I don't know if something like
But you can already generate all the aritys with
One idea is to maybe implement so that it only works when the set of possible functors is finite, just like |
Beta Was this translation helpful? Give feedback.
-
I definitely thought about doing something like I did with |
Beta Was this translation helpful? Give feedback.
-
I think the property I would want from If there are only I think this is strictly stronger than monotonicity. Some predicates that seem to have this property are |
Beta Was this translation helpful? Give feedback.
-
Not sure what you mean here by "other answers", As long as an answer is conditional, so there are some residuals floating around (more precisely floundering around), it might be weak, but not wrong.
Not sure what you mean here. An (complete) answer, that is more specific is just incomplete. Also termination or rather non-termination comes here into play. What about calling it And as you mention
Traditionally this was often called a solution. But these are infinitely many solutions. In any case, for the purpose of better examples, consider a constraint version of In Prolog IV there is a related constraint version |
Beta Was this translation helpful? Give feedback.
-
Ok, let me specify. Suppose we have the following query:
The "answer" for this permutation is more specific, but it is still consistent with the other "answer". This "set of all answers found on backtracking" is a subset of the other permutation. Now suppose this:
The "answer" for this permutation is more general, but it is still consistent with the other "answer". The "set of all answers found on backtracking" of the other answers are subsets of this one. I guess there are more complicated cases where the "answers" are not subsets of one another but are still consistent, but I guess this is enough to explain what I meant. |
Beta Was this translation helpful? Give feedback.
-
At least for the finite case. For the infinite case, things get a bit less precise, when you have unfair enumeration and the like. |
Beta Was this translation helpful? Give feedback.
-
This project seems to be an excellent candidate for a great presentation at the Scryer Prolog meetup in November: https://hsd-pbsa.de/veranstaltung/scryer-prolog-meetup-2023/ If possible, please consider attending the meetup, it would be great to meet you there! |
Beta Was this translation helpful? Give feedback.
-
Recently I made this library to learn how to use attributed variables. It provides a predicate
functor_spec/3
that works likefunctor/3
, but delays execution so that it can work in all modes. The goal was to make something likedif/2
is to(\==)/2
, and I think I was able to do it (I made a lot of tests).It also provides a variant
functor_spec/4
in which the fourth argument is a list of the arguments of the term,(#=..)/2
which is a generalization of(=..)/2
, reified versions of these for use withlibrary(reif)
(functor_spec_t/4
,functor_spec_t/5
and(#=..)/3
), and a predicatefunctor_match_t/3
for use withlibrary(reif)
which unifies it's arguments only if they have the same functor and arity.Example of usage:
I feel like this could be integrated into a built-in library for Scryer, but I'm not sure if this is useful enough to justify that. In my (not so extensive) experience, using predicates like
functor/2
and(=..)/2
usually means that there is a better way to do it with implicit unification in the arguments of predicates (which also can benefit from indexing). But maybe that impression I have is just because they are modal and, because of that, very annoying to use.Beta Was this translation helpful? Give feedback.
All reactions