From: Robert Uhl
Subject: Re: defgeneric, defstruct and no CLOS
Date: 
Message-ID: <m3acgm3oqn.fsf@4dv.net>
verec <·····@mac.com> writes:
>
> I'm again a bit confused. Basically, what I want to do, is to be
> able to define a single "function" name, reused (ie: "redefined")
> for various combinations of arguments such that I can:
>
> (draw conclusion)
> (draw bank-account)
> (draw shape)
>
> I kind of sense that in CL parlance this all what a "generic function"
> is about.

Yup.  You can define a generic function which will choose the right
method to run based on the type of the arguments.  One thing which may
be surprising is that every method must have congruent arguments.

> I get even more confused when I start to consider that in CL, values
> are typed, but identifiers (ie symbols) are not, unless ``(declare
> (sometype x))''
> and I don't see (yet?) how ``overloading'' would work nor how I would
> go about to
> (defun draw (conclusion) ...)
> (defun draw (shape) ...)
> and have the right code be called when a form simply contains
> (draw x)

You create the generic function with DEFGENERIC; you then create each
method with DEFMETHOD (actually, the generic function can be implicitly
created by DEFMETHOD, but it's good practise not to do it that way).
E.g., assuming that you've previously defined classes CONCLUSION,
BANK-ACCOUNT and SHAPE:

(defgeneric draw (x)
  (:documentation "This is a generic draw function which can do lots of
stuff.))

(defmethod draw ((conc conclusion))
  "Draw a conclusion"
  (print "I'm drawing a conclusion!))

(defmethod draw ((acct bank-account))
  "Draw a bank account"
  (print "Ain't banks fun?"))

Or something along those lines.

-- 
Robert Uhl <http://public.xdi.org/=ruhl>
If you stand on your head, you will get footprints in your hair.