Search code examples
schemeracketread-eval-print-loop

Is there a way to use load-mode for files in DrRacket?


I would like to use DrRacket in the same way that it works for some of the ‘legacy languages’. In particular, I would like to go through a file as if it were a sequence of commands issued to the interpreter, and not as a module.

Essentially I want to run at least one file in load-mode, but I’m not sure if it’s possible to do it using DrRacket.

Ideally, I could:

*Specify a file that sets the language and maybe loads some modules, which runs by default at startup.

*Then load a file that is not a module (and has no #lang specification) and run it.

It’d also be nice (since I want to use Scheme) if it would allow redefinitions, just as the legacy languages do.


Solution

  • Yes you can, and in fact, the 'legacy languages' (and 'teaching languages') are actually just implemented as DrRacket Plugins. You can remove them from your copy of DrRacket and even add new ones.

    There are various ways to do this depending on if you are okay with a #lang (or #reader) saved in the file. If you're not, its still doable, you just need to use drracket:get/extend:extend-unit-frame to add your tool to DrRacket, and possibly drracket:get/extend:extend-definitions-text to easily extend the definitions window.

    I won't go into the details of making a generic DrRacket plugin here, that belongs in a different question...also the DrRacket Plugins Manual has the information you need.1 I will, however, point you in the direction of how you can use DrRacket in load mode out of the box.

    Check out the racket/load language. It is designed to run each expression in the top level as if you were at a REPL typing it. I find it very useful for testing the differences between Racket module and top level interactions.

    Of course, if you don't make a DrRacket plugin, you will still need to put:

    #lang racket/load
    

    at the top of your file, but you otherwise get a 'legacy mode' out of the box.

    1If it doesn't please continue to ask questions, and of course we always love help from anyone who is willing to contribute. <3