Le vendredi 2 septembre 2016 12:32:52 UTC+2, Jack Firth a écrit :
> However, (parameterize ([param tool-func]) (dynamic-require mod-path)) 
> doesn't seem to work because the parameter is being set for the runtime phase 
> rather than the expansion time phase.

Here's a solution, which also allows the mod-path to return a value, but it 
must do so at compile-time (I think the run-time is not even executed).

param.rkt:

#lang racket
(provide foo)
(define foo (make-parameter #f))



mod-path.rkt:

#lang racket
(require (for-meta 1 "param.rkt"))
(provide (for-syntax return-value))
(define-for-syntax return-value `("here's my report: " (foo is ,(foo))))
(provide (for-syntax varref))
(define-for-syntax varref (#%variable-reference))



tool.rkt:

#lang racket
(require (for-meta 1 "param.rkt"))
(define run-time-param-value (+ 40 2))
(define run-time-module-name (string-append "mod" "-path.rkt"))
(define result
  (eval #`(begin
            (define-syntax (trampoline _stx)
              (parameterize ([foo #,run-time-param-value])
                (define ns
                  (eval '(begin
                           (require (for-template #,run-time-module-name))
                           (variable-reference->namespace varref))))
                #`#,(namespace-variable-value 'varref #f #f ns)))
            (define varref-0 (trampoline))
            (define ns-0 (variable-reference->namespace varref-0))
            (parameterize ([current-namespace ns-0])
              (namespace-variable-value 'return-value)))))
result





After our discussion on IRC:

> …
> @notjack: IIUC, your tool expands 'mod, and wants to access the syntax 
> properties of the expanded code?
> <notjack> yup, exactly
> …

it seems something like this would be more suited to your purposes:

mod-path.rkt:

#lang racket
(define-syntax (mod-stx stx)
  (syntax-property #'42
                   'my-prop 123))
(mod-stx)



tool.rkt:

#lang racket
(define (traverse stx)
  (when (and (syntax? stx) (syntax-property stx 'my-prop))
    (displayln (syntax-property stx 'my-prop)))
  (cond
    [(syntax? stx) (traverse (syntax-e stx))]
    [(list? stx) (map traverse stx)]
    [(pair? stx) (traverse (car stx))
                 (traverse (cdr stx))]
    [(vector? stx) (traverse (vector->list stx))]
    [(prefab-struct-key stx) (traverse (struct->vector stx))])
  (void))
 
(traverse
 (parameterize ([read-accept-lang #t]
                [current-namespace (make-base-namespace)])
   (expand-syntax
    (namespace-syntax-introduce
     (read-syntax "tool.rkt" (open-input-file "tool.rkt"))))))
;; => 123
;;    123

-- 
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