[plt-scheme] problem with internal definitions

From: Giannandrea Castaldi (g.castal at tiscali.it)
Date: Mon Jan 20 07:06:42 EST 2003

I'm using for the first time DrScheme and I want to run the code I've 
written with mit-scheme.
I've problems with internal definitions. For example I can't load the 
following definition:

(define (make-account balance)
    (define (deposit amount)
      (begin (set! balance (+ balance amount))
             balance))
    (define (withdraw amount)
      (if (>= balance amount)
          (begin (set! balance (- balance amount))
                 balance)
          "Insufficient funds"))
    (define (dispatch m)
      (cond ((eq? m 'deposit) deposit)
            ((eq? m 'withdraw) withdraw)
            (else (error "Unknown request - MAKE-ACCOUNT" m))))
    dispatch)

The error is: 'define: found a definition that is not at the top level'

Looking at '5.2.2  Internal definitions' of 
<http://127.0.0.1:8000/doc/r5rs/r5rs-Z-H-2.html#%_toc_%_sec_5.2.2>Revised 
Report on the Algorithmic Language Scheme I should rewrite my code in 
the following manner but it doesn't work anyway and gives me the same error.

(define (make-account balance)
  (let ()
    (
     (define deposit (lambda (amount)
       (begin (set! balance (+ balance amount))
	      balance)))
     (define withdraw (lambda (amount)
       (if (>= balance amount)
	   (begin (set! balance (- balance amount))
		  balance)
	   "Insufficient funds")))
     (define dispatch (lambda (m)
       (cond ((eq? m 'deposit) deposit)
	     ((eq? m 'withdraw) withdraw)
	     (else (error "Unknown request - MAKE-ACCOUNT" m)))))
    dispatch)))

What's wrong in my code? Can't DrScheme load my orginal code as mit-scheme?

Thanks a lot.

Giannandrea Castaldi






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20030120/b00920cd/attachment.html>

Posted on the users mailing list.