[plt-scheme] Define in define

From: Ahmad Issa (ahmadissa at gmail.com)
Date: Tue Sep 19 02:32:08 EDT 2006

Hi, i'm using MzScheme, with my code:

(define (partition n)
    (define results (make-vector (+ n 1)))
    (define (update cur max val)
        (vector-set! (vector-ref results cur) max val)
        val)

    (let loop ((i 0))
        (cond ((> i n) 0)
              (else (vector-set! results i (make-vector (+ n 1) 0))
                      (loop (+ i 1)))))

    (define (part cur max)
        (cond ((= cur 0) 1)
              ((not (= (vector-ref (vector-ref results cur) max) 0))
                      (vector-ref (vector-ref results cur) max))
              (else (update cur max (let loop ((i 1))
                      (cond ((or (> i max) (> i cur)) 0)
                              (else (+ (part (- cur i) i)
                                         (loop (+ i 1)))))))))))

I receive the error "define: not allowed in an expression context in:
(define (part cur max) (cond ((= cur 0) 1) ((not (= (vector-ref (vector-ref
results cur) max) 0))...", why can't I put a define in a define after a let
statement?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20060919/fe7fc2de/attachment.html>

Posted on the users mailing list.