Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Enumerations/00-META.yaml
Normal file
3
Task/Enumerations/00-META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Enumerations
|
||||
note: Basic language learning
|
||||
4
Task/Enumerations/00-TASK.txt
Normal file
4
Task/Enumerations/00-TASK.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
;Task:
|
||||
Create an enumeration of constants with and without explicit values.
|
||||
<br><br>
|
||||
|
||||
5
Task/Enumerations/11l/enumerations.11l
Normal file
5
Task/Enumerations/11l/enumerations.11l
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
T.enum TokenCategory
|
||||
NAME
|
||||
KEYWORD
|
||||
CONSTANT
|
||||
TEST_CATEGORY = 10
|
||||
7
Task/Enumerations/6502-Assembly/enumerations-1.6502
Normal file
7
Task/Enumerations/6502-Assembly/enumerations-1.6502
Normal 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
|
||||
4
Task/Enumerations/6502-Assembly/enumerations-2.6502
Normal file
4
Task/Enumerations/6502-Assembly/enumerations-2.6502
Normal 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
|
||||
30
Task/Enumerations/6502-Assembly/enumerations-3.6502
Normal file
30
Task/Enumerations/6502-Assembly/enumerations-3.6502
Normal 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
|
||||
7
Task/Enumerations/68000-Assembly/enumerations-1.68000
Normal file
7
Task/Enumerations/68000-Assembly/enumerations-1.68000
Normal 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
|
||||
33
Task/Enumerations/68000-Assembly/enumerations-2.68000
Normal file
33
Task/Enumerations/68000-Assembly/enumerations-2.68000
Normal 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.
|
||||
8
Task/Enumerations/8086-Assembly/enumerations-1.8086
Normal file
8
Task/Enumerations/8086-Assembly/enumerations-1.8086
Normal 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
|
||||
13
Task/Enumerations/8086-Assembly/enumerations-2.8086
Normal file
13
Task/Enumerations/8086-Assembly/enumerations-2.8086
Normal 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.
|
||||
22
Task/Enumerations/ACL2/enumerations.acl2
Normal file
22
Task/Enumerations/ACL2/enumerations.acl2
Normal 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)))
|
||||
13
Task/Enumerations/ALGOL-68/enumerations-1.alg
Normal file
13
Task/Enumerations/ALGOL-68/enumerations-1.alg
Normal 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;
|
||||
24
Task/Enumerations/ALGOL-68/enumerations-2.alg
Normal file
24
Task/Enumerations/ALGOL-68/enumerations-2.alg
Normal 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
|
||||
4
Task/Enumerations/ATS/enumerations-1.ats
Normal file
4
Task/Enumerations/ATS/enumerations-1.ats
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
datatype my_enum =
|
||||
| value_a
|
||||
| value_b
|
||||
| value_c
|
||||
3
Task/Enumerations/ATS/enumerations-2.ats
Normal file
3
Task/Enumerations/ATS/enumerations-2.ats
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#define value_a 1
|
||||
#define value_b 2
|
||||
#define value_c 3
|
||||
1
Task/Enumerations/ATS/enumerations-3.ats
Normal file
1
Task/Enumerations/ATS/enumerations-3.ats
Normal file
|
|
@ -0,0 +1 @@
|
|||
typedef my_enum = [i : int | value_a <= i; i <= value_c] int i
|
||||
3
Task/Enumerations/AWK/enumerations.awk
Normal file
3
Task/Enumerations/AWK/enumerations.awk
Normal 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;
|
||||
2
Task/Enumerations/Ada/enumerations.ada
Normal file
2
Task/Enumerations/Ada/enumerations.ada
Normal 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
|
||||
7
Task/Enumerations/AmigaE/enumerations.amiga
Normal file
7
Task/Enumerations/AmigaE/enumerations.amiga
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
ENUM APPLE, BANANA, CHERRY
|
||||
|
||||
PROC main()
|
||||
DEF x
|
||||
ForAll({x}, [APPLE, BANANA, CHERRY],
|
||||
`WriteF('\d\n', x))
|
||||
ENDPROC
|
||||
15
Task/Enumerations/Arturo/enumerations.arturo
Normal file
15
Task/Enumerations/Arturo/enumerations.arturo
Normal 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
|
||||
3
Task/Enumerations/AutoHotkey/enumerations.ahk
Normal file
3
Task/Enumerations/AutoHotkey/enumerations.ahk
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fruit_%apple% = 0
|
||||
fruit_%banana% = 1
|
||||
fruit_%cherry% = 2
|
||||
16
Task/Enumerations/BASIC/enumerations.basic
Normal file
16
Task/Enumerations/BASIC/enumerations.basic
Normal 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
|
||||
18
Task/Enumerations/BaCon/enumerations.bacon
Normal file
18
Task/Enumerations/BaCon/enumerations.bacon
Normal 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
|
||||
1
Task/Enumerations/Bracmat/enumerations.bracmat
Normal file
1
Task/Enumerations/Bracmat/enumerations.bracmat
Normal file
|
|
@ -0,0 +1 @@
|
|||
fruits=apple+banana+cherry;
|
||||
3
Task/Enumerations/C++/enumerations-1.cpp
Normal file
3
Task/Enumerations/C++/enumerations-1.cpp
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
enum fruits { apple, banana, cherry };
|
||||
|
||||
enum fruits { apple = 0, banana = 1, cherry = 2 };
|
||||
3
Task/Enumerations/C++/enumerations-2.cpp
Normal file
3
Task/Enumerations/C++/enumerations-2.cpp
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
enum class fruits { apple, banana, cherry };
|
||||
|
||||
enum class fruits { apple = 0, banana = 1, cherry = 2 };
|
||||
1
Task/Enumerations/C++/enumerations-3.cpp
Normal file
1
Task/Enumerations/C++/enumerations-3.cpp
Normal file
|
|
@ -0,0 +1 @@
|
|||
enum class fruits : unsigned int { apple, banana, cherry };
|
||||
1
Task/Enumerations/C++/enumerations-4.cpp
Normal file
1
Task/Enumerations/C++/enumerations-4.cpp
Normal file
|
|
@ -0,0 +1 @@
|
|||
enum fruits : unsigned int { apple, banana, cherry };
|
||||
8
Task/Enumerations/C-sharp/enumerations.cs
Normal file
8
Task/Enumerations/C-sharp/enumerations.cs
Normal 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 }
|
||||
3
Task/Enumerations/C/enumerations-1.c
Normal file
3
Task/Enumerations/C/enumerations-1.c
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
enum fruits { apple, banana, cherry };
|
||||
|
||||
enum fruits { apple = 0, banana = 1, cherry = 2 };
|
||||
3
Task/Enumerations/C/enumerations-2.c
Normal file
3
Task/Enumerations/C/enumerations-2.c
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
typedef enum { apple, banana, cherry } fruits;
|
||||
|
||||
typedef enum { apple = 0, banana = 1, cherry = 2 } fruits;
|
||||
11
Task/Enumerations/Clojure/enumerations.clj
Normal file
11
Task/Enumerations/Clojure/enumerations.clj
Normal 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))
|
||||
8
Task/Enumerations/Common-Lisp/enumerations-1.lisp
Normal file
8
Task/Enumerations/Common-Lisp/enumerations-1.lisp
Normal 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))
|
||||
2
Task/Enumerations/Common-Lisp/enumerations-2.lisp
Normal file
2
Task/Enumerations/Common-Lisp/enumerations-2.lisp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(deftype fruit ()
|
||||
'(member +apple+ +banana+ +cherry+))
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
LDA 4 ;load from memory address 4
|
||||
STP
|
||||
NOP
|
||||
NOP
|
||||
byte 1
|
||||
50
Task/Enumerations/D/enumerations.d
Normal file
50
Task/Enumerations/D/enumerations.d
Normal 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));
|
||||
}
|
||||
2
Task/Enumerations/DWScript/enumerations.dw
Normal file
2
Task/Enumerations/DWScript/enumerations.dw
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
type TFruit = (Apple, Banana, Cherry);
|
||||
type TApe = (Gorilla = 0, Chimpanzee = 1, Orangutan = 5);
|
||||
3
Task/Enumerations/Delphi/enumerations.delphi
Normal file
3
Task/Enumerations/Delphi/enumerations.delphi
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
type
|
||||
fruit = (apple, banana, cherry);
|
||||
ape = (gorilla = 0, chimpanzee = 1, orangutan = 5);
|
||||
7
Task/Enumerations/Diego/enumerations-1.diego
Normal file
7
Task/Enumerations/Diego/enumerations-1.diego
Normal 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.);
|
||||
;
|
||||
1
Task/Enumerations/Diego/enumerations-2.diego
Normal file
1
Task/Enumerations/Diego/enumerations-2.diego
Normal file
|
|
@ -0,0 +1 @@
|
|||
add_enum(fruits,⟦apple,banana,cherry⟧);
|
||||
2
Task/Enumerations/Diego/enumerations-3.diego
Normal file
2
Task/Enumerations/Diego/enumerations-3.diego
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
add_flag(ape,⟦gorilla,chimpanzee,orangutan⟧);
|
||||
log_console()_(ape);
|
||||
3
Task/Enumerations/E/enumerations-1.e
Normal file
3
Task/Enumerations/E/enumerations-1.e
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def apple { to value() { return 0 } }
|
||||
def banana { to value() { return 1 } }
|
||||
def cherry { to value() { return 2 } }
|
||||
6
Task/Enumerations/E/enumerations-2.e
Normal file
6
Task/Enumerations/E/enumerations-2.e
Normal 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) { ... }
|
||||
4
Task/Enumerations/E/enumerations-3.e
Normal file
4
Task/Enumerations/E/enumerations-3.e
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
def [Fruit, [=> apple, => banana, => cherry]] := makeEnumeration()
|
||||
|
||||
def [Fruit, [=> apple, => banana, => cherry]] :=
|
||||
makeEnumeration(0, ["apple", "banana", "cherry"])
|
||||
27
Task/Enumerations/EGL/enumerations-1.egl
Normal file
27
Task/Enumerations/EGL/enumerations-1.egl
Normal 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
|
||||
27
Task/Enumerations/EGL/enumerations-2.egl
Normal file
27
Task/Enumerations/EGL/enumerations-2.egl
Normal 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
|
||||
5
Task/Enumerations/Elixir/enumerations-1.elixir
Normal file
5
Task/Enumerations/Elixir/enumerations-1.elixir
Normal 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
|
||||
10
Task/Enumerations/Elixir/enumerations-2.elixir
Normal file
10
Task/Enumerations/Elixir/enumerations-2.elixir
Normal 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
|
||||
7
Task/Enumerations/Elixir/enumerations-3.elixir
Normal file
7
Task/Enumerations/Elixir/enumerations-3.elixir
Normal 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}
|
||||
7
Task/Enumerations/F-Sharp/enumerations-1.fs
Normal file
7
Task/Enumerations/F-Sharp/enumerations-1.fs
Normal 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
|
||||
6
Task/Enumerations/F-Sharp/enumerations-2.fs
Normal file
6
Task/Enumerations/F-Sharp/enumerations-2.fs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
type Fruit =
|
||||
| Apple
|
||||
| Banana
|
||||
| Cherry
|
||||
let basket = [ Apple ; Banana ; Cherry ]
|
||||
Seq.iter (printfn "%A") basket
|
||||
9
Task/Enumerations/Factor/enumerations-1.factor
Normal file
9
Task/Enumerations/Factor/enumerations-1.factor
Normal 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 }
|
||||
11
Task/Enumerations/Factor/enumerations-2.factor
Normal file
11
Task/Enumerations/Factor/enumerations-2.factor
Normal 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
|
||||
2
Task/Enumerations/Fantom/enumerations-1.fantom
Normal file
2
Task/Enumerations/Fantom/enumerations-1.fantom
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// create an enumeration with named constants
|
||||
enum class Fruits { apple, banana, orange }
|
||||
7
Task/Enumerations/Fantom/enumerations-2.fantom
Normal file
7
Task/Enumerations/Fantom/enumerations-2.fantom
Normal 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 }
|
||||
}
|
||||
4
Task/Enumerations/Forth/enumerations-1.fth
Normal file
4
Task/Enumerations/Forth/enumerations-1.fth
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
0 CONSTANT apple
|
||||
1 CONSTANT banana
|
||||
2 CONSTANT cherry
|
||||
...
|
||||
1
Task/Enumerations/Forth/enumerations-2.fth
Normal file
1
Task/Enumerations/Forth/enumerations-2.fth
Normal file
|
|
@ -0,0 +1 @@
|
|||
: ENUM ( n -<name>- n+1 ) DUP CONSTANT 1+ ;
|
||||
1
Task/Enumerations/Forth/enumerations-3.fth
Normal file
1
Task/Enumerations/Forth/enumerations-3.fth
Normal file
|
|
@ -0,0 +1 @@
|
|||
0 ENUM APPLE ENUM BANANA ENUM CHERRY DROP
|
||||
1
Task/Enumerations/Forth/enumerations-4.fth
Normal file
1
Task/Enumerations/Forth/enumerations-4.fth
Normal file
|
|
@ -0,0 +1 @@
|
|||
0 ENUM FIRST ENUM SECOND ... CONSTANT LAST
|
||||
2
Task/Enumerations/Forth/enumerations-5.fth
Normal file
2
Task/Enumerations/Forth/enumerations-5.fth
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
: SIZED-ENUM ( n s -<name>- n+s ) OVER CONSTANT + ;
|
||||
: CELL-ENUM ( n -<name>- n+cell ) CELL SIZED-ENUM ;
|
||||
6
Task/Enumerations/Forth/enumerations-6.fth
Normal file
6
Task/Enumerations/Forth/enumerations-6.fth
Normal 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
|
||||
4
Task/Enumerations/Forth/enumerations-7.fth
Normal file
4
Task/Enumerations/Forth/enumerations-7.fth
Normal 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
|
||||
4
Task/Enumerations/Fortran/enumerations-1.f
Normal file
4
Task/Enumerations/Fortran/enumerations-1.f
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
enum, bind(c)
|
||||
enumerator :: one=1, two, three, four, five
|
||||
enumerator :: six, seven, nine=9
|
||||
end enum
|
||||
3
Task/Enumerations/Fortran/enumerations-2.f
Normal file
3
Task/Enumerations/Fortran/enumerations-2.f
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
enum, bind(c) :: nametype
|
||||
enumerator :: one=1, two, three
|
||||
end enum nametype
|
||||
17
Task/Enumerations/FreeBASIC/enumerations.basic
Normal file
17
Task/Enumerations/FreeBASIC/enumerations.basic
Normal 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
|
||||
23
Task/Enumerations/FutureBasic/enumerations.basic
Normal file
23
Task/Enumerations/FutureBasic/enumerations.basic
Normal 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
|
||||
5
Task/Enumerations/Go/enumerations-1.go
Normal file
5
Task/Enumerations/Go/enumerations-1.go
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
const (
|
||||
apple = iota
|
||||
banana
|
||||
cherry
|
||||
)
|
||||
5
Task/Enumerations/Go/enumerations-2.go
Normal file
5
Task/Enumerations/Go/enumerations-2.go
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
const (
|
||||
apple = 0
|
||||
banana = 1
|
||||
cherry = 2
|
||||
)
|
||||
7
Task/Enumerations/Go/enumerations-3.go
Normal file
7
Task/Enumerations/Go/enumerations-3.go
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
type fruit int
|
||||
|
||||
const (
|
||||
apple fruit = iota
|
||||
banana
|
||||
cherry
|
||||
)
|
||||
7
Task/Enumerations/Go/enumerations-4.go
Normal file
7
Task/Enumerations/Go/enumerations-4.go
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
type fruit int
|
||||
|
||||
const (
|
||||
apple fruit = 0
|
||||
banana fruit = 1
|
||||
cherry fruit = 2
|
||||
)
|
||||
11
Task/Enumerations/Groovy/enumerations.groovy
Normal file
11
Task/Enumerations/Groovy/enumerations.groovy
Normal 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()
|
||||
1
Task/Enumerations/Haskell/enumerations.hs
Normal file
1
Task/Enumerations/Haskell/enumerations.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
data Fruit = Apple | Banana | Cherry deriving Enum
|
||||
5
Task/Enumerations/Huginn/enumerations.huginn
Normal file
5
Task/Enumerations/Huginn/enumerations.huginn
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
enum FRUIT {
|
||||
APPLE,
|
||||
BANANA,
|
||||
CHERRY
|
||||
}
|
||||
6
Task/Enumerations/Icon/enumerations.icon
Normal file
6
Task/Enumerations/Icon/enumerations.icon
Normal 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
|
||||
1
Task/Enumerations/Inform-7/enumerations-1.inf
Normal file
1
Task/Enumerations/Inform-7/enumerations-1.inf
Normal file
|
|
@ -0,0 +1 @@
|
|||
Fruit is a kind of value. The fruits are apple, banana, and cherry.
|
||||
6
Task/Enumerations/Inform-7/enumerations-2.inf
Normal file
6
Task/Enumerations/Inform-7/enumerations-2.inf
Normal 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.
|
||||
8
Task/Enumerations/Inform-7/enumerations-3.inf
Normal file
8
Task/Enumerations/Inform-7/enumerations-3.inf
Normal 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
|
||||
4
Task/Enumerations/J/enumerations-1.j
Normal file
4
Task/Enumerations/J/enumerations-1.j
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
enum =: cocreate''
|
||||
( (;:'apple banana cherry') ,L:0 '__enum' ) =: i. 3
|
||||
cherry__enum
|
||||
2
|
||||
1
Task/Enumerations/J/enumerations-2.j
Normal file
1
Task/Enumerations/J/enumerations-2.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
fruit=: ;:'apple banana cherry'
|
||||
4
Task/Enumerations/J/enumerations-3.j
Normal file
4
Task/Enumerations/J/enumerations-3.j
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
2 { fruit
|
||||
+------+
|
||||
|cherry|
|
||||
+------+
|
||||
2
Task/Enumerations/J/enumerations-4.j
Normal file
2
Task/Enumerations/J/enumerations-4.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fruit i.<'banana'
|
||||
1
|
||||
4
Task/Enumerations/J/enumerations-5.j
Normal file
4
Task/Enumerations/J/enumerations-5.j
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(<'banana') +&.(fruit&i.) <'banana'
|
||||
+------+
|
||||
|cherry|
|
||||
+------+
|
||||
4
Task/Enumerations/J/enumerations-6.j
Normal file
4
Task/Enumerations/J/enumerations-6.j
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{{for_example. fruit do. echo;example end.}} ''
|
||||
apple
|
||||
banana
|
||||
cherry
|
||||
2
Task/Enumerations/JScript.NET/enumerations.jscript
Normal file
2
Task/Enumerations/JScript.NET/enumerations.jscript
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
enum fruits { apple, banana, cherry }
|
||||
enum fruits { apple = 0, banana = 1, cherry = 2 }
|
||||
3
Task/Enumerations/Java/enumerations-1.java
Normal file
3
Task/Enumerations/Java/enumerations-1.java
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
enum Fruits{
|
||||
APPLE, BANANA, CHERRY
|
||||
}
|
||||
6
Task/Enumerations/Java/enumerations-2.java
Normal file
6
Task/Enumerations/Java/enumerations-2.java
Normal 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; }
|
||||
}
|
||||
7
Task/Enumerations/JavaScript/enumerations.js
Normal file
7
Task/Enumerations/JavaScript/enumerations.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// enum fruits { apple, banana, cherry }
|
||||
|
||||
var f = "apple";
|
||||
|
||||
if(f == "apple"){
|
||||
f = "banana";
|
||||
}
|
||||
1
Task/Enumerations/Julia/enumerations.julia
Normal file
1
Task/Enumerations/Julia/enumerations.julia
Normal file
|
|
@ -0,0 +1 @@
|
|||
@enum Fruits APPLE BANANA CHERRY
|
||||
15
Task/Enumerations/Kotlin/enumerations.kotlin
Normal file
15
Task/Enumerations/Kotlin/enumerations.kotlin
Normal 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}")
|
||||
}
|
||||
32
Task/Enumerations/Lingo/enumerations-1.lingo
Normal file
32
Task/Enumerations/Lingo/enumerations-1.lingo
Normal 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
|
||||
34
Task/Enumerations/Lingo/enumerations-2.lingo
Normal file
34
Task/Enumerations/Lingo/enumerations-2.lingo
Normal 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>
|
||||
1
Task/Enumerations/Lua/enumerations-1.lua
Normal file
1
Task/Enumerations/Lua/enumerations-1.lua
Normal file
|
|
@ -0,0 +1 @@
|
|||
local fruit = {apple = 0, banana = 1, cherry = 2}
|
||||
1
Task/Enumerations/Lua/enumerations-2.lua
Normal file
1
Task/Enumerations/Lua/enumerations-2.lua
Normal file
|
|
@ -0,0 +1 @@
|
|||
local apple, banana, cherry = 0,1,2
|
||||
56
Task/Enumerations/M2000-Interpreter/enumerations.m2000
Normal file
56
Task/Enumerations/M2000-Interpreter/enumerations.m2000
Normal 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
|
||||
6
Task/Enumerations/M4/enumerations.m4
Normal file
6
Task/Enumerations/M4/enumerations.m4
Normal 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
|
||||
5
Task/Enumerations/MATLAB/enumerations.m
Normal file
5
Task/Enumerations/MATLAB/enumerations.m
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
stuff = {'apple', [1 2 3], 'cherry',1+2i}
|
||||
|
||||
stuff =
|
||||
|
||||
'apple' [1x3 double] 'cherry' [1.000000000000000 + 2.000000000000000i]
|
||||
11
Task/Enumerations/Mathematica/enumerations.math
Normal file
11
Task/Enumerations/Mathematica/enumerations.math
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
MapIndexed[Set, {A, B, F, G}]
|
||||
->{{1}, {2}, {3}, {4}}
|
||||
|
||||
A
|
||||
->{1}
|
||||
|
||||
B
|
||||
->{2}
|
||||
|
||||
G
|
||||
->{4}
|
||||
4
Task/Enumerations/Metafont/enumerations-1.metafont
Normal file
4
Task/Enumerations/Metafont/enumerations-1.metafont
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
vardef enum(expr first)(text t) =
|
||||
save ?; ? := first;
|
||||
forsuffixes e := t: e := ?; ?:=?+1; endfor
|
||||
enddef;
|
||||
5
Task/Enumerations/Metafont/enumerations-2.metafont
Normal file
5
Task/Enumerations/Metafont/enumerations-2.metafont
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
enum(1, Apple, Banana, Cherry);
|
||||
enum(5, Orange, Pineapple, Qfruit);
|
||||
show Apple, Banana, Cherry, Orange, Pineapple, Qfruit;
|
||||
|
||||
end
|
||||
1
Task/Enumerations/Modula-3/enumerations-1.mod3
Normal file
1
Task/Enumerations/Modula-3/enumerations-1.mod3
Normal 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
Loading…
Add table
Add a link
Reference in a new issue