guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: In search of cool Scheme


From: Harvey J. Stein
Subject: Re: In search of cool Scheme
Date: 23 May 2001 11:22:59 -0400

"Hans O. Lowe" <address@hidden> writes:

 > Sam & Klaus,
 > 
 > I don't know about doing it with data stream and delayed evaluation,
 > but I was thinking of something simple like this:
 > 
 > (define (differentiate y)
 >   (if (list? y) 
 >       (cond ((eq? (car y) '+) (cons '+ (map differentiate (cdr y))))
 >             ((eq? (car y) '-) (cons '- (map differentiate (cdr y))))
 >             ((eq? (car y) 'sin) (list '*
 >                                       (list 'cos (cadr y))
 >                                       (differentiate (cadr y))))
 >             (else 'y))
 >       (cond ((number? y) 0)
 >             ((eq? y 'x) 1)
 >             (else (list 'differentiate y)))))
 > 
 > ;;; Try this:
 >   (display (differentiate '(4 x (sin u))))

Don't forget to add in a macro to do:

   (let ((x 3) (u 4)) (eval (differentiate '(* x (sin u)))))

   
-- 
Harvey Stein
Bloomberg LP
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]