From: Delaregue
Subject: if or defmethod
Date: 
Message-ID: <6b4aa54a.0210040105.16b6e7e4@posting.google.com>
Hello,

I've got several generic functions manipulating dates. The dates are
passed as strings most of the time because the input come from a GUI.
Every so often though, I end up passing an integer instead of a
string.

Is it better to add a method to the generic function to correctly
handle the integer or should I use something like (if (integerp
...)... within the existing method?

Thank you.

From: Fred Gilham
Subject: Re: if or defmethod
Date: 
Message-ID: <u78z1ee0fl.fsf@snapdragon.csl.sri.com>
> Is it better to add a method to the generic function to correctly
> handle the integer or should I use something like (if (integerp
> ...)... within the existing method?

I'd probably do it by having a canonical representation (perhaps a
date class), then have methods that target that canonical
representation converting from the various other formats that you
might have to deal with.

This might be overkill, but the fact that you asked the question seems
to indicate that the design of the date manipulation code is important
to your application.

-- 
Fred Gilham                                         ······@csl.sri.com
The density of a textbook must be inversely proportional to the
density of the students using it. --- Dave Stringer-Calvert
From: Christopher C. Stacy
Subject: Re: if or defmethod
Date: 
Message-ID: <ud6qq9p03.fsf@dtpq.com>
>>>>> On 4 Oct 2002 02:05:14 -0700, Delaregue  ("Delaregue") writes:

 Delaregue> Hello,
 Delaregue> I've got several generic functions manipulating dates. The dates are
 Delaregue> passed as strings most of the time because the input come from a GUI.
 Delaregue> Every so often though, I end up passing an integer instead of a
 Delaregue> string.

 Delaregue> Is it better to add a method to the generic function to correctly
 Delaregue> handle the integer or should I use something like (if (integerp
 Delaregue> ...)... within the existing method?

Some people like to add a method for integers, which converts it
into a date instance and then calls the same generic function.

(defgeneric foo (thingy))

(defmethod foo ((thingy integer))
  (foo (make-instance 'thingy :thing integer)))
From: Andy Reiter
Subject: Re: if or defmethod
Date: 
Message-ID: <d4b78695.0210041919.50244301@posting.google.com>
·········@netscape.net (Delaregue) wrote in message news:<····························@posting.google.com>...
[..]
> Is it better to add a method to the generic function to correctly
> handle the integer or should I use something like (if (integerp
> ...)... within the existing method?

I personally don't know CLOSE -yet- but when I need such multiple-type
handlers, use 'typecase'.


 
> Thank you.