Forum OpenACS Q&A: Re: Problem set 1 - Exercise 2

Collapse
Posted by Michael Bluett on
I too am looking through the pset, having been through it on an Ars Digita bootcamp way back. Some of the links in the psets are broken, but can be found by searching archive.org for the URLs, and going back to about Feb 2002 for a working copy.

My answer to the aquarium problem was:

proc createAquariumRow {title cost number} {
	return [list $title $cost $number]
}

proc returnAquariumTitle {aquarium} {
	return [lindex $aquarium 0]
}

proc returnAquariumCost {aquarium} {
	return [lindex $aquarium 1]
}

proc returnAquariumNumber {aquarium} {
	return [lindex $aquarium 2]
}

proc returnAquariumSubtotal {aquarium} {
	return [expr [returnAquariumNumber $aquarium] * [returnAquariumCost $aquarium] ]
}

set aquarium_types_and_costs \
   [list [createAquariumRow "Lake Malawi Cichlid" 5000 2] \
         [createAquariumRow "Saltwater Community" 7000 3] \
         [createAquariumRow "Reef" 10000 4] \
         [createAquariumRow "Planted Freshwater" 6000 10] \
         [createAquariumRow "Suspended-in-midair Stingray Pond" 45000 1] \
         [createAquariumRow "Fish Tank" 1 1] \
   ]
If you have any other questions, just ask.