Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion resonable use of internal functions

From: Friedrich Dominicus <Friedrich.Domini...@inka.de>
Subject: resonable use of internal functions
Date: 1999/11/16
Message-ID: <38318307.B1B8D1B1@inka.de>#1/1
X-Deja-AN: 549317954
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: newsmaster@inka.de
X-Trace: sapa.inka.de 942769583 6711 212.227.14.197 (16 Nov 1999 16:26:23 GMT)
Organization: Friedrich Dominicus
Mime-Version: 1.0
Reply-To: Friedrich.Domini...@inka.de
NNTP-Posting-Date: 16 Nov 1999 16:26:23 GMT
Newsgroups: comp.lang.lisp

On a question in an newsgroup about algorithms on asked for an
algrorithms from sin. I grabbed my old Bronstein and found a definiton
there. I tried to translate that into Common Lisp (I'm aware, that sin
is there ready for use, I just take it as an exercise for me;-)

So I come up with this implementation

(defun sine (x)
  (flet ((next-factor (val n)
		(+ val (* (expt -1 n)  
			  (/ (expt x (+ (* 2 n) 1)) 
			     (fact (+ (* 2 n) 1)))))))
	(labels ((inner-sine (val n)
		  (let ((new-val (next-factor val n)))
		      (if (good-enough (abs val) (abs new-val))
			   (float new-val)
			(inner-sine new-val (1+ n))))))
	  (inner-sine 0 0))))

My question is about the style in which it is written and if the usage
of inner functions seems to be appropriate here.

And I have another questoin about flet and labels. And I wonder if there
is a case where I just can use flet but not labels. Just for the fun of
it (and despite what was writte in the Hyperspec), I changed the labels
before inner-sine to flet and of course then this function can't be
found. But I really don't know when I should use flet and labels. In
recursive functions the answer is clear, I just can use labels but
instead of flet I used labels and that worked quite fine. So some
comments would be very welcome

Regards
Friedrich