Sunday, March 17, 2024

racket

 racket is one of scheme dialect and I want to use racket to learn "the litte schemer". One of problem I meet is how to load file with scheme code (not racket code) into REPL and run relate function. In guile, it is very simple: guile -l my_function.scm. but in racket, it is little complex.

  • with load (traditional scheme file, no #lang)
 it could work "racket -if <my_function.scm>" but my_function.scm should not start with "#lang racket". it is same with load function
  • with module (racket file, with #lang)
Racket has concept of module, every file is module and each module need "initial-module-path" which is "The #lang at the start of a module file begins a shorthand for a module form"

First, like import in python, you could use (require my_function.scm) in source code and "-t " in command line to import a module, but you need to list which function is export by (provide function) in my_function.scm, or (provide (all-defined-out)) to export all functions. 

 -t <file>, --require <file> Like -e '(require (file "<file>"))' [*]

Another trick point is you need "racket -i -t my_function.scm" instead of "racket -t  my_function.scm -i". I don't know why but I guess it is related to "If -t/-l/-p/-u appears before the first -i/-e/-f/-r, -n is added".

Second, you could config initial-module in command line with "racket -I typed/racket" (#lang typed/racket in source code). The magic of of initial-module-path is you could define a new language with different syntax.

Third, you could always start "racket -i" and use ",enter my_function.scm" or "racket -i -e '(enter! "my_function.scm")'" to go to my_function namespace.