Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -1,6 +0,0 @@
\\ block For This {}, or For object [, object2] { }, where object is a group, or a pointer to group, or an item from an array contains a group
\\ This is "this context".
For This {
\\ any new definition here has a temporary use
\\ can be nested, but if we use object then we can use dots to access members of it. If we use a second one then we have to use double dots (..x for second object, for access to x member)
}

View file

@ -1,76 +0,0 @@
Class PointA {
Property x=0~
Property Y=0~
Operator "=" (n1) {
n=group(n1)
if n.x=.x Then if n.y=.y then push true : exit
push false
}
Module Print {
Print "Point" , .x, .y
}
Class:
Module PointA {
\\ ? means optionally
Read ? .[x], .[y]
}
}
Class Circle {
Property R=300~ ' type single
Operator "=" (n1) {
n=group(n1)
n2=This ' get a copy of this to check n against n2
if valid(@n as n2) else push false :exit
if n.x=.x Then if n.y=.y then if n.r=.r then push true : exit
push false
}
Module Print {
Print "Circle", .x, .y, .r
}
Class:
Module Circle {
if match("nn") then {
M=PointA(Number, Number)
} Else.if match("G") then {
M=PointA()
Read M
} Else M=PointA()
M=This
\\ If match("N") then Read M.r \\ check if a number is in top of stack
\\ Read ? M.r \\ optionally
Read M.r \\ for this example, r has value, so this used if stack is empty.
This=M
}
}
A=PointA(10,3)
C=Circle(20,10,5)
D=Circle(A, 100)
B=A
K=PointA()
Z=Circle(A)
P=PointA(600,700)
\\ N is a pointer to array
N=(A, B, C, D, K, P, Z)
M=each(N)
While M {
For This {
\\ a copy in MM
MM=Array(M)
MM.Print
Print A=MM, D=MM ' using MM=A interpreter use "=" from MM
}
}
\\ pA is a pointer to D (a named group)
pA->D
Print pA=D, pA=Z
pA=>Print
\\ pA is a pointer to a copy of D (a float group)
pA->(D)
Print pA=D, pA=Z
pA=>Print
\\ rA is a reference to D (& is optional in Link statement)
Link &D to &rA
rA.Print

View file

@ -1,67 +0,0 @@
Class PointA {
X=0~, Y=0~
Module Print {
Print "Point" , .x, .y
}
Class:
Module PointA {
Read ? .x, .y
}
}
Class Circle {
Property R {
Value,
Set {
If Value>1000 then Value=1000
}
}=300~
Module Print {
Print "Circle", .x, .y, .r
}
Class:
Module Circle {
if match("nn") then {
M=PointA(Number, Number)
} Else.if match("G") then {
M=PointA()
Read M
} Else M=PointA()
M=This
This=M
Read ? .r
}
}
A=PointA(10,3)
C=Circle(20,10,5)
D=Circle(A, 100)
B=A
K=PointA()
Z=Circle(A)
P=PointA(600,700)
\\ N is a pointer to stack
N=Stack:=A, B, C, D, K, P, Z
\\ M is a pointer to an iterator
M=each(N)
While M {
For This {
\\ a copy in MM
MM=StackItem(M)
MM.Print
}
}
\\ NN is a pointer to Inventory
Inventory NN= 1:=A, 2:=B, 3:=C, 4:=D, 5:=K, 6:=P,7:= Z
M=each(NN)
While M {
For This {
\\ a copy in MM
MM=Eval(M)
MM.Print
}
}
\\ we can call NN(3).print
Print "NN(3).Print"
NN(3).Print
NN(3).R=5000
NN(3).Print

View file

@ -0,0 +1,108 @@
Module Polymorphism {
Class Point {
private:
double x, y
public:
module print {
Print "x="+.x, "y="+.y
}
class:
module Point (.x, .y) {
}
}
Class Circle as Point {
private:
double r
public:
group radius {
value {
link parent r to r
=r
}
Set {
Error "No Set for radius"
}
}
module print {
Print "x="+.x, "y="+.y, "r="+.r
}
class:
module Circle (.x, .y, .r) {
}
}
Class Circle2{
{ ' a different constructor - Version 14
read xa=0, ya=0, ra=0
if ra=0 then ra=1
}
public:
Property r {
value, ' we can read it
set { ' we can change if is >0
if value<=0 then exit ' skip
}
}=ra
Point Inner(xa, ya)
// add a function to Inner to read private X and Y
Group Inner {
function readXY {
=.x, .y
}
}
Group CircleType { ' an inner object which return a value of type circle
Value { ' return a Circle type
link parent Inner to that
link parent r to ra
=Circle(!that.readXY(), ra)
}
}
module print {
(x,y)=.inner.readXY()
Print "x="+x, "y="+y, "r="+.r
}
}
A=Point(10, 20)
B=Circle(2,3,5)
doit(A)
doit(B)
print B is type Point = true
print B is type Circle = true
C=Circle2(12,13,15)
C.r=0
Print "C radius = ";C.r
print C is type Circle2 = true
doit(C.CircleType)
// Circle2 has a Point object
doit(C.Inner)
D=C.CircleType
print "D radious = ";d.radius
try {
d.radius=100
}
print error$
print D is type Point = true
print D is type Circle = true
print D is type Circle2 = false
doit(D)
doit2(&D)
doit3(pointer(D)) ' we pass a weak reference - pointer((D)) is a real pointer of a copy of D
Z->Point(10, 20) ' same as Z=Pointer(Point(10,20)), it is a real pointer
doit4(&Z)
End
sub doit(a as Point) ' pass by value
a.print
end sub
sub doit2(&a as Point) ' pass by reference
a.print
end sub
sub doit3(a as *Point) ' pass by value a pointer (weak reference or real pointer)
a=>print
end sub
sub doit4(&a as *Point) ' pass by reference a pointer (weak reference or real pointer)
a=>print
end sub
}
Polymorphism

View file

@ -0,0 +1,11 @@
#lang rhombus/static
class Point(~x = 0, ~y = 0):
nonfinal
method print():
println(@str{Point at @(x),@(y)})
class Circle(~r = 1):
extends Point
override method print():
println(@str{Circle at @(x),@(y) with radius @(r)})

View file

@ -0,0 +1,13 @@
def p = Point()
p.print() // Point at 0,0
println(p.x) // 0
def p2 = Point(~y: 1)
p2.print() // Point at 0,1
def c = Circle(~y: 3, ~r: 2)
c.print() // Circle at 0,3 with radius 2
println(c.r) // 2
def c2 = Circle(~y: 5)
c2.print() // Circle at 0,5 with radius 5