Previously we defined a list of symbols as

   ;; A list-of-symbol is either
   ;;   - empty, or
   ;;   - (make-lst name los)
   ;;     where name is a symbol and los is a list-of-symbol

   (define-struct lst (first rest))

and used

   make-lst, lst-first, lst-rest, lst?

Scheme has these built-in, but with different names.  We used the
above definition to emphasize that lists are simply a particular
use of structures.  Now we will write

   ;; A list-of-symbol is either
   ;;   - empty, or
   ;;   - (cons name los)
   ;;     where name is a symbol and los is a list-of-symbol

and replace

   make-lst   ->  cons
   lst-first  ->  first
   lst-rest   ->  rest
   lst?       ->  cons?

No define-struct is needed for cons since it is built-in.


Finish stepping through the previous example of count-services.


Previously looked at Bubba-serve? example.  Let's extend it.
Let's have one function that answers whether a mechanic has
serviced a plane, for any mechanic.  Here's the template, again
just the same except for there's a second argument for the name
of the mechanic.

   ;; mechanic-serve? : list-of-symbol symbol -> bool
   ;; determine whether the mechanic is one on the list
   (define (mechanic-serve? a-los mech)
      (cond [(empty? a-los) ...]
            [(lst? a-los)   ...(first a-los)
                            ...(mechanic-serve? (rest a-los))...]))

But there's a problem here.  mechanic-serve? takes two arguments.
What's an appropriate second argument in the recursive call?

   ;; mechanic-serve? : list-of-symbol symbol -> bool
   ;; determine whether the mechanic is one on the list
   (define (mechanic-serve? a-los mech)
      (cond [(empty? a-los) ...]
            [(lst? a-los)   ...(first a-los)
                            ...(mechanic-serve? (rest a-los) mech)...]))

The finished function looks very similar to Bubba-serve?, except that
it looks for mech.

   ;; mechanic-serve? : list-of-symbol symbol -> bool
   ;; determine whether the mechanic is one on the list
   (define (mechanic-serve? a-los mech)
      (cond [(empty? a-los) false]
            [(lst? a-los)   (cond [(symbol=? (first a-los) mech) true]
                                  [else (mechanic-serve? (rest a-los)
                                                         mech)])]))



Another example, looking at our previous definition of flying objects.
What is the total capacity of a list of flying objects?  The 
can get the data definition of such a list by just modifying the
data definition of a list of symbols:

   ;; A list-of-flying-object is either
   ;;   - empty, or
   ;;   - (cons name los)
   ;;     where name is a flying-object and los is a list-of-flying-object

   (define (total-capacity alofo)
     (cond [(empty? alofo) ...]
           [(cons? alofo)  ...(first alofo)
                           ...(total-capacity (rest alofo))...]))

The template is just the same also.  In fact, this is so straightforward
that we won't always bother repeating this in class.  However you should
on your homeworks, to get more practice.

How would we fill in the template to write our function?  In the empty
case, the list has zero capacity.  In the cons case, we want to add
the capacity of the first flying object to the total capacity of the
rest of the objects.   How do we calculate the capacity of a single
flying object?  That seems complicated enough for a helper function:

   (define (capacity afo)
     (cond [(plane? afo)   (brand-seats (plane-brand afo))]
           [(balloon? afo) (balloon-capacity afo)]
           [(ufo? afo)     (ufo-capacity afo)]))

   (define (total-capacity alofo)
     (cond [(empty? alofo) 0]
           [(cons? alofo)  (+ (capacity (first alofo))
                              (total-capacity (rest alofo)))]))

We want to use a helper function because it is easier to understand
if you separate the ideas.  capacity calculates the capacity for
one flying object and follows the structure of a flying-object.
total-capacity calculates the capacity for a bunch of flying objects
and follows the structure of a list-of-flying-object.  We might
want to use capacity in other programs as well.  Easier to test
separately.