Re: Newbie problem: invalid context for definition

"Scott G. Miller" <[email protected]> Mon, 16 Apr 2007 14:07:43 -0500
Newsgroups gmane.comp.java.sisc.user
Message-ID <[email protected]>
On Mon, Apr 16, 2007 at 08:55:15PM +0200, Jon Kleiser wrote:
> When I try this little program, using sisc-1.16.6, ...
> 
> (define desc-series
> 	(lambda (size)
> 		(let countdown ((n size) (s ()))
> 			(if (= n 0) s
> 				(countdown (- n 1) (append s (list n)))))))
> 
> (define do-from-to
> 	(lambda (m n)
> 		(let loop ((i m))
> 			(begin
> 				(define i2 (* i i)) (display i2) (newline)
> 				(define ds (desc-series i2)) (display ds) (newline) ;problem
> 				(if (= i n) 'done
> 					(loop (+ i 1)))))))
> 
> (do-from-to 2 4)
> 
> ... I get this:

In Scheme, nested definitions can only appear at the beginning of a 
begin.  As soon as you have a non-definition expression, you are no 
longer in definition context and any later definition is illegal.  So, 
in your program above, the (display i2) expression is the first 
non-definition expression.

Scott

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/