I try to initialize an array2M, but get a strange result.
Am I doiing something wrong?
Code: Select all
class facts - matrixDB
linsys : array2M{real} := erroneous.
sizeX : positive := erroneous. % 4 colums
sizeY : positive := erroneous. % 3 rows
class facts
v : (real*).
clauses
v([2, 1, -1, 8]).
v([-3, -1, 2, -11]).
v([-2, 1, 2, -3]).
clauses
solve() :-
System = [ X || v(X) ],
sizeY := list::length(System), % 3 Rows
System = [H | _],
sizeX := list::length(H), % 4 Columns
linsys := array2M::new(sizeX - 1, sizeY - 1),
stdio::write("System = ", System, "\n"),
fillArray2M(System),
stdio::write("Output = \n"),
printArray2M(),
!.
solve() :-
stdio::write("Could not initialise").
class predicates
printArray2M : ().
clauses
printArray2M() :-
foreach RowCounter = std::fromTo(0, sizeY - 1) do
foreach ColCounter = std::fromTo(0, sizeX - 1) do
Value = linsys:get(ColCounter, RowCounter),
stdio::write(Value, " ")
end foreach,
stdio::write("\n")
end foreach.
class predicates
fillArray2M : (real** System).
clauses
fillArray2M(System) :-
foreach RowCounter = std::fromTo(0, sizeY - 1) do
foreach ColCounter = std::fromTo(0, sizeX - 1) do
Row = list::nth(RowCounter, System),
Value = list::nth(ColCounter, Row),
linsys:set(ColCounter, RowCounter, Value)
end foreach
end foreach.
System = [[2,1,-1,8],[-3,-1,2,-11],[-2,1,2,-3]]
Output =
2 1 -1 -3
-3 -1 2 -2
-2 1 2 -3
I am using VIP904 (32bit)
Kind regards
Ben