Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
|
|
@ -0,0 +1,38 @@
|
|||
# Create an unnamed m*n array as a table with m rows, each row being a list
|
||||
create or replace function matrix(m, n, init) as table (
|
||||
with recursive row as (
|
||||
select list_transform(range(0,n), x -> z) as row
|
||||
from (select init as z)),
|
||||
cte as (
|
||||
select 1 as i, row from row
|
||||
union all
|
||||
select i+1, row
|
||||
from cte
|
||||
where i < m
|
||||
)
|
||||
from cte
|
||||
);
|
||||
|
||||
# The backing table
|
||||
create or replace table t_ (
|
||||
i INTEGER NOT NULL check(i>0), check(i<= getenv('M')::INTEGER),
|
||||
row DOUBLE[]
|
||||
);
|
||||
|
||||
# The view
|
||||
create or replace view t as from t_ order by i;
|
||||
|
||||
# Initialize the backing table
|
||||
insert into t_ from matrix( getvariable('M')::INT, getvariable('N')::INT, 0.0);
|
||||
|
||||
prepare update_matrix as /* $1=i $2=j $3=value */
|
||||
update t_
|
||||
set row = row[1:$2-1] || [$3] || row[$2+1:]
|
||||
where i = $1
|
||||
;
|
||||
|
||||
create or replace function matrix_get(ii,jj) as (
|
||||
select row[jj]
|
||||
from t
|
||||
where i = ii
|
||||
);
|
||||
|
|
@ -5,12 +5,12 @@ public program()
|
|||
var n := new Integer();
|
||||
var m := new Integer();
|
||||
|
||||
console.write("Enter two space delimited integers:");
|
||||
console.loadLine(n,m);
|
||||
Console.write("Enter two space delimited integers:");
|
||||
Console.loadLine(n,m);
|
||||
|
||||
var myArray := class Matrix<int>.allocate(n,m);
|
||||
|
||||
myArray.setAt(0,0,2);
|
||||
|
||||
console.printLine(myArray.at(0, 0))
|
||||
Console.printLine(myArray.at(0, 0))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ public program()
|
|||
auto n := new Integer();
|
||||
auto m := new Integer();
|
||||
|
||||
console.write("Enter two space delimited integers:");
|
||||
console.loadLine(n,m);
|
||||
Console.write("Enter two space delimited integers:");
|
||||
Console.loadLine(n,m);
|
||||
|
||||
auto myArray2 := new object[][](n.Value).populate::(int i => (new object[](m.Value)) );
|
||||
myArray2[0][0] := 2;
|
||||
myArray2[1][0] := "Hello";
|
||||
|
||||
console.printLine(myArray2[0][0]);
|
||||
console.printLine(myArray2[1][0]);
|
||||
Console.printLine(myArray2[0][0]);
|
||||
Console.printLine(myArray2[1][0]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +1,110 @@
|
|||
/*REXX program allocates/populates/displays a two-dimensional array. */
|
||||
call bloat /*the BLOAT procedure does all allocations.*/
|
||||
/*no more array named @ at this point. */
|
||||
exit /*stick a fork in it, we're all done honey.*/
|
||||
/*─────────────────────────BLOAT subroutine─────────────────────────────*/
|
||||
bloat: procedure; say /*"PROCEDURE" makes this a ··· procedure. */
|
||||
say 'Enter two positive integers (a 2-dimensional array will be created).'
|
||||
pull n m . /*elements are allocated as they're defined*/
|
||||
/*N and M should be verified at this point.*/
|
||||
@.=' · ' /*Initial value for all @ array elements,*/
|
||||
/*this ensures every element has a value.*/
|
||||
do j =1 for n /*traipse through the first dimension [N]*/
|
||||
do k=1 for m /* " " " second " [M]*/
|
||||
if random()//7==0 then @.j.k=j'~'k /*populate every 7th random*/
|
||||
end /*k*/
|
||||
end /*j*/
|
||||
/* [↓] display array to console: row,col */
|
||||
do r=1 for n; _= /*construct one row (or line) at a time. */
|
||||
do c=1 for m /*construct row one column at a time. */
|
||||
_=_ right(@.r.c,4) /*append a nice-aligned column to the line.*/
|
||||
end /*kk*/ /* [↑] an nicely aligned line is built. */
|
||||
say _ /*display one row at a time to the terminal*/
|
||||
end /*jj*/
|
||||
/*╔════════════════════════════════════════════════════════════════════╗
|
||||
║ When the RETURN is executed (from a PROCEDURE in this case), and ║
|
||||
║ array @ is "de─allocated", that is, it's no longer defined, and ║
|
||||
║ the array's storage is now free for other REXX variables. If the ║
|
||||
║ BLOAT subroutine didn't have a "PROCEDURE" on that statement,║
|
||||
║ the array @ would've been left intact. The same effect is ║
|
||||
║ performed by a DROP statement (an example is shown below). ║
|
||||
╚════════════════════════════════════════════════════════════════════╝*/
|
||||
drop @. /*because of the PROCEDURE statement, the*/
|
||||
return /* [↑] DROP statement is superfluous. */
|
||||
-- 8 Aug 2025
|
||||
include Settings
|
||||
signal off novalue
|
||||
|
||||
say 'CREATE AN TWO-DIMENSIONAL ARRAY AT RUNTIME'
|
||||
say version
|
||||
say
|
||||
call CreateMult
|
||||
call ShowMult 'Global'
|
||||
call CreateAddi
|
||||
call ShowAddi 'Global'
|
||||
call CreateSubt
|
||||
call ShowSubt 'Global'
|
||||
exit
|
||||
|
||||
CreateMult:
|
||||
procedure expose Mult.
|
||||
arg xx
|
||||
do i = 1 to 9
|
||||
do j = 1 to 9
|
||||
Mult.i.j=i*j
|
||||
end
|
||||
end
|
||||
return
|
||||
|
||||
ShowMult:
|
||||
parse arg xx
|
||||
say ' 'xx 'multiplication table'
|
||||
say ' 'Copies('-',25)
|
||||
say ' 1 2 3 4 5 6 7 8 9'
|
||||
say ' 'Copies('-',25)
|
||||
do i = 1 to 9
|
||||
call CharOut ,i
|
||||
do j = 1 to 9
|
||||
call CharOut ,Right(Mult.i.j,3)
|
||||
end
|
||||
say
|
||||
end
|
||||
say ' 'Copies('-',25)
|
||||
say
|
||||
return
|
||||
|
||||
CreateAddi:
|
||||
procedure
|
||||
do i = 1 to 9
|
||||
do j = 1 to 9
|
||||
Addi.i.j=i+j
|
||||
end
|
||||
end
|
||||
call ShowAddi 'Local'
|
||||
return
|
||||
|
||||
ShowAddi:
|
||||
parse arg xx
|
||||
say ' 'xx 'addition table'
|
||||
say ' 'Copies('-',25)
|
||||
say ' 1 2 3 4 5 6 7 8 9'
|
||||
say ' 'Copies('-',25)
|
||||
if DataType(Addi.1.1) = 'CHAR' then do
|
||||
call CharOut ,' 'Addi.1.1 Addi.2. Addi.3.3'...'
|
||||
say
|
||||
end
|
||||
else do
|
||||
do i = 1 to 9
|
||||
call CharOut ,i
|
||||
do j = 1 to 9
|
||||
call CharOut ,Right(Addi.i.j,3)
|
||||
end
|
||||
say
|
||||
end
|
||||
end
|
||||
say ' 'Copies('-',25)
|
||||
say
|
||||
return
|
||||
|
||||
CreateSubt:
|
||||
procedure expose Subt.
|
||||
do i = 1 to 9
|
||||
do j = 1 to 9
|
||||
Subt.i.j=i-j
|
||||
end
|
||||
end
|
||||
call ShowSubt 'Global'
|
||||
drop Subt.
|
||||
return
|
||||
|
||||
ShowSubt:
|
||||
parse arg xx
|
||||
say ' 'xx 'subtraction table'
|
||||
say ' 'Copies('-',25)
|
||||
say ' 1 2 3 4 5 6 7 8 9'
|
||||
say ' 'Copies('-',25)
|
||||
if DataType(Subt.1.1) = 'CHAR' then do
|
||||
call CharOut ,' 'Subt.1.1 Subt.2. Subt.3.3'...'
|
||||
say
|
||||
end
|
||||
else do
|
||||
do i = 1 to 9
|
||||
call CharOut ,i
|
||||
do j = 1 to 9
|
||||
call CharOut ,Right(Subt.i.j,3)
|
||||
end
|
||||
say
|
||||
end
|
||||
end
|
||||
say ' 'Copies('-',25)
|
||||
say
|
||||
return
|
||||
|
||||
include Abend
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
tpl =: 'one' -> 1, 2 -> 'two'
|
||||
map =: tuple tpl as map \ 'map' is not a keyword
|
||||
print join map map as pairs \ converts to row, then joins values
|
||||
Loading…
Add table
Add a link
Reference in a new issue