2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

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

View file

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

View file

@ -1,10 +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
Dict.has_key?(fruits, :banana) #=> true
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)
Dict.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

@ -1,2 +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

@ -2,7 +2,7 @@ enum Fruit <Apple Banana Cherry>; # Numbered 0 through 2.
enum ClassicalElement (
Earth => 5,
'Air', # Gets the value 6.
Fire => 'hot',
Water => 'wet'
'Air', # gets the value 6
'Fire', # gets the value 7
Water => 10,
);

View file

@ -0,0 +1,8 @@
Enum fruits {
Apple
Banana
Cherry
}
[fruits]::Apple
[fruits]::Apple + 1
[fruits]::Banana + 1

View file

@ -0,0 +1,8 @@
Enum fruits {
Apple = 10
Banana = 15
Cherry = 30
}
[fruits]::Apple
[fruits]::Apple + 1
[fruits]::Banana + 1

View file

@ -1,50 +1,55 @@
/*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 */
/*REXX program illustrates a method of enumeration of constants via stemmed arrays. */
fruit.=0 /*the default for all possible "FRUITS." (zero). */
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 be specified as: 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 ')
/*A method of using a list (of some fruits).*/
@fruits= 'apple apricot avocado banana bilberry blackberry blackcurrant blueberry baobab',
'boysenberry breadfruit cantaloupe cherry chilli chokecherry citron coconut',
'cranberry cucumber currant date dragonfruit durian eggplant elderberry fig',
'feijoa gac gooseberry grape grapefruit guava honeydew huckleberry jackfruit',
'jambul juneberry kiwi kumquat lemon lime lingenberry loquat lychee mandarin',
'mango mangosteen nectarine orange papaya passionfruit peach pear persimmon',
'physalis pineapple pitaya pomegranate pomelo plum pumpkin rambutan raspberry',
'redcurrant satsuma squash strawberry tangerine tomato ugli watermelon zucchini'
/*╔════════════════════════════════════════════════════════════════════════════════════╗
Parental warning: sex is discussed below: PG13. 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; it was*/
/* ↓ called the Panama disease (a soil─borne fungus)*/
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.' /* " */
if fruit.peach\=0 then say "We gots " fruit.peach ' fuzzy fruit.' /* " */
maxL=length(' fruit ') /*ensure this header title can be shown*/
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.*/
do p =0 for 2 /*the first pass finds the maximums. */
do j=1 for words(@fruits) /*process each of the names of fruits. */
@=word(@fruits, j) /*obtain a fruit name from the list. */
#=value('FRUIT.'@) /* " the quantity of a fruit. */
if \p then do /*is this the first pass through ? */
maxL=max(maxL, length(@)) /*the longest (widest) name of a fruit.*/
maxQ=max(maxQ, length(#)) /*the widest width quantity of fruit. */
iterate /*j*/ /*now, go get another name of a fruit. */
end
if j==1 then say center('fruit', maxL) center("quantity", maxQ)
if j==1 then say copies('' , maxL) copies("" , maxQ)
if #\=0 then say right( @ , maxL) right( # , maxQ)
end /*j*/
end /*p*/
/*stick a fork in it, we're all done. */