Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,45 @@
import util.
go =>
% Create an array of length 10
Len = 10,
A = new_array(Len),
bind_vars(A,0), % Initialize all values to 0
println(a=A),
A[1] := 1, % Assign a value
println(a=A),
println(a1=A[1]), % print first element
% (re)assign a value
foreach(I in 1..Len) A[I] := I end,
println(A[3..7]), % print some interval of an array
nl,
% 2D arrays
A2 = new_array(4,4),
foreach(I in 1..4, J in 1..4)
A2[I,J] := (I-1)*4+J
end,
foreach(Row in A2) println(Row) end,
% These functions are defined in the util module.
% They returns lists so we have to convert them to arrays.
println('rows '=to_array(A2.rows)),
println('columns '=A2.columns.to_array),
println(diagonal1=A2.diagonal1.to_array),
println(diagonal2=A2.diagonal2.to_array),
nl,
% Pushing values to an array
A3 = {}, % an empty array
foreach(I in 1..4)
A3 := A3 ++ {10**I+I}
end,
println(a3=A3),
nl,
% Some misc functions
println([first=A3.first(), second=A3.second(),last=A3.last()]),
nl.

View file

@ -0,0 +1,13 @@
listvariant :-
List = new_list(5), % create a list of length 5
nth(1,List,a), % put an a at position 1 , nth/3 uses indexing from 1
nth(4,List,b), % put an b at position 4
println(list=List),
append(List,[d],List2), % append an d at the end , List2 has 5 elements
println(list2=List2),
Add = new_list(5), % create a new list of length 5
append(List2,Add,List3), % append 5 free variables to List2
println(len=List3.len), % List3 now has 11 elements
println(list3=List3),
Value = List3[1], % get the value at position 1
println(value=Value). % will print out a