|
|
GVarName | ::= | atom | whole content of a variable |
atom(Integer,...,Integer) | element of an array | ||
GVarName-Integer | sub-term selection | ||
Integer | ::= | integer | immediate value |
GVarName | indirect value |
a | the content of variable associated to a (any kind) |
t(1) | the 2nd element of the array associated to t |
t(k) | if the value associated to k is I, the Ith element of the array associated to t |
a-1-2 | if the value associated to a is f(g(a,b,c),2), the sub-term b |
GVarName is a variable | instantiation_error | ||
GVarName is neither a variable nor a callable term | type_error(callable, GVarName) | ||
GVarName contains an invalid argument number (or GVarName is an array) | domain_error(g_argument_selector, GVarName) | ||
GVarName contains an invalid index (or GVarName is not an array) | domain_error(g_array_index, GVarName) | ||
GVarName is used as an indirect index or argument selector and is not an integer | type_error(integer, GVarName) | ||
|
GVarName contains an argument selector and the assignment is backtrackable | domain_error(g_argument_selector, GVarName) | ||
|
|
Size is neither a variable nor an integer | type_error(integer, Size) | ||
|
Old is neither a variable nor an integer | type_error(integer, Old) | ||
New is neither a variable nor an integer | type_error(integer, New) | ||
GVarName stores an array | type_error(integer, g_array) | ||
GVarName stores a term T which is not an integer | type_error(integer, T) | ||
|
Bit is a variable | instantiation_error | ||
Bit is neither a variable nor an integer | type_error(integer, Bit) | ||
Bit is an integer < 0 | domain_error(not_less_than_zero, Bit) | ||
GVarName stores an array | type_error(integer, g_array) | ||
GVarName stores a term T which is not an integer | type_error(integer, T) | ||
|
my_g_inc(Var, Old, New) :- g_read(Var, Old), N is Value + 1, g_assign(Var, X), New = N.
test(Old) :- | testb(Old) :- | |
g_assign(x,1), | g_assign(x,1), | |
( g_read(x, Old), | ( g_read(x, Old), | |
g_assign(x, 2) | g_assignb(x, 2) | |
; g_read(x, Old), | ; g_read(x, Old), | |
g_assign(x, 3) | g_assign(x, 3) | |
). | ). |
test(B) :- | test(B) :- | |
g_assign(b, f(X)), | g_link(b, f(X)), | |
X = 12, | X = 12, | |
g_read(b, B). | g_read(b, B). |
| ?- g_assign(w, g_array(3)), g_read(w, X). X = g_array([0,0,0]) | ?- g_assign(w(0), 16), g_assign(w(1), 32), g_assign(w(2), 64), g_read(w, X). X = g_array([16,32,64])
| ?- g_assign(k, g_array([16,32,64])), g_read(k, X). X = g_array([16,32,64]) | ?- g_assign(k, g_array(3,null)), g_read(k, X), g_array_size(k, S). S = 3 X = g_array([null,null,null])
| ?- g_assign(w, g_array(2, g_array(3))), g_read(w, X). X = g_array([g_array([0,0,0]),g_array([0,0,0])]) | ?- ( for(I,0,1), for(J,0,2), K is I*3+J, g_assign(w(I,J), K), fail ; g_read(w, X) ). X = g_array([g_array([0,1,2]),g_array([3,4,5])]) | ?- g_read(w(1),X). X = g_array([3,4,5])
| ?- g_assign(w,g_array([1,2,g_array([a,b,c]), g_array(2,z),5])), g_read(w, X). X = g_array([1,2,g_array([a,b,c]), g_array([z,z]),5]) | ?- g_read(w(1), X), g_read(w(2,1), Y), g_read(w(3,1), Z). X = 2 Y = b Z = z | ?- g_read(w(1,2),X). uncaught exception: error(domain_error(g_array_index,w(1,2)),g_read/2)
| ?- g_assign(a, g_array([10,20,30])), g_read(a, X). X = g_array([10,20,30]) | ?- g_assign(a, g_array_extend(5,null)), g_read(a, X). X = g_array([10,20,30,null,null]) | ?- g_assign(a, g_array([10,20,30])), g_read(a, X). X = g_array([10,20,30]) | ?- g_assign(a, g_array_extend([1,2,3,4,5,6])), g_read(a, X). X = g_array([10,20,30,4,5,6])
| ?- g_assign(t, g_array_auto(3)), g_assign(t(1), foo), g_read(t,X). X = g_array([0,foo,0]) | ?- g_assign(t(5), bar), g_read(t,X). X = g_array([0,foo,0,0,0,bar,0,0]) | ?- g_assign(t, g_array_auto(2, g_array(2))), g_assign(t(1,1), foo), g_read(t,X). X = g_array([g_array([0,0]),g_array([0,foo])]) | ?- g_assign(t(3,0), bar), g_read(t,X). X = g_array([g_array([0,0]),g_array([0,foo]),g_array([0,0]),g_array([bar,0])]) | ?- g_assign(t(3,4), bar), g_read(t,X). uncaught exception: error(domain_error(g_array_index,t(3,4)),g_assign/2) | ?- g_assign(t, g_array_auto(2, g_array_auto(2))), g_assign(t(1,1), foo), g_read(t,X). X = g_array([g_array([0,0]),g_array([0,foo])]) | ?- g_assign(t(3,3), bar), g_read(t,X). X = g_array([g_array([0,0]),g_array([0,foo]),g_array([0,0]), g_array([0,0,0,bar])]) | ?- g_assign(t, g_array_auto(2, g_array_auto(2, null))), g_read(t(2,3), U), g_read(t, X). U = null X = g_array([g_array([null,null]),g_array([null,null]), g_array([null,null,null,null]),g_array([null,null])])