9.0
top
← prev up next →

Choose-out: Conditional ProvideπŸ”— i

provide-spec

( choose-out proc-expr[true-idfalse-id]...)

Exports the names true-id. The expression proc-expr must evaluate at expansion-time to a zero-argument procedure. Each name is bound to a transformer that conditionally expands to true-id or false-id depending on the result of the given procedure in the importing module.

Examples:
> (module struct-mathracket
;`num` is an internal representation
(struct num[value])
;set this to `#t` in modules that use `num` values
(define-for-syntax num-client?(box #false))
;addition for `num` values
(define (num-+n0n1)
(num(+ (num-valuen0)(num-valuen1))))
;wrapper: convert `num` addition to Racket addition
(define (racket-+v0v1)
(num-value(num-+(numv0)(numv1))))
;export `num-+` or `racket-+` depending on the importing module
num
(for-syntax num-client?)
(choose-out (λ ()(unbox num-client?))
[num-+racket-+])))
> (module struct-clientracket
;familiar client, uses the `num` representation
(require 'struct-math)
(begin-for-syntax (set-box! num-client?#true))
(displayln (num-+(num2)(num2))))
> (require 'struct-client)

#<num>

> (module racket-clientracket
;foreign client: uses Racket numbers
(require 'struct-math)
(displayln (num-+22)))
> (require 'racket-client)

4

Typed Racket uses a similar protocol to decide whether an identifier exported from a typed module should be protected with a contract. A #lang typed/racket module expands (via #%module-begin ) to code that sets a flag similar to the num-client? flag in the example above.

1Choose-Out RenamingsπŸ”— i

A choose-out renaming is a kind of rename transformer.

procedure

true-id
false-id)choose-out-renaming?
rename?:(-> any/c )
true-id:identifier?
false-id:identifier?
Construct a choose-out renaming from a predicate and two identifiers. Adds the 'not-free-identifier=? syntax property to both identifiers.

procedure

( choose-out-renaming? x)boolean?

x:any/c
Predicate for a choose-out renaming.

If id is bound to a choose-out renaming, returns the source of the renaming. Otherwise, returns id.

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /