CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
1
Task/Enumerations/0DESCRIPTION
Normal file
1
Task/Enumerations/0DESCRIPTION
Normal file
|
|
@ -0,0 +1 @@
|
|||
Create an enumeration of constants with and without explicit values.
|
||||
2
Task/Enumerations/1META.yaml
Normal file
2
Task/Enumerations/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Basic language learning
|
||||
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
|
||||
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
|
||||
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.bas
Normal file
16
Task/Enumerations/BASIC/enumerations.bas
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
|
||||
3
Task/Enumerations/C++/enumerations.cpp
Normal file
3
Task/Enumerations/C++/enumerations.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.c
Normal file
3
Task/Enumerations/C/enumerations.c
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
enum fruits { apple, banana, cherry };
|
||||
|
||||
enum fruits { apple = 0, banana = 1, cherry = 2 };
|
||||
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+))
|
||||
17
Task/Enumerations/D/enumerations.d
Normal file
17
Task/Enumerations/D/enumerations.d
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Anonymous
|
||||
enum { APPLE, BANANA, CHERRY }
|
||||
|
||||
// Named (commonlu used enum in D) (uint)
|
||||
enum Fruits1 { apple, banana, cherry }
|
||||
|
||||
// Named with specified values (uint)
|
||||
enum Fruits2 { apple = 0, banana = 10, cherry = 20 }
|
||||
|
||||
// Named, typed and with specified values
|
||||
enum Fruits3 : ubyte { apple = 0, banana = 100, cherry = 200 }
|
||||
|
||||
void main() {
|
||||
static assert(CHERRY == 2);
|
||||
int f1 = Fruits2.banana; // No error
|
||||
// Fruits2 f2 = 1; // Compilation error
|
||||
}
|
||||
2
Task/Enumerations/DWScript/enumerations.dwscript
Normal file
2
Task/Enumerations/DWScript/enumerations.dwscript
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
type TFruit = (Apple, Banana, Cherry);
|
||||
type TApe = (Gorilla = 0, Chimpanzee = 1, Orangutan = 5);
|
||||
4
Task/Enumerations/Delphi/enumerations.delphi
Normal file
4
Task/Enumerations/Delphi/enumerations.delphi
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
type
|
||||
TFruit = (Apple, Banana, Cherry);
|
||||
|
||||
TApe = (Gorilla = 0, Chimpanzee = 1, Orangutan = 5);
|
||||
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
|
||||
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
|
||||
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
|
||||
)
|
||||
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
|
||||
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; }
|
||||
}
|
||||
1
Task/Enumerations/JavaScript/enumerations.js
Normal file
1
Task/Enumerations/JavaScript/enumerations.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
var fruits = { apple : 0, banana : 1, cherry : 2 };
|
||||
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
|
||||
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]
|
||||
18
Task/Enumerations/PHP/enumerations.php
Normal file
18
Task/Enumerations/PHP/enumerations.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// Using an array/hash
|
||||
$fruits = array( "apple", "banana", "cherry" );
|
||||
$fruits = array( "apple" => 0, "banana" => 1, "cherry" => 2 );
|
||||
|
||||
// If you are inside a class scope
|
||||
class Fruit {
|
||||
const APPLE = 0;
|
||||
const BANANA = 1;
|
||||
const CHERRY = 2;
|
||||
}
|
||||
|
||||
// Then you can access them as such
|
||||
$value = Fruit::APPLE;
|
||||
|
||||
// Or, you can do it using define()
|
||||
define("FRUIT_APPLE", 0);
|
||||
define("FRUIT_BANANA", 1);
|
||||
define("FRUIT_CHERRY", 2);
|
||||
5
Task/Enumerations/Perl/enumerations.pl
Normal file
5
Task/Enumerations/Perl/enumerations.pl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Using an array
|
||||
my @fruits = qw(apple banana cherry);
|
||||
|
||||
# Using a hash
|
||||
my %fruits = ( apple => 0, banana => 1, cherry => 2 );
|
||||
2
Task/Enumerations/PicoLisp/enumerations-1.l
Normal file
2
Task/Enumerations/PicoLisp/enumerations-1.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(de enum "Args"
|
||||
(mapc def "Args" (range 1 (length "Args"))) )
|
||||
2
Task/Enumerations/PicoLisp/enumerations-2.l
Normal file
2
Task/Enumerations/PicoLisp/enumerations-2.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
: (enum A B C D E F)
|
||||
-> F
|
||||
1
Task/Enumerations/Python/enumerations-1.py
Normal file
1
Task/Enumerations/Python/enumerations-1.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
FIRST_NAME, LAST_NAME, PHONE = range(3)
|
||||
1
Task/Enumerations/Python/enumerations-2.py
Normal file
1
Task/Enumerations/Python/enumerations-2.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
vars().update((key,val) for val,key in enumerate(("FIRST_NAME","LAST_NAME","PHONE")))
|
||||
3
Task/Enumerations/R/enumerations.r
Normal file
3
Task/Enumerations/R/enumerations.r
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
factor(c("apple", "banana", "cherry"))
|
||||
# [1] apple banana cherry
|
||||
# Levels: apple banana cherry
|
||||
50
Task/Enumerations/REXX/enumerations.rexx
Normal file
50
Task/Enumerations/REXX/enumerations.rexx
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*REXX program to illustrate enumeration of constants via stemmed arrays*/
|
||||
fruit.=0 /*the default for all "FRUITS." */
|
||||
fruit.apple = 65
|
||||
fruit.cherry = 4
|
||||
fruit.kiwi = 12
|
||||
fruit.peach = 48
|
||||
fruit.plum = 50
|
||||
fruit.raspberry = 17
|
||||
fruit.tomato = 8000
|
||||
fruit.ugli = 2
|
||||
fruit.watermelon = 0.5 /*could also specify: 1/2 */
|
||||
|
||||
/*A partial list of some fruits (below). */
|
||||
/* [↓] This is one method of using a list. */
|
||||
FruitList='apple apricot avocado banana bilberry blackberry blackcurrent blueberry baobab boysenberry breadfruit cantalope cherry chilli chokecherry citront',
|
||||
'coconut cranberry cucumber current date dragonfruit durian eggplant elderberry fig feijoa gac gooseberry grape grapefruit guava honeydew huckleberry jackfruit',
|
||||
'jambul juneberry kiwi kumquat lemon lime lingenberry loquat lychee mandarine mango mangosteen netarine orange papaya passionfruit peach pear persimmon',
|
||||
'physalis pineapple pitaya pomegranate pomelo plum pumpkin rambutan raspberry redcurrent satsuma squash strawberry tangerine tomato ugli watermelon zucchini'
|
||||
/*┌────────────────────────────────────────────────────────────────────┐
|
||||
│ Spoiler alert: sex is discussed below: PG-13. Most berries don't │
|
||||
│ have "berry" in their name. A berry is a simple fruit produced │
|
||||
│ from a single ovary. Some true berries are: pomegranate, guava, │
|
||||
│ eggplant, tomato, chilli, pumpkin, cucumber, melon, and citruses. │
|
||||
│ Blueberry is a false berry, blackberry is an aggregate fruit, │
|
||||
│ and strawberry is an accessory fruit. Most nuts are fruits. │
|
||||
│ The following aren't true nuts: almond, cashew, coconut, │
|
||||
│ macadamia, peanut, pecan, pistachio, and walnut. │
|
||||
└────────────────────────────────────────────────────────────────────┘*/
|
||||
/* [↓] due to a Central America blight in 1922.*/
|
||||
if fruit.banana=0 then say "Yes! We have no bananas today." /*(sic)*/
|
||||
if fruit.kiwi \=0 then say "We gots" fruit.kiwi "hairy fruit." /*(sic)*/
|
||||
if fruit.peach\=0 then say "We gots" fruit.peach "fuzzy fruit." /*(sic)*/
|
||||
maxL = length(' fruit ')
|
||||
maxQ = length(' quantity ')
|
||||
say
|
||||
do pass=1 for 2 /*first pass finds the maximums. */
|
||||
do j=1 for words(FruitList)
|
||||
f=word(FruitList,j) /*get a fruit name from the list.*/
|
||||
q=value('FRUIT.'f)
|
||||
if pass==1 then do /*widest fruit name and quantity.*/
|
||||
maxL=max(maxL,length(f)) /*longest fruit name*/
|
||||
maxQ=max(maxQ,length(q)) /*widest fruit quant*/
|
||||
iterate /*j*/
|
||||
end
|
||||
if j==1 then say center('fruit',maxL) center('quantity',maxQ)
|
||||
if j==1 then say copies('─',maxL) copies('─',maxQ)
|
||||
if q\=0 then say right(f,maxL) right(q,maxQ)
|
||||
end /*j*/
|
||||
end /*pass*/
|
||||
/*stick a fork in it, we're done.*/
|
||||
5
Task/Enumerations/Ruby/enumerations.rb
Normal file
5
Task/Enumerations/Ruby/enumerations.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
module Fruits
|
||||
APPLE = 0
|
||||
BANANA = 1
|
||||
CHERRY = 2
|
||||
end
|
||||
4
Task/Enumerations/Scala/enumerations-1.scala
Normal file
4
Task/Enumerations/Scala/enumerations-1.scala
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
sealed abstract class Fruit
|
||||
case object Apple extends Fruit
|
||||
case object Banana extends Fruit
|
||||
case object Cherry extends Fruit
|
||||
3
Task/Enumerations/Scala/enumerations-2.scala
Normal file
3
Task/Enumerations/Scala/enumerations-2.scala
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
object Fruit extends Enumeration {
|
||||
val Apple, Banana, Cherry = Value
|
||||
}
|
||||
8
Task/Enumerations/Scheme/enumerations.ss
Normal file
8
Task/Enumerations/Scheme/enumerations.ss
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(define apple 0)
|
||||
(define banana 1)
|
||||
(define cherry 2)
|
||||
|
||||
(define (fruit? atom)
|
||||
(or (equal? 'apple atom)
|
||||
(equal? 'banana atom)
|
||||
(equal? 'cherry atom)))
|
||||
4
Task/Enumerations/Tcl/enumerations-1.tcl
Normal file
4
Task/Enumerations/Tcl/enumerations-1.tcl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
proc enumerate {name values} {
|
||||
interp alias {} $name: {} lsearch $values
|
||||
interp alias {} $name@ {} lindex $values
|
||||
}
|
||||
6
Task/Enumerations/Tcl/enumerations-2.tcl
Normal file
6
Task/Enumerations/Tcl/enumerations-2.tcl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
enumerate fruit {apple blueberry cherry date elderberry}
|
||||
|
||||
fruit: date
|
||||
# ==> prints "3"
|
||||
fruit@ 2
|
||||
# ==> prints "cherry"
|
||||
Loading…
Add table
Add a link
Reference in a new issue