[plt-scheme] Parameterizing expansion of subexpressions
Carl Eastlund wrote:
> Why are you saving an expansion-time expression, instead of a run-time
> value? You could easily write a macro that saved a value in a
> parameter each time you ran with-value; with an extra lambda-wrapping
> at with-value and application at observe, you could have the
> expression be re-executed at each observe if that's your intention. I
> don't see why you want the expression itself to be lifted out and
> re-expanded at each call site. Am I missing something obvious?
Not obvious, no. I'm basically making a let* with a hole - or a package
system - for probabilistic theories. Here's the basic idea minus the
probability, as an example:
(define-syntax the-package
(let*/hole ([x <some-expression>]
[y <some-expression>])))
(with-let*/hole the-package
(<some-computation> x y))
It should evaluate exactly as if (<some-computation> x y) had appeared
in the let* body.
I want Scheme identifiers to represent the identifiers exported by
the-package. (Otherwise I'd find myself writing half an interpreter.)
Without special handling, the identifiers within with-let*/hole aren't
free-identifier=? to those within let*/hole because of hygiene. So
let*/hole needs to export identifiers as syntax at expansion time, and
with-let*/hole needs to import them at expansion time - and then do the
special handling.
I tried wrapping define-package and open-package to do it.
Unfortunately, they exposed implementation details of the monad that my
macros target. This and other things made it a hairy mess, and not at
all obvious that it was correct even when it seemed to work.
Neil T