Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
from: http://rosettacode.org/wiki/Enumerations
note: Basic language learning

View file

@ -0,0 +1,4 @@
;Task:
Create an enumeration of constants with and without explicit values.
<br><br>

View file

@ -0,0 +1,5 @@
T.enum TokenCategory
NAME
KEYWORD
CONSTANT
TEST_CATEGORY = 10

View file

@ -0,0 +1,7 @@
Sunday equ 0
Monday equ 1
Tuesday equ 2
Wednesday equ 3
Thursday equ 4
Friday equ 5
Saturday equ 6

View file

@ -0,0 +1,4 @@
enum $0400
OBJECT_XPOS .dsb 16 ;define 16 bytes for object X position
OBJECT_YPOS .dsb 16 ;define 16 bytes for object Y position
ende

View file

@ -0,0 +1,30 @@
Days_Of_The_Week:
word Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
Sunday:
byte "Sunday",0
Monday:
byte "Monday",0
Tuesday:
byte "Tuesday",0
Wednesday:
byte "Wednesday",0
Thursday:
byte "Thursday",0
Friday:
byte "Friday",0
Saturday:
byte "Saturday",0
LDA #$03 ;we want to load Wednesday
ASL A ;these are 16-bit pointers to strings, so double A
TAX ;transfer A to X so that we can use this index as a lookup
LDA Days_Of_The_Week,x ;get low byte
STA $00 ;store in zero page memory
LDA Days_Of_The_Week+1,x ;get high byte
STA $01 ;store in zero page memory directly after low byte
LDY #0 ;clear Y
LDA ($00),Y ;Load the "W" of Wednesday into accumulator

View file

@ -0,0 +1,7 @@
Sunday equ 0
Monday equ 1
Tuesday equ 2
Wednesday equ 3
Thursday equ 4
Friday equ 5
Saturday equ 6

View file

@ -0,0 +1,33 @@
Days_Of_The_Week:
DC.L Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
Sunday:
DC.B "Sunday",0
EVEN ;conditionally aligns to a 2-byte boundary if the data isn't aligned already
Monday:
DC.B "Monday",0
EVEN
Tuesday:
DC.B "Tuesday",0
EVEN
Wednesday:
DC.B "Wednesday",0
EVEN
Thursday:
DC.B "Thursday",0
EVEN
Friday:
DC.B "Friday",0
EVEN
Saturday:
DC.B "Saturday",0
EVEN
;In this example, load Thursday.
LEA Days_Of_The_Week,A0 ;load base address of table into A0
MOVE.W #4,D0 ;Thursday's index
LSL.W #2,D0 ;multiply by 4 since each pointer is 32-bit
LEA (A0,D0),A1 ;load table offset by D0 into A1
MOVE.L (A1),A1 ;dereference the pointer, now the address of "Thursday" is in A1.
MOVE.B (A1)+,D1 ;Load the "T" of Thursday into D1, auto-increment to next letter for the next load.

View file

@ -0,0 +1,8 @@
Sunday equ 0
Monday equ 1
Tuesday equ 2
Wednesday equ 3
Thursday equ 4
Friday equ 5
Saturday equ 6
Sunday equ 7

View file

@ -0,0 +1,13 @@
mov ax,seg DaysOfTheWeek
mov ds,ax
mov si,offset DaysOfTheWeek
mov bx,2 ;desired enumeration of 2 = Tuesday
add bx,bx ;double bx since this is a table of words
mov ax,[bx+si] ;load the address of the string "Tuesday" into ax
mov si,ax ;we can't load indirectly from AX, so move it into SI. We don't need the old value of SI anymore
mov al,[si] ;load the byte at [SI] (in this case, the "T" in Tuesday.)
ret
DaysOfTheWeek word Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
;each is a pointer to a string containing the text you would expect.

View file

