[plt-scheme] too easy question: local/global parameter set!

From: junior schemer (juniorscheme at hotmail.com)
Date: Tue Aug 11 11:11:13 EDT 2009

i just started scheming, and i still got a lot of beginner-questions. 
with this one, i'm blocked for a while, so is there someone who can help me out? 
at first, i present my basic code, at the end, you can see what it should do (and what it doesn't).
my problem is the global set! of a variable (here = item-index) and correctly store this in a list.
is there someone who can make me see the light? 
thank you in advance! 
; i'm using R5RS
(define item-index 0)
(define new-item (vector item-index 'new-item))
(define (index item) (vector-ref item 0))
(define list-of-items '())
(define (add-item item-name)
    (if (empty? list-of-items)
        (begin (set! item-index (+ item-index 1))
               (set! list-of-items (list item-name)))
        (begin (set! item-index (+ item-index 1))
               (vector-set! item-name 0 item-index)
               (set! list-of-items (append list-of-items (list item-name))))))
(add-item new-item)
(add-item new-item)
(add-item new-item)
(add-item new-item)

; should be
; > (#(1 new-item) #(2 new-item) #(3 new-item) #(4 new-item))
; > 4
; but results in
; > (#(4 new-item) #(4 new-item) #(4 new-item) #(4 new-item))
; > 4
Voeg vrienden toe van LinkedIn & Facebook aan je Windows Live
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090811/799d3128/attachment.html>

Posted on the users mailing list.