-
I'm looking into implementing Constraint Handling Rules in Scryer as a module, and I think it can be done with just I know Scryer has some way to do it, because it has residual goals with attributed variables, but in the little I have delved into it, it seems that it's very attached to the toplevel. Is there a general way of doing residual goals that I'm not aware of or is it necessary to modify the toplevel to make it possible to do this in a new module? If there isn't a general way to do residual goals, should we add a way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
CHRs are not really constraints, but something close. They need an explicit notion of a store. And thus they do not enjoy the same algebraic properties as constraint systems do. Also, it seems that interest in them has waned. The current implementation in SWI is incompatible with occurs-check unification being activated at the same time. So this would not be an easy port. There are definitely more grateful tasks to consider. |
Beta Was this translation helpful? Give feedback.
-
Every module that attaches attributes to variables can describe residual goals as a relation between an attributed variable and a list of goals, described with the DCG nonterminal If this nonterminal is present in a module where attributes of a variable stem from, then, when residual goals are needed, it is automatically invoked with the variable as argument. The nonterminal must describe a list of goals that, when called, cause equivalent attributes to be present on that variable. Also, it should remove the attributes it has translated to such goals. For example, in attribute_goals(X) --> { get_atts(X, +dif(Goals)) }, gather_dif_goals(X, Goals), { put_atts(X, -dif(_)) }. The interface to relate terms to residual goals is ?- dif(X, Y), copy_term(X-Y, X-Y, Gs). Gs = [dif:dif(X,Y)], ... . |
Beta Was this translation helpful? Give feedback.
-
What's the status of this project? I'm very interested in having a CHR implementation for Scryer. |
Beta Was this translation helpful? Give feedback.
In short, what you see here is not the Prolog code that is actually running when you try the example, because these sample definitions are only Prolog facts.
You can define goal expansions to expand these facts to any Prolog clauses you want. These clauses can introduce variables and attach attributes as you need them. The residual goals can omit any variable that is not needed.