These days I write more and more code in scheme. Guix support for Racket scheme and Guile scheme is rather good (unsurprisingly perhaps).
For Racket simply do
guix package -i racket
I usually create a special profile with
guix package -i racket -p ~/opt/racket
and load the environment with
source ~/opt/racket/profile
Works a treat. All tools should work.
To get the emacs working environment
guix package -i emacs emacs-magit emacs-rainbow-mode \
emacs-racket-mode emacs-geiser \
emacs-json-mode emacs-markdown-mode emacs-org \
emacs-paredit racket -p ~/opt/racket
One thing that requires an extra step is compilation of external C libs. An example could read
#include "escheme.h"
Scheme_Object *scheme_initialize(Scheme_Env *env) {
Scheme_Env *mod_env;
mod_env = scheme_primitive_module(scheme_intern_symbol("hi"),
env);
scheme_add_global("greeting",
scheme_make_utf8_string("hello"),
mod_env);
scheme_finish_primitive_module(mod_env);
return scheme_void;
}
Scheme_Object *scheme_reload(Scheme_Env *env) {
return scheme_initialize(env); /* Nothing special for reload */
}
Scheme_Object *scheme_module_name() {
return scheme_intern_symbol("hi");
}
This is because crti.o is missing, e.g. following the docs on 3m extensions brings up the error
raco ctool --3m --ld hw.so hw_3m.o ld: cannot find crti.o: No such file or directory
crti.o is part of the glibc package which needs to be added to the profile (see also R.org). One quick hack is to find the glibc in racket and add that to the path
ldd ~/opt/racket/bin/racket /gnu/store/h90vnqw0nwd0hhm1l5dgxsdrigddfmq4-glibc-2.28/lib/ld-linux-x86-64.so.2 export LIBRARY_PATH=/gnu/store/h90vnqw0nwd0hhm1l5dgxsdrigddfmq4-glibc-2.28/lib raco ctool --xform hw.c raco ctool --3m --cc hw.3m.c raco ctool --3m --ld hw.so hw_3m.o
now builds. The module can be loaded with
> (load-extension "hw.so") "hi"
Note you may have to update the module search path first btw with something like
(current-directory (build-path "/home/user/racket"))
note that DrRacket (for some reason) may start in $HOME. To check print the path with
(current-directory)
To create a proper module read the docs. You can also use the FFI which allows you to bind C functions natively without much work.