shriram / gradescope-racket

Infrastructure to autograde Racket code on Gradescope
MIT License
17 stars 8 forks source link

support module exports #1

Closed shriram closed 4 years ago

shriram commented 4 years ago

Because BSL does not export names, we currently use namespace tools to extract the name from inside the module. This works across many languages, but it has a subtle flaw: it does not respect rename-out. For instance, in

(provide [rename-out (three four)])

(define three 3)
(define four 4)

the value of four obtained from requiring the module is 3 but when obtained from the module's namespace, it's 4.

Therefore, either the name extraction should respect rename-out, or we should first try to obtain the name through regular means, and resort to namespace inspection only as a last resort. (A language without provide has no need for rename-out, so this should be safe.)

shriram commented 4 years ago

The solution is to not default to extracting the namespace. dynamic-require can be used to require the name directly using the "external" interface.

If the name isn't found, we have an ambiguity: either the student program is in error, or it's written in a language (like BSL) that doesn't provide the name. Since the BSL issue isn't surmountable, we have to be generous and extract the name (it's reasonable to assume the student wouldn't have uploaded the code if they hadn't wanted it exposed).

In principle we should check the implementing language and only do this if the language is a student language (or at least issue a warning about automatic extraction), but that seems unlikely to be a priority. (Also because other student languages may be built atop BSL, and they will also trigger this warning, which is likely to be confusing to students.)