[racket] Some problem with hash-update!

From: Evgeny Odegov (oev-racket at sibmail.com)
Date: Sat Sep 13 11:45:28 EDT 2014

Oh, I'm wrong. The last code is not equivalent to initial.
The equivalent code has this problem:

(define result (make-hash))
(define big-list (list))
(define (callback dwTextID lpszInfoText lpvUser)
  (if (equal? lpszInfoText "")
      (set! big-list (append big-list (list dwTextID)))
      (hash-update! result
                    lpszInfoText
                    (lambda (id-lst)
                      (define v (list dwTextID))
                      (append id-lst v))
                    '()))
  #t)


The code with `cons' instead `append' works fine:

(define result (make-hash))
(define (callback dwTextID lpszInfoText lpvUser)
  (hash-update! result
                lpszInfoText
                (lambda (id-lst)
                  (define new-id-lst (cons dwTextID id-lst))
                  (unless (list? new-id-lst)

                    (error "~v" new-id-lst))
                  new-id-lst)
                '())
  #t)





Posted on the users mailing list.