[plt-scheme] Undefined Identifier?

From: Robby Findler (robby at cs.uchicago.edu)
Date: Mon Oct 22 15:56:14 EDT 2007

This looks a little bit like a bug that was fixed in the contract
library, so you might want to try getting the latest in SVN.

If that doesn't help, a complete program (preferably small!) that
fails would let me do a more careful investigation.

Thanks,
Robby

On 10/22/07, Adamson, Joel J. <JADAMSON at partners.org> wrote:
> Dear List,
>
> I have a module that works just fine, and then I added a (provide/contract ) and
> now I get these run-time errors.  The other change I made was to import some new
> modules to cover the provide/contract.
>
> > (require "leslie.ss")
> > (define queen   (build-L-hash     delta
>     life-table-gens))
> reference to an identifier before its definition: build-L-hash in module:
> |,/home/joel/lisp/scm/population/leslie|
> > (neXt-gen monkey (make-f64vector 5 100) 10)
> reference to undefined identifier: lifted.3
>
> The module is below.  As far as I can tell, I'm not referencing build-L-hash
> before I define it, except in the provide, which never mattered before.  And
> what does "lifted.3" mean?
>
> Where do I go to find these errors?  The deepest debugging I do is using trace.
> What else should I use?  I'm using MzScheme 371 from SVN (fairly recent).  No
> DrScheme or MrED.
>
> Thanks,
> Joel
>
> (module leslie mzscheme
>
>   (require
>    "lalgebra.ss"
>    "life-table.ss"
>    (lib "compat.ss")
>    (lib "foreign.ss")
>    (all-except (lib "list.ss" "srfi" "1") any)
>    (lib "vector-lib.ss" "srfi" "43")
>    (all-except (lib "contract.ss") ->)
>    (rename (lib "contract.ss") ->/c ->)
>    (planet "all.ss" ("wmfarr" "plt-linalg.plt" 1 5)))
>
>   (provide make-L
>            build-L-hash
>            neXt-accum
>            neXt-diff)
>
>   (provide/contract
>    (neXt-gen (->/c ((hash-table? 'equal) f64vector? integer? f64vector?))))
>
>   ;; this function builds the Leslie matrix
>   ;; this works as of 23:32 on 8-20-2007
>   (define (make-L M P a)
>       (let* ((d (length M))               ;create a dxd matrix
>              (L (make-matrix d d 0)))     ;of zeros
>         (do ((x 0 (+ x 1))                ;start at 0
>              (off-by 1 (+ off-by 1)))     ;off-diag elements
>             ((= x d) L)                   ;when x = d we're done
>           (matrix-set! L x 0 (*
>                               (* (list-ref M x) (list-ref a x))
>                               (list-ref P 0))) ;f(x,t)
>           (if (= x (- d 1))
>               #f
>               (matrix-set! L x off-by (list-ref P off-by))))))
>
>   (define (make-L-helper life-table)
>     (make-L (life-table-M life-table)
>             (life-table-P life-table)
>             (life-table-a life-table)))
>
>   ;; usage: (define hash (build-L-hash struct-list struct-field)
>   ;; the only remaining task is to coerce any input into a list, since
>   ;; map and foreach expect proper lists
>   (define (build-L-hash struct-list struct-field)
>     (let ((hash (make-hash-table 'equal))
>           (struct-list (if (atom? struct-list)
>                             (list struct-list)
>                             struct-list)))
>       (for-each
>        (lambda (s)
>          (let ((matrix (make-L-helper s)))
>            (map
>             (lambda (v)
>               (hash-table-put! hash v matrix))
>             (struct-field s))))
>        struct-list)
>       hash))
>
>   ;; NEXT-GEN takes a hash L, a vector N and a time
>   ;; t and produces the next vector
>   ;; hash-table f64vector integer -> f64vector
>   (define (neXt-gen L N t)
>     (f64vector-matrix-mul
>      N
>      (hash-table-get L t)))
>
>   ;; NEXT-ACCUM takes a hash L, a vector N, a time
>   ;; t0, t and produces a list of successive values of
>   ;; the vector
>   (define (neXt-accum L N t0 t)
>     (let ((neXt-vec (neXt-gen L N t0)))
>       (if (= 1 (- t0 t)) '()
>           (cons neXt-vec
>                 (neXt-accum L neXt-vec
>                             (add1 t0) t)))))
>
>   ;; NEXT-DIFF take a hash L, a vector N and times t,t0 and produces the
>   ;; stable age distribution
>   ;; this function should be used with a call-with-values procedure to
>   ;; produce the output "Population size:... Time to Stable Age
>   ;; Distribution... Size of ..."
>   ;; hash f64vector integer integer float -> f64vector integer float
>   (define (neXt-diff L N t0 t tol)
>     (let* ((neXt-vec (neXt-gen L N t0))
>            (norm (f64vector-norm
>                   (apply f64vector-sub
>                          (vector-list-scale
>                           (neXt-accum L neXt-vec t0 (add1 t0)))))))
>       (cond ((> t0 t) (error (format "Failure to converge")))
>             ((< norm tol) (values
>                            (vector-list-scale (list N))
>                            t0
>                            norm))
>             (else (neXt-diff L neXt-vec (add1 t0) t tol))))))
>
> ;; test:
>   ;;   (define delta
>   ;;   (make-life-table
>   ;;    (iota 100 0 1)
>   ;;    (iota 5 5 5)
>   ;;    (iota 5 0.8 -0.02)
>   ;;    (make-list 5 0.5)))
>
>   ;; (define epsilon
>   ;;   (make-life-table
>   ;;    (iota 100 100 1)
>   ;;    (iota 5 5 5)
>   ;;    (iota 5 0.6 -0.002)
>   ;;    (make-list 5 0.5)))
>   ;;   (define peter
>   ;;   (build-L-hash
>   ;;    (list delta epsilon)
>   ;;    life-table-gens))
>   ;; (map f64vector->list
>   ;;         (vector-list-scale
>   ;;          (grow-pop-age-classes
>   ;;           peter
>   ;;           (make-f64vector 5 100)
>   ;;           1 200)))
>
>
> Joel J. Adamson
> Clinical Research Analyst
> Pediatric Psychopharmacology Research
> Massachusetts General Hospital
> 55 Fruit St.
> Boston, MA 02114
> (617) 643-1432
> (303) 880-3109 (mobile)
>
>
> The information transmitted in this electronic communication is intended only for the person or entity to whom it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this information in error, please contact the Compliance HelpLine at 800-856-1983 and properly dispose of this information.
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.