<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
I'm using for the first time DrScheme and I want to run the code I've written
with mit-scheme.<br>
I've problems with internal definitions. For example I can't load the following
definition:<br>
<blockquote><code></code></blockquote>
<pre>(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'
</pre>
Looking at '<a
href="http://127.0.0.1:8000/doc/r5rs/r5rs-Z-H-2.html#%_toc_%_sec_5.2.2">5.2.2 Internal
definitions' of </a>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.<br>
<br>
<pre>(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
</pre>
<pre>
</pre>
<br>
<pre>
</pre>
<br>
</body>
</html>