From 0d505a3d3c056a232111f4d5274688f37b07d242 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Tue, 5 Apr 2022 15:14:25 +0300 Subject: [PATCH] Init --- 01.nix | 3 +++ 02.nix | 4 ++++ 03.nix | 8 ++++++++ 04.nix | 6 ++++++ 05.nix | 7 +++++++ 06.nix | 8 ++++++++ 07.nix | 8 ++++++++ 08.nix | 8 ++++++++ 09.nix | 11 +++++++++++ 10.nix | 11 +++++++++++ 10 files changed, 74 insertions(+) create mode 100644 01.nix create mode 100644 02.nix create mode 100644 03.nix create mode 100644 04.nix create mode 100644 05.nix create mode 100644 06.nix create mode 100644 07.nix create mode 100644 08.nix create mode 100644 09.nix create mode 100644 10.nix diff --git a/01.nix b/01.nix new file mode 100644 index 0000000..e1285f5 --- /dev/null +++ b/01.nix @@ -0,0 +1,3 @@ +{ + helloWorld = "Hello" + " " + "World"; +} diff --git a/02.nix b/02.nix new file mode 100644 index 0000000..8df375b --- /dev/null +++ b/02.nix @@ -0,0 +1,4 @@ +# code goes here +{ + v="understood"; +} diff --git a/03.nix b/03.nix new file mode 100644 index 0000000..30f4ac8 --- /dev/null +++ b/03.nix @@ -0,0 +1,8 @@ +let + h = "Hello"; + w = "World"; + s = " "; +in +{ + helloWorld = h + s + w; +} diff --git a/04.nix b/04.nix new file mode 100644 index 0000000..b090534 --- /dev/null +++ b/04.nix @@ -0,0 +1,6 @@ +let + h = "Hello"; +in +{ + helloWorld = "${h} World"; # Modify this line +} diff --git a/05.nix b/05.nix new file mode 100644 index 0000000..fb176a6 --- /dev/null +++ b/05.nix @@ -0,0 +1,7 @@ +let + h = "Strings"; + value = 4; +in +{ + helloWorld = "${h} ${toString value} the win!"; +} diff --git a/06.nix b/06.nix new file mode 100644 index 0000000..8c96dec --- /dev/null +++ b/06.nix @@ -0,0 +1,8 @@ +let + f = "f"; + o = "o"; + func = a: b: c: a + b + c; +in +{ + foo = func f o "o"; +} diff --git a/07.nix b/07.nix new file mode 100644 index 0000000..042143e --- /dev/null +++ b/07.nix @@ -0,0 +1,8 @@ +let + f = "f"; + o = "o"; + func = {a, b, c}: a + b + c; +in +{ + foo = func {a=f; b=o; c="o";}; +} diff --git a/08.nix b/08.nix new file mode 100644 index 0000000..b0dba5a --- /dev/null +++ b/08.nix @@ -0,0 +1,8 @@ +let + min = a: b: if (a > b) then b else a; #modify these + max = a: b: if (a > b) then a else b; #two lines only +in +{ + ex0 = min 5 3; + ex1 = max 9 4; +} diff --git a/09.nix b/09.nix new file mode 100644 index 0000000..c3a49dd --- /dev/null +++ b/09.nix @@ -0,0 +1,11 @@ +let + f = "f"; + o = "o"; + b = "b"; + func = {a ? f, b ? "a", c ? ""}: a+b+c; #only modify this line! +in +rec { + foo = func {b="o"; c=o;}; #must evaluate to "foo" + bar = func {a=b; c="r";}; #must evaluate to "bar" + foobar = func {a=foo;b=bar;}; #must evaluate to "foobar" +} diff --git a/10.nix b/10.nix new file mode 100644 index 0000000..39426d2 --- /dev/null +++ b/10.nix @@ -0,0 +1,11 @@ +let + arguments = {a="f"; b="o"; c="o"; d="bar";}; #only modify this line + func = {a, b, c, ...}: a+b+c; + func2 = args@{a, b, c, ...}: a+b+c+args.d; +in +{ + #the argument d is not used + foo = func arguments; + #now the argument d is used + foobar = func2 arguments; +}