Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,17 @@
package Shapes is
type Point is tagged private;
procedure Print(Item : in Point);
function Setx(Item : in Point; Val : Integer) return Point;
function Sety(Item : in Point; Val : Integer) return Point;
function Getx(Item : in Point) return Integer;
function Gety(Item : in Point) return Integer;
function Create return Point;
function Create(X : Integer) return Point;
function Create(X, Y : Integer) return Point;
private
type Point is tagged record
X : Integer := 0;
Y : Integer := 0;
end record;
end Shapes;

View file

@ -0,0 +1,77 @@
with Ada.Text_Io; use Ada.Text_Io;
package body Shapes is
-----------
-- Print --
-----------
procedure Print (Item : in Point) is
begin
Put_line("Point");
end Print;
----------
-- Setx --
----------
function Setx (Item : in Point; Val : Integer) return Point is
begin
return (Val, Item.Y);
end Setx;
----------
-- Sety --
----------
function Sety (Item : in Point; Val : Integer) return Point is
begin
return (Item.X, Val);
end Sety;
----------
-- Getx --
----------
function Getx (Item : in Point) return Integer is
begin
return Item.X;
end Getx;
----------
-- Gety --
----------
function Gety (Item : in Point) return Integer is
begin
return Item.Y;
end Gety;
------------
-- Create --
------------
function Create return Point is
begin
return (0, 0);
end Create;
------------
-- Create --
------------
function Create (X : Integer) return Point is
begin
return (X, 0);
end Create;
------------
-- Create --
------------
function Create (X, Y : Integer) return Point is
begin
return (X, Y);
end Create;
end Shapes;

View file

@ -0,0 +1,18 @@
package Shapes.Circles is
type Circle is new Point with private;
procedure Print(Item : Circle);
function Setx(Item : Circle; Val : Integer) return Circle;
function Sety(Item : Circle; Val : Integer) return Circle;
function Setr(Item : Circle; Val : Integer) return Circle;
function Getr(Item : Circle) return Integer;
function Create(P : Point) return Circle;
function Create(P : Point; R : Integer) return Circle;
function Create(X : Integer) return Circle;
function Create(X : Integer; Y : Integer) return Circle;
function Create(X : Integer; Y : Integer; R : Integer) return Circle;
function Create return Circle;
private
type Circle is new Point with record
R : Integer := 0;
end record;
end Shapes.Circles;

View file

@ -0,0 +1,106 @@
with Ada.Text_Io; use Ada.Text_IO;
package body Shapes.Circles is
-----------
-- Print --
-----------
procedure Print (Item : Circle) is
begin
Put_line("Circle");
end Print;
----------
-- Setx --
----------
function Setx (Item : Circle; Val : Integer) return Circle is
begin
return (Val, Item.Y, Item.R);
end Setx;
----------
-- Sety --
----------
function Sety (Item : Circle; Val : Integer) return Circle is
Temp : Circle := Item;
begin
Temp.Y := Val;
return Temp;
end Sety;
----------
-- Setr --
----------
function Setr (Item : Circle; Val : Integer) return Circle is
begin
return (Item.X, Item.Y, Val);
end Setr;
----------
-- Getr --
----------
function Getr (Item : Circle) return Integer is
begin
return Item.R;
end Getr;
------------
-- Create --
------------
function Create (P : Point) return Circle is
begin
return (P.X, P.Y, 0);
end Create;
------------
-- Create --
------------
function Create (P : Point; R : Integer) return Circle is
begin
return (P.X, P.Y, R);
end Create;
------------
-- Create --
------------
function Create (X : Integer) return Circle is
begin
return (X, 0, 0);
end Create;
------------
-- Create --
------------
function Create (X : Integer; Y : Integer) return Circle is
begin
return (X, Y, 0);
end Create;
------------
-- Create --
------------
function Create (X : Integer; Y : Integer; R : Integer) return Circle is
begin
return (X, Y, R);
end Create;
------------
-- Create --
------------
function Create return Circle is
begin
return (0, 0, 0);
end Create;
end Shapes.Circles;

View file

@ -0,0 +1,10 @@
with Shapes.Circles; use Shapes.Circles;
use Shapes;
procedure Shapes_Main is
P : Point;
C : Circle;
begin
P.Print;
C.Print;
end Shapes_Main;

View file

@ -0,0 +1,119 @@
struct Point {
mut:
x f64
y f64
}
struct Circle {
mut:
x f64
y f64
r f64
}
// interface definition
interface Printer {
print()
}
// point methods
fn (p &Point) print() {
println('$p.x $p.y')
}
fn (p &Point) get_x() f64 {
return p.x
}
fn (mut p Point) set_x(v f64) {
p.x = v
}
fn (p &Point) get_y() f64 {
return p.y
}
fn (mut p Point) set_y(v f64) {
p.y = v
}
fn (p &Point) clone() &Point {
return &Point{
x: p.x
y: p.y
}
}
fn (mut p Point) set(q &Point) {
p.x = q.x
p.y = q.y
}
// circle methods
fn (c &Circle) print() {
println('$c.x $c.y $c.r')
}
fn (c &Circle) get_x() f64 {
return c.x
}
fn (mut c Circle) set_x(v f64) {
c.x = v
}
fn (c &Circle) get_y() f64 {
return c.y
}
fn (mut c Circle) set_y(v f64) {
c.y = v
}
fn (c &Circle) get_r() f64 {
return c.r
}
fn (mut c Circle) set_r(v f64) {
c.r = v
}
fn (c &Circle) clone() &Circle {
return &Circle{
x: c.x
y: c.y
r: c.r
}
}
fn (mut c Circle) set(d &Circle) {
c.x = d.x
c.y = d.y
c.r = d.r
}
// "constructors" are idiomatic if involving something more than just assigning initial values
// in V, by default, structs have default values relative to their type
fn new_point(x f64, y f64) &Point {
return &Point{
x: x
y: y
}
}
fn new_circle(x f64, y f64, r f64) &Circle {
return &Circle{
x: x
y: y
r: r
}
}
// a type of polymorphism: both types implement the printer interface
// print function can be called through a variable without knowing the underlying type
fn main() {
mut i := Printer(new_point(3, 4)) // polymorphic variable + assign one type
i.print() // call polymorphic function
i = Printer(new_circle(5, 12, 13)) // assign different type to same variable
i.print() // same call accesses different method now
}