Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -1,24 +1,96 @@
BEGIN # example 2 #
MODE ENUM = [0]CHAR; # something with minimal size #
MODE APPLE = STRUCT(ENUM apple), BANANA = STRUCT(ENUM banana), CHERRY = STRUCT(ENUM cherry);
MODE FRUIT = UNION(APPLE, BANANA, CHERRY);
MODE ENUM = SHORT SHORT INT; # something with minimal size #
MODE ASSAM = STRUCT(ENUM assam),
BREADFRUIT = STRUCT(ENUM breadfruit),
CAYENNE = STRUCT(ENUM cayenne),
DEKOPON = STRUCT(ENUM dekopon),
EGGFRUIT = STRUCT(ENUM eggfruit),
FEIJOA = STRUCT(ENUM feijoa),
GOOSEBERRY = STRUCT(ENUM gooseberry),
HUCKLEBERRY = STRUCT(ENUM huckleberry),
INKYCAP = STRUCT(ENUM inkycap, STRING warning), # !! #
JICAMA = STRUCT(ENUM jicama);
MODE ANFOOD = UNION(ASSAM, EGGFRUIT, INKYCAP);
MODE AFOOD = UNION(BREADFRUIT, CAYENNE, DEKOPON, FEIJOA, GOOSEBERRY, HUCKLEBERRY, JICAMA);
# MODE FRUIT = UNION(ASSAM, BREADFRUIT, CAYENNE, DEKOPON, EGGFRUIT, FEIJOA, GOOSEBERRY, HUCKLEBERRY, JICAMA); #
MODE SAVORY = UNION(BREADFRUIT, CAYENNE, JICAMA, INKYCAP);
MODE FOOD = UNION(AFOOD, ANFOOD);
OP REPR = (FRUIT f)STRING:
CASE f IN
(APPLE):"Apple",
(BANANA):"Banana",
(CHERRY):"Cherry"
OP REPR = (FOOD in food)STRING:
CASE in food IN
(ASSAM a):"Assam",
(BREADFRUIT b):"Breadfruit",
(CAYENNE c):"Cayenne",
(DEKOPON d):"Dekopon",
(EGGFRUIT e):"Eggfruit",
(FEIJOA f):"Feijoa",
(GOOSEBERRY g):"Gooseberry",
(HUCKLEBERRY h):"Huckleberry ",
(INKYCAP i):"Inkycap: "+warning OF i,
(JICAMA j):"Jicama"
OUT
"?" # uninitalised #
ESAC;
OP COLOR = (FOOD in food)STRING:
CASE in food IN
(ASSAM a):"black",
(BREADFRUIT b):"brown",
(CAYENNE c):"red",
(DEKOPON d):"orange",
(EGGFRUIT e):"yellow",
(FEIJOA f):"green",
(GOOSEBERRY g):"blue",
(HUCKLEBERRY h):"violet",
(INKYCAP i):"gray",
(JICAMA j):"white"
OUT
"?" # uninitalised #
ESAC;
OP ABS = (FOOD in food)INT:
CASE in food IN
(ASSAM a): 0,
(BREADFRUIT b): 1,
(CAYENNE c): 2,
(DEKOPON d): 3,
(EGGFRUIT e): 4,
(FEIJOA f): 5,
(GOOSEBERRY g): 6,
(HUCKLEBERRY h): 7,
(INKYCAP i): 8,
(JICAMA j): 9
ESAC;
INKYCAP inkycap := (8,"An edible (although poisonous when combined with alcohol) mushroom!");
FOOD food := inkycap;
CASE food IN # in a conformity-clause #
(ANFOOD):print(("It is an ",REPR food, ".", new line)),
(AFOOD):print(("It is a ",REPR food, ".", new line))
OUT
"?" # uninitalised #
SKIP # uninitialised FOOD #
ESAC;
FRUIT x := LOC CHERRY;
CASE food IN # in a conformity-clause #
(SAVORY):print((REPR food," is ", COLOR food,"(",whole(ABS food,-1),") and savoury.", new line))
OUT
SKIP
ESAC;
# output only, food in a conformity-clause format-frame #
printf(($"Food: "f(food|
(ASSAM a):$"assam"$,
(BREADFRUIT b):$"breadfruit"$,
(CAYENNE c):$"cayenne"$,
(DEKOPON d):$"dekopon"$,
(EGGFRUIT e):$"eggfruit"$,
(FEIJOA f):$"feijoa"$,
(GOOSEBERRY g):$"gooseberry"$,
(HUCKLEBERRY h):$"huckleberry"$,
(INKYCAP i):$"inkycap"$,
(JICAMA j):$"jicama"$
|$"?"$)l$))
CASE x IN
(APPLE):print(("It is an ",REPR x, new line)),
(BANANA):print(("It is a ",REPR x, new line)),
(CHERRY):print(("It is a ",REPR x, new line))
OUT
SKIP # uninitialised FRUIT #
ESAC
END

View file

@ -0,0 +1,2 @@
APPLE = 1 : BANANA = 2 : CHERRY = 4
? APPLE, BANANA, CHERRY

View file

@ -0,0 +1,9 @@
REM "In software, everything is possible but nothing is free." --Ryan Singer
0 ENUM$ = CHR$ (165) + CHR$ (157) + CHR$ (168) + CHR$ (240) + CHR$ (9) + CHR$ (164) + CHR$ (236) + CHR$ (166) + CHR$ (237) + CHR$ (200) + CHR$ (208) + CHR$ (1) + CHR$ (232) + CHR$ (138) + CHR$ (132) + CHR$ (236)
1 ENUM$ = ENUM$ + CHR$ (133) + CHR$ (237) + CHR$ (76) + CHR$ (242) + CHR$ (226): POKE 11, PEEK (131): POKE 12, PEEK (132):ENUM = PEEK (11) + PEEK (12) * 256: POKE 11, PEEK (ENUM + 1): POKE 12, PEEK (ENUM + 2)
2 DEF FN ENUM(INC) = USR (INC)
RUN
APPLE = FN ENUM(0) : BANANA = FN ENUM(1) : CHERRY = FN ENUM(1)
? APPLE, BANANA, CHERRY

View file

@ -0,0 +1,40 @@
enum Color as u8 {
red
green
blue
}
// Reserved keywords may be escaped with an @.
enum Colors {
@none
red
green
blue
}
// Enums can be given explict integer values and converted into a string
enum Grocery {
apple
orange = 5
pear
}
// Enums can have methods, just like structs
enum Cycle {
one
two
three
}
fn (c Cycle) next() Cycle {
match c {
.one {
return .two
}
.two {
return .three
}
.three {
return .one
}
}
}

View file

@ -0,0 +1,9 @@
mut color := Color.red
// V knows that `color` is a `Color`.
color = .green
println(color) // "green"
match color {
.red {println("the color was red")}
.green {println("the color was green")}
.blue {println("the color was blue")}
}

View file

@ -0,0 +1,2 @@
colors := Colors.@none
println(colors)

View file

@ -0,0 +1,4 @@
g1 := int(Grocery.apple)
g2 := int(Grocery.orange)
g3 := int(Grocery.pear)
println('Grocery IDs: ${g1}, ${g2}, ${g3}')

View file

@ -0,0 +1,6 @@
// Enums can have methods
mut c := Cycle.one
for _ in 0 .. 5 {
println(c)
c = c.next()
}

View file

@ -0,0 +1,4 @@
// Enum values can be converted into string
println(Grocery.from(10) or {Grocery.pear})
println(Grocery.from("orange")!)
println(Grocery.apple.str())