How to require a file whose path depends on a get-env value?

37 views
Skip to first unread message

Kathi Fisler

unread,
Jun 15, 2017, 9:49:57 AM6/15/17
to Racket Developers
We need to be able to construct a path to require based on a command-line argument.  We currently put the command-line value into an environment variable, using get-env to extract the value. In other words, we want to do (the equivalent of)

     (require (string-append "courses" (get-env WHICHCLASS) "defs.rkt"))

How can we pull off something with this behavior, since evaluating seems incompatible with require syntax.

thanks,
Kathi

Jay McCarthy

unread,
Jun 15, 2017, 9:52:37 AM6/15/17
to Kathi Fisler, Racket Developers
You can use dynamic-require and grab the identifiers you need one by
one. Fine if there are few.

You can set up a namespace, dynamic-require into it, and then eval the
code you want inside the namespace. Okay for many ids, but code to run
will be a little painful to write, so hopefully small.

You can make a macro expand to the require and look at get-env in the
compile-time, but now you have to compile and run your code rather
than compiling it first. My guess is that this is not a big deal for
your use case. I'd recommend this if you can.

Jay
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-dev+...@googlegroups.com.
> To post to this group, send email to racke...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-dev/f66540c6-92db-4c58-8622-b1b765309921%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
-=[ Jay McCarthy http://jeapostrophe.github.io ]=-
-=[ Associate Professor PLT @ CS @ UMass Lowell ]=-
-=[ Moses 1:33: And worlds without number have I created; ]=-
Reply all
Reply to author
Forward
0 new messages