@ -0,0 +1,22 @@
(defun symbol-to-constant (sym)
(intern (concatenate 'string "*" (symbol-name sym) "*")
"ACL2"))
(defmacro enum-with-vals (symbol value &rest args)
(if (endp args)
`(defconst ,(symbol-to-constant symbol) ,value)
`(progn (defconst ,(symbol-to-constant symbol) ,value)
(enum-with-vals ,@args))))
(defun interleave-with-nats-r (xs i)
(if (endp xs)
nil
(cons (first xs)
(cons i (interleave-with-nats-r (rest xs)
(1+ i))))))
(defun interleave-with-nats (xs)
(interleave-with-nats-r xs 0))
(defmacro enum (&rest symbols)
`(enum-with-vals ,@(interleave-with-nats symbols)))

View file

@ -0,0 +1,13 @@
BEGIN # example 1 #
MODE FRUIT = INT;
FRUIT apple = 1, banana = 2, cherry = 4;
FRUIT x := cherry;
CASE x IN
print(("It is an apple #",x, new line)),
print(("It is a banana #",x, new line)),
SKIP, # 3 not defined #
print(("It is a cherry #",x, new line))
OUT
SKIP # other values #
ESAC
END;

View file

@ -0,0 +1,24 @@
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);
OP REPR = (FRUIT f)STRING:
CASE f IN
(APPLE):"Apple",
(BANANA):"Banana",
(CHERRY):"Cherry"
OUT
"?" # uninitalised #
ESAC;
FRUIT x := LOC CHERRY;
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,4 @@
datatype my_enum =
| value_a
| value_b
| value_c

View file

@ -0,0 +1,3 @@
#define value_a 1
#define value_b 2
#define value_c 3

View file

@ -0,0 +1 @@
typedef my_enum = [i : int | value_a <= i; i <= value_c] int i

View file

@ -0,0 +1,3 @@
fruit["apple"]=1; fruit["banana"]=2; fruit["cherry"]=3
fruit[1]="apple"; fruit[2]="banana"; fruit[3]="cherry"
i=0; apple=++i; banana=++i; cherry=++i;

View file

@ -0,0 +1,2 @@
type Fruit is (apple, banana, cherry); -- No specification of the representation value;
for Fruit use (apple => 1, banana => 2, cherry => 4); -- specification of the representation values

View file

@ -0,0 +1,7 @@
ENUM APPLE, BANANA, CHERRY
PROC main()
DEF x
ForAll({x}, [APPLE, BANANA, CHERRY],
`WriteF('\d\n', x))
ENDPROC

View file

@ -0,0 +1,15 @@
enum: [apple banana cherry]
print "as a block of words:"
inspect.muted enum
enum: ['apple 'banana 'cherry]
print "\nas a block of literals:"
print enum
enum: #[
apple: 1
banana: 2
cherry: 3
]
print "\nas a dictionary:"
print enum

View file

@ -0,0 +1,3 @@
fruit_%apple% = 0
fruit_%banana% = 1
fruit_%cherry% = 2

View file

@ -0,0 +1,16 @@
REM Impossible. Can only be faked with arrays of strings.
OPTION BASE 1
DIM SHARED fruitsName$(1 to 3)
DIM SHARED fruitsVal%( 1 to 3)
fruitsName$[1] = "apple"
fruitsName$[2] = "banana"
fruitsName$[3] = "cherry"
fruitsVal%[1] = 1
fruitsVal%[2] = 2
fruitsVal%[3] = 3
REM OR GLOBAL CONSTANTS
DIM SHARED apple%, banana%, cherry%
apple% = 1
banana% = 2
cherry% = 3

View file

@ -0,0 +1,18 @@
' Enumerations
' Start at zero
ENUM
cat, dog, parrot
END ENUM
PRINT "Dogs are #", dog
' Set value
ENUM
Sunday=1, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
END ENUM
PRINT Sunday, " ", Wednesday, " ", Saturday
' Change values, ENUM names must be unique
ENUM
sunday=7, monday=1, tuesday, wednesday, thursday, friday, saturday
END ENUM
PRINT sunday, " ", wednesday, " ", saturday

View file

@ -0,0 +1 @@
fruits=apple+banana+cherry;

View file

@ -0,0 +1,3 @@
enum fruits { apple, banana, cherry };
enum fruits { apple = 0, banana = 1, cherry = 2 };

View file

@ -0,0 +1,3 @@
enum class fruits { apple, banana, cherry };
enum class fruits { apple = 0, banana = 1, cherry = 2 };

View file

@ -0,0 +1 @@
enum class fruits : unsigned int { apple, banana, cherry };

View file

@ -0,0 +1 @@
enum fruits : unsigned int { apple, banana, cherry };

View file

@ -0,0 +1,8 @@
enum fruits { apple, banana, cherry }
enum fruits { apple = 0, banana = 1, cherry = 2 }
enum fruits : int { apple = 0, banana = 1, cherry = 2 }
[FlagsAttribute]
enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 }

