This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

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,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,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,2 @@
enum fruits { apple, banana, cherry }
enum fruits { apple = 0, banana = 1, cherry = 2 }

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,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};

View file

@ -0,0 +1 @@
fruit := Fruit.Apple;

View file

@ -0,0 +1,2 @@
ORD(Fruit.Apple); (* Returns 0 *)
VAL(0, Fruit); (* Returns Fruit.Apple *)