Enumerations: Difference between revisions

→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations.
(→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations.)
Line 1,050:
<br>This REXX entry was kinda modeled after the '''BASIC''', '''Forth''', and
'''VBA''' [which does its own enumeration, as does REXX below (as an inventory count)].
<lang rexx>/*REXX program toillustrates a method of illustrate 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 fruit.watermelon = 0.5 /*◄─────────── could also specifybe 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 blackcurrentblackcurrant blueberry baobab boysenberry breadfruit cantalopecantaloupe cherry chilli chokecherry citrontcitron',
'coconut cranberry cucumber currentcurrant date dragonfruit durian eggplant elderberry fig feijoa gac gooseberry grape grapefruit guava honeydew huckleberry jackfruit',
'jambul juneberry kiwi kumquat lemon lime lingenberry loquat lychee mandarinemandarin mango mangosteen netarinenectarine orange papaya passionfruit peach pear persimmon',
'physalis pineapple pitaya pomegranate pomelo plum pumpkin rambutan raspberry redcurrentredcurrant satsuma squash strawberry tangerine tomato ugli watermelon zucchini'
/*┌────────────────────────────────────────────────────────────────────┐
/*╔══════════════════════════════════════════════════════════════════════════════════════╗
SpoilerParental alertwarning: sex is discussed below: PG-13PG─13. Most berries don't have "berry" in ║
│ have "berry" in their name. A berry is a simple fruit produced from a single ovary. Some true ║
│ from a single ovary. Some true berries are: pomegranate, guava, │
║ berries are: pomegranate, guava, eggplant, tomato, chilli, pumpkin, cucumber, melon, and citruses. │
║ 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 ║
│ The following aren't true nuts: almond, cashew, coconut, macadamia, peanut, pecan, pistachio, and walnut.║
╚══════════════════════════════════════════════════════════════════════════════════════╝*/
│ macadamia, peanut, pecan, pistachio, and walnut. │
/* ┌─◄── due to a Central America blight in 1922; it was*/
└────────────────────────────────────────────────────────────────────┘*/
/* [] due to a Central Americacalled blightthe Panama disease (a insoil─borne 1922.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."' /*(sic) " */
if fruit.peach\=0 then say "We gots " fruit.peach " ' fuzzy fruit."' /*(sic) " */
 
maxL = length(' fruit ')
maxL=length(' fruit ') /*ensure this header title can be shown*/
maxQ = length(' quantity ')
maxQ=length(' quantity ') /* " " " " " " " */
say
do passp =10 for 2 /*the first pass finds the maximums. */
do j=1 for words(FruitList) /*process each of the names of fruits. */
f@=word(FruitList, j) /*getobtain a fruit name from the list. */
q#=value('FRUIT.'f@) /* " the quantity of a fruit. */
if pass==1\p then do /*widestis this the first pass through ? fruit name and quantity.*/
maxL=max(maxL, length(f@)) /*the longest fruit(widest) name of a fruit.*/
maxQ=max(maxQ, length(q#)) /*the widest width quantity of fruit. quant*/
iterate /*j*/ iterate /*jnow, 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) , maxL) copies('"'" , maxQ)
if q#\=0 then say right(f @ , maxL) right( # right(q, maxQ)
end /*j*/
end /*passp*/
/*stick a fork in it, we're all done. */</lang>
'''output'''
{{out}}
<pre>
Yes! We have no bananas today.
We gots 12 hairy fruit.
We gots 48 fuzzy fruit.
 
fruit quantity