At Sat, 16 Dec 2017 18:55:15 +0000, Laurent wrote:
> From the second file "loader.rkt" (which interacts with the user), I would
> like to retrieve the property-s of each form declared with 'my-define' in
> "my-file.rkt", *without* running the file (not even sandboxed, that is, it
> must be fast). [...]
>
> I've played with 'dynamic-require' and submodules with some limited success
> but couldn't achieve the goal above. Any idea?

Using submodules plus `dynamic-require` is the right idea. Maybe you
tried `module+` to put together parts of the submodule, but `module+`
implicitly imports the enclosing module.

To avoid that dependency, you can implement `my-define` in the same way
that `module+` is implemented, as demonstrated below.

 > (dynamic-require '(submod "my-file.rkt" my-info) 'my-proc)
 '((property1 . "some value") (property2 . 12))

--------------------------------------------------
;; my-file.rkt:

#lang racket/base
(require (for-syntax racket/base
                     syntax/parse))

(begin-for-syntax
  (define submodule-content '()))

(define-syntax (my-define stx)
  (syntax-parse stx
    [(_ proc ([prop prop-val] ...) rhs)
     (when (null? submodule-content)
       (syntax-local-lift-module-end-declaration
        #'(generate-submodule)))
     (set! submodule-content
           (cons (syntax-local-introduce
                  #`(begin
                      (provide proc)
                      (define proc (list (cons 'prop prop-val) ...))))
                 submodule-content))
     (syntax/loc stx
       (define proc rhs))]))

(define-syntax (generate-submodule stx)
  #`(module my-info racket/base #,@submodule-content))

(my-define my-proc
    ([property1 "some value"] ; some properties of my-proc
     [property2 12])
    (lambda (x) (displayln x) 3))

(my-proc 'ok)

-- 
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 racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to