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,4 @@
type Point is tagged record
X : Integer := 0;
Y : Integer := 0;
end record;

View file

@ -0,0 +1,4 @@
type Point is record
X : Integer := 0;
Y : Integer := 0;
end record;

View file

@ -0,0 +1,11 @@
type Person (Gender : Gender_Type) is record
Name : Name_String;
Age : Natural;
Weight : Float;
Case Gender is
when Male =>
Beard_Length : Float;
when Female =>
null;
end case;
end record;

View file

@ -0,0 +1,5 @@
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Point.
05 x USAGE IS BINARY-SHORT.
05 y USAGE IS BINARY-SHORT.

View file

@ -0,0 +1,24 @@
include "cowgol.coh";
# Definition of a record
record Point is
x: uint32;
y: uint32;
end record;
# Limitation: record types cannot be passed as arguments directly,
# only pointers can be passed
sub print_point(p: [Point]) is
print_i32(p.x); # ... but they don't need to be explicitly dereferenced
print(", ");
print_i32(p.y);
print_nl();
end sub;
# Initialization
var point: Point := {2, 3};
print_point(&point); # prints 2, 3
# Fields are mutable
point.x := 5;
print_point(&point); # now prints 5, 3

View file

@ -0,0 +1,18 @@
/* definition */
type Point = struct {
int x;
int y;
};
/* usage */
proc main() void:
/* initialization */
Point p = (2, 3);
/* fields are accessed using '.' syntax */
writeln(p.x, ", ", p.y); /* prints 2, 3 */
/* fields can be assigned */
p.x := 5;
writeln(p.x, ", ", p.y); /* now prints 5, 3 */
corp

View file

@ -0,0 +1,11 @@
enum x, y
sequence point = {0,0}
printf(1,"x = %d, y = %3.3f\n",point)
point[x] = 'A'
point[y] = 53.42
printf(1,"x = %d, y = %3.3f\n",point)
printf(1,"x = %s, y = %3.3f\n",point)

View file

@ -0,0 +1,27 @@
import gleam/float
import gleam/int
import gleam/io
// In Gleam, a type with one variant which has the same
// name as the type is called a "compound", "record" or
// a "product" type.
// Given a record, it's fields can either be accessed via the dot (.) operator
// or pattern matched.
pub type Point(a) {
Point(x: a, y: a)
}
pub fn point_to_string(p: Point(a), to_string: fn(a) -> String) -> String {
// Example of pattern matching records:
let Point(x, y) = p
"Point{x = " <> x |> to_string <> ", y = " <> y |> to_string <> "}"
// We can also use the . operator:
// "Point{x = " <> p.x |> to_string <> ", y = " <> p.y |> to_string <> "}"
}
pub fn main() {
let p1: Point(Int) = Point(10, 5)
let p2: Point(Float) = Point(10.0, 5.0)
io.println(point_to_string(p1, int.to_string))
io.println(point_to_string(p2, float.to_string))
}

View file

@ -0,0 +1,14 @@
HAI 1.3
O HAI IM point
I HAS A X ITZ A NUMBAR
I HAS A Y ITZ A NUMBAR
KTHX
I HAS A mypoint ITZ LIEK A point
mypoint'Z X R 1.1
mypoint'Z Y R 3.14
VISIBLE mypoint'Z X ", " mypoint'Z Y
KTHXBYE

View file

@ -0,0 +1,13 @@
class point
function __construct(public x, public y) end
function __tostring() return $"({self.x}, {self.y})" end
end
local p = new point(1, 2)
print(p)
-- Mutate point object.
p.x = 2
p.y = 3
print(p)

View file

@ -0,0 +1,18 @@
class Point {
[Int]$a
[Int]$b
Point() {
$this.a = 0
$this.b = 0
}
Point([Int]$a, [Int]$b) {
$this.a = $a
$this.b = $b
}
[Int]add() {return $this.a + $this.b}
[Int]mul() {return $this.a * $this.b}
}
$p1 = [Point]::new()
$p2 = [Point]::new(3,2)
$p1.add()
$p2.mul()