« Return to Thread: Destructive update of terms (from foreign code)

Destructive update of terms (from foreign code)

by Roberto Bagnara :: Rate this Message:

Reply to Author | View in Thread


Hi there.

I have the following problem and I don't know the best
way to solve it.  I have a gigantic, ground Prolog term.
In this term there are some subterms of the form

        f(..., ..., ..., N)

where N is a (small) integer.  The computation consists
of three phases:

1) a traversal of the original gigantic term;
2) a second traversal which copies the original term
    into a new term that is equal to the original apart
    from the fact that some of the integers (N) have been
    replaced by some other integers;
3) a traversal of the new, modified term.

What happens is that:

a) the copy of point (2) is too expensive;
b) the original term is no longer needed after point (2);
c) there is no backtracking involved.

The obvious solution would be to avoid the copy in point (2)
and replace it with a destructive update of the few integers
that need to be changed.  I have read the documentation of
setarg/3 and nb_setarg/3, and none seems to do what I want:
setarg/3 does trailing, which I don't want;
nb_setarg(+Arg, +Term, +Value) has the problem that
"[if] Term is not atomic [which is my case], it is
duplicated using duplicate_term/2", and this duplication
is precisely what I want to avoid.

Am I missing something?

Note that I am very willing to destructively modify the
term using C/C++ code (actually, this would be even better
for me).  And portability is not an issue.
Thanks a lot for any hint,

     Roberto

--
Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:bagnara@...
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

 « Return to Thread: Destructive update of terms (from foreign code)