Compiling R7RS code to executable
I noticed that on the website the --r7rs flag is only for running scripts with interpreter, is there something similar for compiling R7RS code?
Assuming files. main.scm
(import (scheme base)
(foo bar))
(hello)
foo/bar.sld
(define-library
(foo bar)
(import (scheme base)
(scheme write))
(export hello)
(include "bar.scm"))
foo/bar.scm
(define (hello)
(display "Hello world")
(newline))
You can compile it with different R7RS supporting implementations like so:
- Loko
loko -std=r7rs --compile main.scm
- Cyclone
cyclone main.scm
- Chicken
csc -R r7rs -X r7rs -c -J -static -unit foo.bar -o foo.bar.a foo/bar.sldcsc -R r7rs -X r7rs -static -uses foo.bar main.scm
They all produce main executable which can then be just run with ./main
This is an oversight, the compiler should support both --r7rs and general custom preludes.
I will make sure this is implemented before release, hopefully sooner.
We should also add support for recognizing .sld files as r7rs by default, maybe for the .scm files too so that you don't even have to specify the prelude flag and it just works out of the box.
another UX improvement detail should be automatic main (or not requiring a main at all) for r7rs.
Since you are well versed with multiple r7rs implementations, what other flags are common?
Most implementations also have flags for adding directories into the beginning of load path and at the end of load path. Imagine your foo directory was in ~/libraries. Then you could run something like:
gxc --r7rs -I ~/libraries -o main main.scm
If the flags -I and -A are free then I recommend them. They are used often in new implementations and they come from https://srfi.schemers.org/srfi-138/srfi-138.html
Edit: I noticed that there is GERBIL_LOADPATH, but sometimes it can be handy to have the option to put the library path in front of the list, or at the end of the list. For example an SRFI library in the directory can break things if it is loaded first.
yeah, both -I and -A are free. -I is easy to add and makes sense, we should also add it to gxi.
What does -A do? like -I but append instead of prepend?
ok i see, prepend and append indeed. I will add them.
I will also add -D, we already use it in gxtest.