1
0
Fork
You've already forked flix-euler
0
Project Euler problems in Flix language
  • Text 100%
2023年06月27日 14:51:25 -04:00
.testcases problems 29 and 30 2023年06月27日 11:52:20 -04:00
assets created assets directory to store misc files 2023年06月18日 10:52:00 -04:00
src additional comments 2023年06月27日 14:51:25 -04:00
.gitignore add .envrc to .gitignore 2023年06月15日 09:05:15 -04:00
flix.toml initial commit 2023年06月12日 14:24:53 -04:00
LICENSE Initial commit 2023年06月12日 17:41:49 +00:00
README.md updated README 2023年06月26日 11:42:43 -04:00

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