When I was skimming some prolog related questions recently, I stumbled upon this answer by @mat to question How to represent directed cyclic graph in Prolog with direct access to neighbour verticies .
So far, my personal experience with attributed variables in Prolog has been very limited. But the use-case given by @mat sparked my interest. So I tried using it for answering another question, ordering lists with constraint logic programming.
First, the good news: My first use of attributed variables worked out like I wanted it to.
Then, the not so good news: When I had posted by answer, I realized there were several API's and implementations for attributed variables in Prolog.
I feel I'm over my head here... In particular I want to know the following:
- What API's are in wide-spread use? Up to now, I found two: SICStus and SWI.
- Which features do the different attributed variable implementations offer? The same ones? Or does one subsume the other?
- Are there differences in semantics?
- What about the actual implementation? Are some more efficient than others?
- Can be (or is) using attributed variables a portability issue?
Lots of question marks, here... Please share your experience / stance? Thank you in advance!
Edit 2015-04-22
Here's a code snippet of the answer mentioned above:
init_att_var(X,Z) :-
put_attr(Z,value,X).
get_att_value(Var,Value) :-
get_attr(Var,value,Value).
So far I "only" use put_attr/3
and get_attr/3
, but---according to the SICStus Prolog documentation on attributed variables---SICStus offers put_attr/2
and get_attr/2
.
So even this very shallow use-case requires some emulation layer (one way or the other).