Hello,

I was just playing with units and requires.
The idea is to require a module to obtain a unit. This module lives in a
path known by the user. So the user enters a path at run-time, the
dynamic-require acquires the unit which is then linked with another unit
and invoked. It goes like this:

;; test-sig.rkt

#lang racket

(provide test-sig^)

(define-signature test-sig^
  (my-base-class%))


;; unit-sig.rkt

#lang racket

(require "test-sig.rkt")
(provide my-unit@)

(define-signature class-sig^
  (my-class%))

(define-unit my-unit@

  (import test-sig^)
  (export class-sig^)

  (define my-class%
    (class my-base-class%
      (super-new)
      (define foo 2)

      (define/override (yay!)
        'yay))))

(define (run dir)
  (define path-to-unit
    (build-path (current-directory) dir "my-base-class-unit.rkt"))

  (define bunit@
    (dynamic-require path-to-unit 'my-base-unit@))

  (define-compound-unit/infer my-compound@

    (import)
    (export class-sig^)

    (link bunit@ my-unit@))

  (define-values/invoke-unit/infer my-compound@)

  (display (send (new my-class%) yay!)))

(run "sub")

;; sub/my-base-class-unit.rkt

#lang racket

(require "../test-sig.rkt")
(provide my-base-unit@)

(define-unit my-base-unit@

  (import)
  (export test-sig^)

  (define my-base-class%
    (class object%
      (super-new)
      (abstract yay!))))

When I try to run unit-sig.rkt:
racket -l errortrace -t unit-sig.rkt
/home/pmatos/tmp/unit-sig/unit-sig.rkt:36:10:
define-compound-unit/infer: unknown unit definition
  at: bunit@
  in: (define-compound-unit/infer my-compound@ (import) (export
class-sig^) (link bunit@ my-unit@))
  errortrace...:
  context...:

/home/pmatos/installs/racket-6.12/collects/racket/private/unit-compiletime.rkt:164:0:
lookup-def-unit
   /home/pmatos/installs/racket-6.12/collects/racket/unit.rkt:2056:0:
build-compound-unit/infer
   /home/pmatos/installs/racket-6.12/collects/racket/unit.rkt:1850:2

/home/pmatos/installs/racket-6.12/share/pkgs/errortrace-lib/errortrace/errortrace-lib.rkt:497:2:
errortrace-annotate

/home/pmatos/installs/racket-6.12/share/pkgs/errortrace-lib/errortrace/errortrace-lib.rkt:567:4
   standard-module-name-resolver

I am surprised that it complains about bunit@ even though it was defined
on the dynamic-require line. Why is this?

I assume it might have to do with the different phases of the compiler
but I am unsure of the details. How can one go about solving this?

-- 
Paulo Matos

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to