-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refining/constraining predicates based on combination of fields #139
Comments
Clorm currently doesn't have a way to specify conditions between fields. It could be a useful feature to add and I could imagine having a specially named class member function that checks some user-specified condition. Unfortunately, for the moment my only thought would be to define two distinct classes:
On the positive side this would only unify with the facts that you require and the |
Thank you for the suggestion. I can reduce a little bit the pain of having two classes when querying by taking their union at the cost of prefixing my predicates.
I'm not sure what would be the best approach to make these sort of things more direct, but it feels like the union not being first class is one element that gets in the way. For example, I can replace |
That's a neat trick with using a Yes, union is not a first class element in the query. There are a bunch of features that would be nice to add to the query mechanism but would need substantial rewriting to get around limitations of the current implementation. Adding a way to constrain the unification based on the combination of values would be a simpler and more self-contained task. |
Agreed. First-class union is overkill for the usecase in this issue. Drawing inspiration from the
Was that the sort of thing you had in mind? |
Yes, something like this. Adding it to the class signature is one option. Something like the way
|
Is there a mechanism to impose constraints on the predicate sub-class based on combinations of fields?
In the following example, I would like any predicate intance that unifies with the Data class to be such that if the info type is
"height"
then the value is of typeint
and if the info type is"firstname"
then the value is of typestr
. I would like theuser3
facts not to unify withData
. A suitable solution to my problem would let me avoid the additional filtering condition in functionprint_data
because the querying mechanism should have already filtered out the bad data.I know that I could turn
data
to an arity-2 predicate and turnheight
andfirstname
into arity-1 function symbols. For exampledata(user1,height(170)). data(user1,firstname("Anna")).
This would let me define a suitably constrainedData
class directly, but it is undesirable for other reasons (e.g., it messes up themissing/2
rule).The text was updated successfully, but these errors were encountered: