Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,14 @@
Module Arr {
\\ array as tuple
A=(1,2,3,4,5)
Print Array(A,0)=1
Print A
\\ add two arrays
A=Cons(A, (6,))
Print Len(A)=6
Print A
\\ arrays may have arrays, inventories, stacks as items
A=((1,2,3),(4,5,6))
Print Array(Array(A, 0),2)=3
}
Arr

View file

@ -0,0 +1,36 @@
Module CheckStack {
\\ ordered collection: Stack
\\ we can add values to top or bottom,
\\ we can move values to and from top
A=Stack:=100,300,600,800,900
Print StackItem(A, 2)=300, Len(A)=5
Stack A {
\\ push to bottom (or end)
Data 2000, 4000
}
Print StackItem(A, 7)=4000, Len(A)=7
Stack A {
\\ pop from top
Read X, Y
Print X=100, Y=300
}
Print StackItem(A,5)=4000, Len(A)=5
Stack A {
\\ push to top
Push 2, 1
Stack ' display stack items
}
\\ we can make a new stack merging other stacks
A=Stack(A, stack:=5000,6000,7000)
Print Len(A)=10
Stack A {
Shift 1,-Len(A) ' Reverse order
Stack ' Display
}
Stack A {Drop 8}
Print Len(A)=2
Flush ' empty current stack
Stack A ' dump A to current stack
Print Stack.Size=2, Len(A)=0
}
CheckStack

View file

@ -0,0 +1,28 @@
Module Maps {
\\ Inventory as pairs of keys/values
\\ keys has to be unique
\\ Empty string "" can be used as key
\\ Search, Add and Delete in O(1)
\\ if we use delete we lost the order
\\ keys can be numbers or strings, either can exist in same inventory. Values can be anything (including objects)
\\ 0 can be used for string
\\ Keys must be unique
\\ a variable which hold an inventory is a pointer type
Inventory A=10:="A",20:="B",40:="C"
Print A$(10)="A", A$("20")="B"
\\ split search from retrieval, using key one time
If Exist(A,40) Then Print Eval$(A)="C"
k=Each(A)
While k {
\\ print keys as strings and values
Print Eval$(k, k^), Eval$(k)
}
\\ We can use Sort to sort as numbers or text
Append A, 5:="First"
Sort A as number
\\ Print can print an inventory using columns
Print A ' First A B C
Sort A as text
Print A ' A B C First
}
Maps

View file

@ -0,0 +1,31 @@
Module Sets {
\\ Inventory as set of keys
\\ keys has to be unique
\\ Empty string "" can be used as key
\\ Search, Add and Delete in O(1)
\\ if we use delete we lost the order
\\ keys can be numbers or strings, either can exist in same inventory
\\ 0 can be used for string
\\ Keys must be unique
\\ a variable which hold an inventory is a pointer type
Inventory A=10,20,40
If Exist(A,20) Then Print Eval(A)=20
k=Each(A)
While k {
\\ print keys as strings and value same as key (as number here)
Print Eval$(k, k^), Eval(k)
}
\\ sort is a Quick sort
Sort Descending A as number
Print A ' 40 20 10
\\ For no unique keys
\\ we can't delete from anywhere.
\\ we can drop some keys from the end only
\\ Exist() move internal index to last of the same key
\\ we can give values also (make it as Map)
Inventory Queue B=1,1,1,2,2,6,10
Drop B 3
Print B ' prints 1 1 1 2
\\ sort is an insertion sort (stable)
}
Sets

View file

@ -0,0 +1,50 @@
Module GetC {
declare c collection
def decimal aDecimal=3000032131231231312312
Document doc$
Print type$(c)
\\ we get an inventory list of all methods/properties of a com Object
m=param(c)
IF LEN(m)>1 THEN {
For i=0 to len(m)-1
\\ use index, not key so i! is index
Doc$=m$(i!)+{
} ' we use this block for new line
Next i
}
Report Doc$
Clipboard Doc$
\\ so now we have to use it, using Methid to call Add
Method c, "Add", 100, "Hello"
Method c, "Add", 2000, "There"
\\ add a decimal number
Method c, "Add", aDecimal, "Zero"
Method c, "count" as count
Print count =3 ' we have three members
Method C, "_NewEnum" as Item
Method c, "Item", "Zero" as ZeroItem ' we get the decimal number
Print ZeroItem
Print type$(Item)="Nothing" ' we have numbers
k=0
While Item {
k++
print k, eval(item)
}
c.item=lambda c (akey$) ->{
try ok {
method c, "item", akey$ as ret
}
If type$(Ret)="Empty" Then Error "Key not used"
=ret
}
Print c.item("Hello")
Try {
val=c.item("Hello12")
}
Print Error$
Push c
}
GetC
Read a
Print type$(a)="Collection" ' if we don't declare