Since today i am full of great new ideas, here is another one i have been contemplating
Suppose we have a dynamic fact such as so, and we want to update the list to include another element, e:
:- dynamic adjacent/2.
adjacent(a, [b, c, d]).
Today one would do something like this:
update_adjacent(X, Added) :- adjacent(X, Current_List), append(Current_list, Added, New_List), retract(adjacent(X, Current_List), assert(adjacent(X, New_List).
Could one envision an dynamic_set_arg/3 operator, that takes as arguments a position and a new argument and updates the internal representation with the new argument as so:
update_adjacent(X, Added) :- adjacent(X, Current_List), append(Current_list, Added, New_List), dynamic_set_arg(2, adjacent(X, Current_List), New_List).
Would it be worthwhile – i.e. save time both in terms by needing only one operation and not two (retract/assert) and by making indexing simpler for update?
It would be in line with, say, SQL Update: