summaryrefslogtreecommitdiff
path: root/nix-turing/io-example.nix
diff options
context:
space:
mode:
authorstuebinm2021-07-20 20:43:16 +0200
committerstuebinm2021-07-20 20:43:16 +0200
commit3d498c134a9c0ab61c86a233edd0b2eb76ef44eb (patch)
tree944d1735a932ecabe3d07a01b0dcb22d7b12adc8 /nix-turing/io-example.nix
parentb160fc2033cfa8a356098d962bab790ec273ec03 (diff)
playing around with IO in Nix
Diffstat (limited to 'nix-turing/io-example.nix')
-rw-r--r--nix-turing/io-example.nix41
1 files changed, 41 insertions, 0 deletions
diff --git a/nix-turing/io-example.nix b/nix-turing/io-example.nix
new file mode 100644
index 0000000..9692629
--- /dev/null
+++ b/nix-turing/io-example.nix
@@ -0,0 +1,41 @@
+with import <nixpkgs> {}.lib;
+
+let
+ # all possible winning rows
+ winning = [
+ ["tl" "tm" "tr"]
+ ["ml" "mm" "mr"]
+ ["bl" "bm" "br"]
+ ["tl" "ml" "bl"]
+ ["tm" "mm" "bm"]
+ ["tr" "mr" "br"]
+ ["tl" "mm" "br"]
+ ["bl" "mm" "tr"]
+ ];
+
+ showGrid = grid: with grid; ''
+ ===========GRID===========
+ ${tl} | ${tm} | ${tr}
+ ---------
+ ${ml} | ${mm} | ${mr}
+ ---------
+ ${bl} | ${bm} | ${br}
+ '';
+
+ # the inital empty grid
+ emptyGrid = listToAttrs
+ (map (name: {inherit name; value = " ";})
+ ["tl" "tm" "tr" "ml" "mm" "mr" "bl" "bm" "br"]);
+
+in {seed}:
+with import ./io.nix {s = seed;};
+
+do initialWorld [
+ (v: read_input "hello!")
+ (log)
+ (v: read_input "lalala second round!")
+ (log)
+ (ifThenElse (v: v == "condition\n")
+ (v: log "condition was met!")
+ (v: log "condition did not hold!"))
+]