Re-defined constant when dynamically evaluating module forms

23 views
Skip to first unread message

Sage Gerard

unread,
May 12, 2021, 10:40:54 PM5/12/21
to Racket Users
I have a program that takes a (trusted) module form as a list and then
pulls out a provided value using this method. I used syntax/modread and
generate a pseudorandom id for each value of `trusted` here.

(define-namespace-anchor anchor)
(define module-namespace (namespace-anchor->namespace anchor))
(define (add trusted)
  (eval trusted module-namespace)
  (dynamic-require `',(cadr trusted) 'data))

Full disclosure: I don't know how to do better. I figured that this
wasn't the best way to do it to begin with because I get the following
error under `raco test`'s runtime configuration.

define-values: assignment disallowed;
 cannot re-define a constant
  constant: lifted/4
  in module:'pkgdef1620873248

I don't know what "lifted/4" is.

If I am bringing in module forms that I trust, what's the best way to
dynamically evaluate them and pull out a provided value without running
into that error?

--

~slg


Matthew Flatt

unread,
May 12, 2021, 10:46:21 PM5/12/21
to Sage Gerard, Racket Users
I think the problem here is that you're re-defining a module. The
`lifted/4` binding is probably a generated one in the module, and
redeclaring the module would require changing `lifted/4` --- and
probably other bindings that you would recognize, but `lifted/4`
happens to be hit first.

To avoid this kind of problem redeclaring a module, maybe you want a
fresh namespace every time, or maybe you want to parameterize `eval`
with `compile-enforce-module-constants` as #f so that redefinition is
allowed.
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/e0a048c8-77ac-5126-5bef-226ecbe90
> 6dc%40sagegerard.com.
Reply all
Reply to author
Forward
0 new messages