For Programmers: Free Programming Magazines  


Home > Archive > Prolog > February 2006 > Changing list items in Prolog









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Changing list items in Prolog
twoflower

2006-02-25, 4:42 am

Hi,

let's have list of some terms, eg. vertex(Id, Height, Excess). I'd like to able to change of the 'attributes' of some vertex in the list, for example:

PHP:

do_something
(Height,VertexList) :- member(vertex(IdHeightExcess), VertexList), % I suppose this runs in O(N), how to change that?
                                     % and 
now I'd like to change 'Excess' of this vertex



Primitive way how to do it would be to write a predicate which would take the original array and either just copy the vertexes into new array or copy changed vertex to the new array if it is the vertex I want to change. But this takes O(N) time, which is too much...

Is there any approach?

Thank you very much.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com