Hello! I just made a new recipe for Scheme cookbook about how to run Scheme code with different implementations to test it’s portability.
opened 04:12PM - 27 Feb 25 UTC
## Problem
You want to write portable code and to test it with multiple impleme… ntations. However installing them can be cumbersome and time consuming.
## Solution
Running the code in a container using Docker.
### Running a script
We mount the current working directory inside the container to /workdir and run file called test.scm. Replace the SCHEME\_NAME with the name of the Scheme you want to use, for example "guile". And replace SCHEME\_GOMMAND with command you want to run, for example "guile".
```shell
docker run -v "$PWD:/workdir" -it schemers/SCHEME_NAME bash -c "cd /workdir && SCHEME_COMMAND test.scm"
```
If you also need to install some packages inside the container it is better to create a Dockerfile and pass the implementation name as argument. Build it and then run container using the built image.
Here is and example of such Dockerfile in which Scheme implementation is passed as and argument. Then we install the packages we need, just curl here for example. Then we set the workdir inside the Dockerfile so we dont need to set it in the command.
```dockerfile
ARG SCHEME=
FROM schemers/${SCHEME}
RUN apt-get update && apt-get install -y curl
WORKDIR /workdir
```
Then we build it using tag my-scheme and run it. Just like previously replace SCHEME\_NAME and SCHEME\_COMMAND with implementation and command you want.
```shell
docker build . --build-arg SCHEME=SCHEME_NAME --tag=my-scheme
docker run -v "$PWD:/workdir" my-scheme bash -c "SCHEME_COMMAND test.scm"
```
### Opening a REPL
See [https://containers.scheme.org/](https://containers.scheme.org/).
### Notes
- Windows
- You might need to replace the current directory environment variable, $PWD, with %cd%.
- Containers and tags
- All the containers and tags can be found in [Schemers Docker hub](https://hub.docker.com/u/schemers)
Credit: @Retropikzel
I included a note about what needs to be changed to run it on windows, but since I’m not a windows user I thought I’d ask here for people who run windows to test if the commands work as is? Any other feedback is also appriciated!
1 Like