80 likes | 100 Views
Common Lisp!. John Paxton Montana State University Summer 2003. Montana National Parks. Yellowstone Glacier. Structure Declaration. (defstruct city name country (population 100000) ). Structure Creation. > (setf san-salvador (make-city))
E N D
Common Lisp! John Paxton Montana State University Summer 2003
Montana National Parks • Yellowstone • Glacier
Structure Declaration (defstruct city name country (population 100000) )
Structure Creation > (setf san-salvador (make-city)) #S(CITY :NAME NIL :COUNTRY NIL :POPULATION 100000) > (setf bozeman (make-city :population 30000)) #S(CITY :NAME NIL :COUNTRY NIL :POPULATION 30000)
Field Access > (setf (city-country san-salvador) 'el-salvador) EL-SALVADOR
Useful Predicates > (city-p san-salvador) T > (describe san-salvador) #S(CITY :NAME NIL :COUNTRY EL-SALVADOR :POPULATION 100000) is a structure of type CITY. Slots: NAME = NIL COUNTRY = EL-SALVADOR POPULATION = 100000 and more!
Questions • Declare a structure called playing-time that can hold the number of minutes and seconds that a song lasts. • Instantiate an instance of the above structure that plays for 3 minutes and 42 seconds. • Declare another structure called song that can hold the name of a song and its playing-time.
Questions • Instantiate an instance of this previous structure for the 1996 Los del Rio hit, Macarena, which plays for 3 minutes and 12 seconds. • Access the name of the song. • Access the playing-time of the song. • Declare an array that can hold 3 songs. • Assign the above structure to the second slot in the array.