I am reading this tutorial from 2014 about the Nix language:
I add the following to a file myfactorial.nix
let
# factorial : int -> int
factorial = n: if n == 0 then 1
else n * factorial (n-1);
in
factorial 9
and evaluate with:
nix-instantiate --eval myfactorial.nix
and get back:
error: undefined variable 'n-1'
at /home/i97henka/github/hk.nix.dev.walkthrough/myfactorial.nix:4:48:
3| factorial = n: if n == 0 then 1
4| else n * factorial (n-1);
| ^
5| in
I have tried to double check my work to make sure that I didn’t accidentally mistype anything.
Please let me know what gives.
I guess it was just a typo (or just muscle memory, I mean in almost every other language n-1 is a subtraction).
When I copy the strings from the blogpost I get (n — 1), so everything seems fine. I mean, if the Nix language would suddenly change its behavior in such a drastic way that would be very bad