From: Gavin E. Gleason
Subject: Derivitive's using CLOS
Date: 
Message-ID: <87vhbww02a.fsf@hasdrubal.unm.edu>
I was writing a differentiation function, and started thinking that
maybe it would be better if I wrote it in CLOS thinking that new
methods could then be easily added for new functions.  However I soon
ran into some conceptual problems. 

Ideally I want the form that is being differentiated to be a standard
lisp arethmetic expression so that variables can be bound and
evaluated, after the derivitive is found.  How do you specialize on
the functions given these constraints in CLOS?

P.S.  This is most definitely not a homework assignment. 

-- 
"Syntactic sugar causes cancer of the semicolon."
	-Alan Perlis
From: Barry Margolin
Subject: Re: Derivitive's using CLOS
Date: 
Message-ID: <e%Rg3.1192$KM3.287899@burlma1-snr2>
In article <··············@hasdrubal.unm.edu>,
Gavin E. Gleason <········@unm.edu> wrote:
>
>I was writing a differentiation function, and started thinking that
>maybe it would be better if I wrote it in CLOS thinking that new
>methods could then be easily added for new functions.  However I soon
>ran into some conceptual problems. 
>
>Ideally I want the form that is being differentiated to be a standard
>lisp arethmetic expression so that variables can be bound and
>evaluated, after the derivitive is found.  How do you specialize on
>the functions given these constraints in CLOS?

I would use EQL specializers on the symbols, e.g.

(defmethod differentiate-function-call ((function (eql +)) args)
  (list* '+ (mapcar #'differentiate args)))

(defmethod differentiate ((expression number))
  0)

(defmethod differentiate ((expression symbol))
  (if (variablep symbol)
      1
      symbol))     

(defmethod differentiate ((expression cons))
  (differentiate-function-call (car expression) (cdr expression)))

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.