- Text 100%
|
|
||
|---|---|---|
| .testcases | problems 29 and 30 | |
| assets | created assets directory to store misc files | |
| src | additional comments | |
| .gitignore | add .envrc to .gitignore | |
| flix.toml | initial commit | |
| LICENSE | Initial commit | |
| README.md | updated README | |
I like to kick the tires on a new programming language by working a few Project Euler problems. Here I am trying out the Flix language. Flix is a brand new language, at version 0.37.0 at time of writing.
My code may or may not be idiomatic, I don't know. I suspect the idioms are still developing. The code is guided in part by a desire to try out language features, so in some problems I choose approaches that could have been simpler had I been focused purely on the problem per se.
The solutions were built and tested in the following environment:
- Host OS: MacOs Ventura 13.2.1
- Java: openjdk 20.0.1 2023年04月18日
- Flix: 0.38.0
- Visual Studio Code 1.79.2
- flix extension for VS Code, v1.5.0
How I run
The Flix language runtime is distributed as a Java jar file. On my machine the flix extension for VS Code installed that jar file in $HOME/Library/Application Support/Code/User/globalStorage/flix.flix/flix.jar
I find it convenient to invoke the jar via a shell script as follows:
#!/usr/bin/env sh
OPTIONS="-Xss4M" # Increase java stack size.
# VS Code Flix extension installs the Flix jar here.
JAR="$HOME/Library/Application Support/Code/User/globalStorage/flix.flix/flix.jar"
java "$OPTIONS" -jar "$JAR" "$@"
I keep the script at $HOME/bin/flix, which is on my command path.
Creating a new Flix project
~/tmp
❯ mkdir someproject
~/tmp
❯ cd someproject
~/tmp/someproject
❯ flix init
Creating '/Users/beavis/tmp/someproject/src'.
Creating '/Users/beavis/tmp/someproject/test'.
Creating '/Users/beavis/tmp/someproject/flix.toml'.
Creating '/Users/beavis/tmp/someproject/.gitignore'.
Creating '/Users/beavis/tmp/someproject/LICENSE.md'.
Creating '/Users/beavis/tmp/someproject/README.md'.
Creating '/Users/beavis/tmp/someproject/src/Main.flix'.
Creating '/Users/beavis/tmp/someproject/test/TestMain.flix'.
~/tmp/someproject
❯ tree
.
├── LICENSE.md
├── README.md
├── flix.toml
├── src
│ └── Main.flix
└── test
└── TestMain.flix
How I test
The 'flix test' command will run all the test files in the project test directory. I find this less than ideal. As the number of tests grows I become less inclined to run ALL the tests because it can take longer than I like.
Instead, I keep all the test files in a hidden directory called .testcases and keep the project test directory empty. I use two custom shell scripts,'t' and 'tall' (short for test and testall) to manage the on the fly creation/deletion of symlinks that allow me to either run all the tests (tall) or run a single test file of my choosing, (t). Note that the 't' script depends on the fabulous (fzf)[https://github.com/junegunn/fzf]. I use (direnv)[https://direnv.net/] to set up the project specific environment variables used by 't' and 'tall'. My modified setup looks like this.
~/tmp/someproject
❯ tree -a
.
├── .envrc
├── .gitignore
├── .testcases
│ └── TestMain.flix
├── LICENSE.md
├── README.md
├── bin
│ ├── t
│ └── tall
├── flix.toml
├── src
│ └── Main.flix
└── test