How to consistently replace atoms with variables in Prolog? -
i writing parser sparql (semantic web query language) using dcg. want replace sparql variable names prolog variables. how go this?
i can generate new variables using length([newvar], 1)
, cannot keep track of existing assignments using list of name-variable pairs. member/2
operation on list return new variable, not 1 stored in list.
is there easy way naming variables in prolog, e.g., '$var(name)'
?
member/2 want. here example:
welcome swi-prolog (multi-threaded, 64 bits, version 7.3.25) copyright (c) 1990-2016 university of amsterdam, vu amsterdam l=[a-x,b-y,c-z], member(b-v,l). l = [a-x, b-v, c-z], y = v
but might problems if interleave write/1 member/2, since variable might change identity, i.e. write symbol in following circumstances:
- because of garbage collection, if variable written _g<memloc>
- because of aliasing, in above example memloc of v might shown
instead of memloc of y
same problem (@<)/2. 1 way out use attribute variables, @ least puts end aliasing, since attribute variables unified last,
so in above example if y attribute variable , v ordinary variable never see memloc of v after calling member/2.
bye
Comments
Post a Comment