View file

@ -0,0 +1,3 @@
enum fruits { apple, banana, cherry };
enum fruits { apple = 0, banana = 1, cherry = 2 };

View file

@ -0,0 +1,3 @@
typedef enum { apple, banana, cherry } fruits;
typedef enum { apple = 0, banana = 1, cherry = 2 } fruits;

View file

@ -0,0 +1,11 @@
; a set of keywords
(def fruits #{:apple :banana :cherry})
; a predicate to test "fruit" membership
(defn fruit? [x] (contains? fruits x))
; if you need a value associated with each fruit
(def fruit-value (zipmap fruits (iterate inc 1)))
(println (fruit? :apple))
(println (fruit-value :banana))

View file

@ -0,0 +1,8 @@
;; symbol to number
(defconstant +apple+ 0)
(defconstant +banana+ 1)
(defconstant +cherry+ 2)
;; number to symbol
(defun index-fruit (i)
(aref #(+apple+ +banana+ +cherry+) i))

View file

@ -0,0 +1,2 @@
(deftype fruit ()
'(member +apple+ +banana+ +cherry+))

View file

@ -0,0 +1,5 @@
LDA 4 ;load from memory address 4
STP
NOP
NOP
byte 1

View file

@ -0,0 +1,50 @@
void main() {
// Named enumeration (commonly used enum in D).
// The underlying type is a 32 bit int.
enum Fruits1 { apple, banana, cherry }
// You can assign an enum to the general type, but not the opposite:
int f1 = Fruits1.banana; // No error.
// Fruits1 f2 = 1; // Error: cannot implicitly convert.
// Anonymous enumeration, as in C, of type 32 bit int.
enum { APPLE, BANANA, CHERRY }
static assert(CHERRY == 2);
// Named enumeration with specified values (int).
enum Fruits2 { apple = 0, banana = 10, cherry = 20 }
// Named enumeration, typed and with specified values.
enum Fruits3 : ubyte { apple = 0, banana = 100, cherry = 200 }
// Named enumeration, typed and with partially specified values.
enum Test : ubyte { A = 2, B, C = 3 }
static assert(Test.B == 3); // Uses the next ubyte, duplicated value.
// This raises a compile-time error for overflow.
// enum Fruits5 : ubyte { apple = 254, banana = 255, cherry }
enum Component {
none,
red = 2 ^^ 0,
green = 2 ^^ 1,
blue = 2 ^^ 2
}
// Phobos BitFlags support all the most common operations on flags.
// Some of the operations are shown below.
import std.typecons: BitFlags;
alias ComponentFlags = BitFlags!Component;
immutable ComponentFlags flagsEmpty;
// Value can be set with the | operator.
immutable flagsRed = flagsEmpty | Component.red;
immutable flagsGreen = ComponentFlags(Component.green);
immutable flagsRedGreen = ComponentFlags(Component.red, Component.green);
immutable flagsBlueGreen = ComponentFlags(Component.blue, Component.green);
// Use the & operator between BitFlags for intersection.
assert (flagsGreen == (flagsRedGreen & flagsBlueGreen));
}

View file

@ -0,0 +1,2 @@
type TFruit = (Apple, Banana, Cherry);
type TApe = (Gorilla = 0, Chimpanzee = 1, Orangutan = 5);

View file

@ -0,0 +1,3 @@
type
fruit = (apple, banana, cherry);
ape = (gorilla = 0, chimpanzee = 1, orangutan = 5);

View file

@ -0,0 +1,7 @@
add_enum(⟪{int}⟫,⟦{str}⟧,urgency)
()_enum(⟪4⟫,⟦emergent⟧)_static(URGENCY_EMERGENT)_colour(red)_color({hex},#ca0031)_desc(The most urgent (critical) state, severe risk.);
()_enum(⟪3⟫,⟦exigent⟧)_static(URGENT_EXIGENT)_colour(orange)_color({hex},#ff6400)_desc(The high urgent state, high risk.);
()_enum(⟪2⟫,⟦urgent⟧)_static(URGENT_URGENT)_colour(yellow)_color({hex},#fce001)_desc(The elevated urgent state, elevated risk.);
()_enum(⟪1⟫,⟦infergent⟧)_static(URGENT_INFERGENT)_colour(blue)_color({hex},#3566cd)_desc(The low urgent state, low / guarded risk.);
()_enum(⟪0⟫,⟦nonurgent⟧)_static(URGENT_NON)_colour(green)_color({hex},#009a66)_desc(The non-urgent state, negligible risk.);
;

View file

@ -0,0 +1 @@
add_enum(fruits,⟦apple,banana,cherry⟧);

View file

@ -0,0 +1,2 @@
add_flag(ape,⟦gorilla,chimpanzee,orangutan⟧);
log_console()_(ape);

View file

@ -0,0 +1,3 @@
def apple { to value() { return 0 } }
def banana { to value() { return 1 } }
def cherry { to value() { return 2 } }

View file

@ -0,0 +1,6 @@
interface Fruit guards FruitStamp {}
def apple implements FruitStamp {}
def banana implements FruitStamp {}
def cherry implements FruitStamp {}
def eat(fruit :Fruit) { ... }

View file

@ -0,0 +1,4 @@
def [Fruit, [=> apple, => banana, => cherry]] := makeEnumeration()
def [Fruit, [=> apple, => banana, => cherry]] :=
makeEnumeration(0, ["apple", "banana", "cherry"])

View file

@ -0,0 +1,27 @@
// Without explicit values
enumeration FruitsKind
APPLE,
BANANA,
CHERRY
end
program EnumerationTest
function main()
whatFruitAmI(FruitsKind.CHERRY);
end
function whatFruitAmI(fruit FruitsKind)
case (fruit)
when(FruitsKind.APPLE)
syslib.writestdout("You're an apple.");
when(FruitsKind.BANANA)
syslib.writestdout("You're a banana.");
when(FruitsKind.CHERRY)
syslib.writestdout("You're a cherry.");
otherwise
syslib.writestdout("I'm not sure what you are.");
end
end
end

View file

@ -0,0 +1,27 @@
// With explicit values
library FruitsKind type BasicLibrary {}
const APPLE int = 0;
const BANANA int = 1;
const CHERRY int = 2;
end
program EnumerationTest
function main()
whatFruitAmI(FruitsKind.CHERRY);
end
function whatFruitAmI(fruit int in)
case (fruit)
when(FruitsKind.APPLE)
syslib.writestdout("You're an apple.");
when(FruitsKind.BANANA)
syslib.writestdout("You're a banana.");
when(FruitsKind.CHERRY)
syslib.writestdout("You're a cherry.");
otherwise
syslib.writestdout("I'm not sure what you are.");
end
end
end

View file

@ -0,0 +1,5 @@
fruits = [:apple, :banana, :cherry]
fruits = ~w(apple banana cherry)a # Above-mentioned different notation
val = :banana
Enum.member?(fruits, val) #=> true
val in fruits #=> true

View file

@ -0,0 +1,10 @@
fruits = [{:apple, 1}, {:banana, 2}, {:cherry, 3}] # Keyword list
fruits = [apple: 1, banana: 2, cherry: 3] # Above-mentioned different notation
fruits[:apple] #=> 1
Keyword.has_key?(fruits, :banana) #=> true
fruits = %{:apple=>1, :banana=>2, :cherry=>3} # Map
fruits = %{apple: 1, banana: 2, cherry: 3} # Above-mentioned different notation
fruits[:apple] #=> 1
fruits.apple #=> 1 (Only When the key is Atom)
Map.has_key?(fruits, :banana) #=> true

View file

@ -0,0 +1,7 @@
# Keyword list
fruits = ~w(apple banana cherry)a |> Enum.with_index
#=> [apple: 0, banana: 1, cherry: 2]
# Map
fruits = ~w(apple banana cherry)a |> Enum.with_index |> Map.new
#=> %{apple: 0, banana: 1, cherry: 2}

View file

@ -0,0 +1,7 @@
type Fruit =
| Apple = 0
| Banana = 1
| Cherry = 2
let basket = [ Fruit.Apple ; Fruit.Banana ; Fruit.Cherry ]
Seq.iter (printfn "%A") basket

View file

@ -0,0 +1,6 @@
type Fruit =
| Apple
| Banana
| Cherry
let basket = [ Apple ; Banana ; Cherry ]
Seq.iter (printfn "%A") basket

View file

@ -0,0 +1,9 @@
IN: scratchpad { "sun" "mon" "tue" "wed" "thur" "fri" "sat" } <enum>
--- Data stack:
T{ enum f ~array~ }
IN: scratchpad [ 1 swap at ] [ keys ] bi
--- Data stack:
"mon"
{ 0 1 2 3 4 5 6 }

View file

@ -0,0 +1,11 @@
IN: scratchpad USE: alien.syntax
IN: scratchpad ENUM: day sun mon { tue 42 } wed thur fri sat ;
IN: scratchpad 1 <day>
--- Data stack:
mon
IN: scratchpad 42 <day>
--- Data stack:
mon
tue

View file

@ -0,0 +1,2 @@
// create an enumeration with named constants
enum class Fruits { apple, banana, orange }

View file

@ -0,0 +1,7 @@
// create an enumeration with explicit values
enum class Fruits_
{
apple (1), banana (2), orange (3)
const Int value
private new make (Int value) { this.value = value }
}

View file

@ -0,0 +1,4 @@
0 CONSTANT apple
1 CONSTANT banana
2 CONSTANT cherry
...

View file

@ -0,0 +1 @@
: ENUM ( n -<name>- n+1 ) DUP CONSTANT 1+ ;

View file

@ -0,0 +1 @@
0 ENUM APPLE ENUM BANANA ENUM CHERRY DROP

View file

@ -0,0 +1 @@
0 ENUM FIRST ENUM SECOND ... CONSTANT LAST

View file

@ -0,0 +1,2 @@
: SIZED-ENUM ( n s -<name>- n+s ) OVER CONSTANT + ;
: CELL-ENUM ( n -<name>- n+cell ) CELL SIZED-ENUM ;

View file

@ -0,0 +1,6 @@
0 ENUM FIRST \ value = 0
CELL-ENUM SECOND \ value = 1
ENUM THIRD \ value = 5
3 SIZED-ENUM FOURTH \ value = 6
ENUM FIFTH \ value = 9
CONSTANT SIXTH \ value = 10

View file

@ -0,0 +1,4 @@
: CONSTANTS ( n -- ) 0 DO I CONSTANT LOOP ;
\ resistor digit colors
10 CONSTANTS black brown red orange yellow green blue violet gray white

View file

@ -0,0 +1,4 @@
enum, bind(c)
enumerator :: one=1, two, three, four, five
enumerator :: six, seven, nine=9
end enum

View file

@ -0,0 +1,3 @@
enum, bind(c) :: nametype
enumerator :: one=1, two, three
end enum nametype

View file

@ -0,0 +1,17 @@
' FB 1.05.0 Win64
Enum Animals
Cat
Dog
Zebra
End Enum
Enum Dogs
Bulldog = 1
Terrier = 2
WolfHound = 4
End Enum
Print Cat, Dog, Zebra
Print Bulldog, Terrier, WolfHound
Sleep

View file

@ -0,0 +1,23 @@
window 1, @"Enumerations", (0,0,480,270)
begin enum 1
_apple
_banana
_cherry
end enum
begin enum
_appleExplicit = 10
_bananaExplicit = 15
_cherryExplicit = 30
end enum
print "_apple = "; _apple
print "_banana = "; _banana
print "_cherry = "; _cherry
print
print "_appleExplicit = "; _appleExplicit
print "_bananaExplicit = "; _bananaExplicit
print "_cherryExplicit = "; _cherryExplicit
HandleEvents

View file

@ -0,0 +1,5 @@
const (
apple = iota
banana
cherry
)

View file

@ -0,0 +1,5 @@
const (
apple = 0
banana = 1
cherry = 2
)

View file

@ -0,0 +1,7 @@
type fruit int
const (
apple fruit = iota
banana
cherry
)

View file

@ -0,0 +1,7 @@
type fruit int
const (
apple fruit = 0
banana fruit = 1
cherry fruit = 2
)

View file

@ -0,0 +1,11 @@
enum Fruit { apple, banana, cherry }
enum ValuedFruit {
apple(1), banana(2), cherry(3);
def value
ValuedFruit(val) {value = val}
String toString() { super.toString() + "(${value})" }
}
println Fruit.values()
println ValuedFruit.values()

View file

@ -0,0 +1 @@
data Fruit = Apple | Banana | Cherry deriving Enum

View file

@ -0,0 +1,5 @@
enum FRUIT {
APPLE,
BANANA,
CHERRY
}

View file

@ -0,0 +1,6 @@
fruits := [ "apple", "banana", "cherry", "apple" ] # a list keeps ordered data
fruits := set("apple", "banana", "cherry") # a set keeps unique data
fruits := table() # table keeps an unique data with values
fruits["apple"] := 1
fruits["banana"] := 2
fruits["cherry"] := 3

View file

@ -0,0 +1 @@
Fruit is a kind of value. The fruits are apple, banana, and cherry.

View file

@ -0,0 +1,6 @@
[sentence form]
Fruit is a kind of value. The fruits are apple, banana, and cherry.
A fruit has a number called numeric value.
The numeric value of apple is 1.
The numeric value of banana is 2.
The numeric value of cherry is 3.

View file

@ -0,0 +1,8 @@
[table form]
Fruit is a kind of value. The fruits are defined by the Table of Fruits.
Table of Fruits
fruit numeric value
apple 1
banana 2
cherry 3

View file

@ -0,0 +1,4 @@
enum =: cocreate''
( (;:'apple banana cherry') ,L:0 '__enum' ) =: i. 3
cherry__enum
2

View file

@ -0,0 +1 @@
fruit=: ;:'apple banana cherry'

View file

@ -0,0 +1,4 @@
2 { fruit
+------+
|cherry|
+------+

View file

@ -0,0 +1,2 @@
fruit i.<'banana'
1

View file

@ -0,0 +1,4 @@
(<'banana') +&.(fruit&i.) <'banana'
+------+
|cherry|
+------+

View file

@ -0,0 +1,4 @@
{{for_example. fruit do. echo;example end.}} ''
apple
banana
cherry

View file

@ -0,0 +1,2 @@
enum fruits { apple, banana, cherry }
enum fruits { apple = 0, banana = 1, cherry = 2 }

View file

@ -0,0 +1,3 @@
enum Fruits{
APPLE, BANANA, CHERRY
}

View file

@ -0,0 +1,6 @@
enum Fruits{
APPLE(0), BANANA(1), CHERRY(2)
private final int value;
fruits(int value) { this.value = value; }
public int value() { return value; }
}

View file

@ -0,0 +1,7 @@
// enum fruits { apple, banana, cherry }
var f = "apple";
if(f == "apple"){
f = "banana";
}

View file

@ -0,0 +1 @@
@enum Fruits APPLE BANANA CHERRY

View file

@ -0,0 +1,15 @@
// version 1.0.5-2
enum class Animals {
CAT, DOG, ZEBRA
}
enum class Dogs(val id: Int) {
BULLDOG(1), TERRIER(2), WOLFHOUND(4)
}
fun main(args: Array<String>) {
for (value in Animals.values()) println("${value.name.padEnd(5)} : ${value.ordinal}")
println()
for (value in Dogs.values()) println("${value.name.padEnd(9)} : ${value.id}")
}

View file

@ -0,0 +1,32 @@
-- parent script "Enumeration"
property ancestor
on new (me)
data = [:]
repeat with i = 2 to the paramCount
data[param(i)] = i-1
end repeat
me.ancestor = data
return me
end
on setAt (me)
-- do nothing
end
on setProp (me)
-- do nothing
end
on deleteAt (me)
-- do nothing
end
on deleteProp (me)
-- do nothing
end
on addProp (me)
-- do nothing
end

View file

@ -0,0 +1,34 @@
enumeration = script("Enumeration").new("APPLE", "BANANA", "CHERRY")
put enumeration["BANANA"]
-- 2
-- try to change a value after construction (fails)
enumeration["BANANA"] = 666
put enumeration["BANANA"]
-- 2
-- try to change a value after construction using setProp (fails)
enumeration.setProp("BANANA", 666)
put enumeration["BANANA"]
-- 2
-- try to delete a value after construction (fails)
enumeration.deleteAt(2)
put enumeration["BANANA"]
-- 2
-- try to delete a value after construction using deleteProp (fails)
enumeration.deleteProp("BANANA")
put enumeration["BANANA"]
-- 2
-- try to add a new value after construction (fails)
enumeration["FOO"] = 666
put enumeration["FOO"]
-- <Void>
-- try to add a new value after construction using addProp (fails)
enumeration.addProp("FOO", 666)
put enumeration["FOO"]
-- <Void>

View file

@ -0,0 +1 @@
local fruit = {apple = 0, banana = 1, cherry = 2}

View file

@ -0,0 +1 @@
local apple, banana, cherry = 0,1,2

View file

@ -0,0 +1,56 @@
Module Checkit {
\\ need revision 15, version 9.4
Enum Fruit {apple, banana, cherry}
Enum Fruit2 {apple2=10, banana2=20, cherry2=30}
Print apple, banana, cherry
Print apple2, banana2, cherry2
Print Len(apple)=0
Print Len(banana)=1
Print Len(cherry)=2
Print Len(cherry2)=2, Cherry2=30, Type$(Cherry2)="Fruit2"
k=each(Fruit)
While k {
\\ name of variable, value, length from first (0, 1, 2)
Print Eval$(k), Eval(k), k^
}
m=apple
Print Eval$(m)="apple"
Print Eval(m)=m
m++
Print Eval$(m)="banana"
Try {
\\ error, m is an object
m=100
}
Try {
\\ error not the same type
m=apple2
}
Try {
\\ read only can't change
apple2++
}
m++
Print Eval$(m)="cherry", m
k=Each(Fruit2 end to start)
While k {
Print Eval$(k), Eval(k) , k^
CheckByValue(Eval(k))
}
m2=apple2
Print "-------------------------"
CheckByValue(m2)
CheckByReference(&m2)
Print m2
Sub CheckByValue(z as Fruit2)
Print Eval$(z), z
End Sub
Sub CheckByReference(&z as Fruit2)
z++
Print Eval$(z), z
End Sub
}
Checkit

View file

@ -0,0 +1,6 @@
define(`enums',
`define(`$2',$1)`'ifelse(eval($#>2),1,`enums(incr($1),shift(shift($@)))')')
define(`enum',
`enums(1,$@)')
enum(a,b,c,d)
`c='c

View file

@ -0,0 +1,5 @@
stuff = {'apple', [1 2 3], 'cherry',1+2i}
stuff =
'apple' [1x3 double] 'cherry' [1.000000000000000 + 2.000000000000000i]

View file

@ -0,0 +1,11 @@
MapIndexed[Set, {A, B, F, G}]
->{{1}, {2}, {3}, {4}}
A
->{1}
B
->{2}
G
->{4}

View file

@ -0,0 +1,4 @@
vardef enum(expr first)(text t) =
save ?; ? := first;
forsuffixes e := t: e := ?; ?:=?+1; endfor
enddef;

View file

@ -0,0 +1,5 @@
enum(1, Apple, Banana, Cherry);
enum(5, Orange, Pineapple, Qfruit);
show Apple, Banana, Cherry, Orange, Pineapple, Qfruit;
end

View file

@ -0,0 +1 @@
TYPE Fruit = {Apple, Banana, Cherry};

Some files were not shown because too many files have changed in this diff Show more