08:49 UTC

< February 2021 > Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

- Console
- #freebsd-nix
- #haskell.nix
- #home-manager
- #nixcon
- #nix-core
- #nix-darwin
- #nix-lang
- #nixops
- #nixos
- #nixos-aarch64
- #nixos-azure
- #nixos-borg
- #nixos-bots
- #nixos-chat
- #nixos-cs
- #nixos-de
- #nixos-dev
- #nixos-emacs
- #nixos-exotic
- #nixos-fr
- #nixos-gnome
- #nixos-infra
- #nixos-kubernetes
- #nixos-nur
- #nixos-officehours
- #nixos-on-your-router
- #nixos-r13y
- #nixos-ruby
- #nixos-rust
- #nixos-security
- #nixos-systemd
- #nixos-unregistered
- #nixos-wg-ai
- #nixos-wiki
- #nixus
- #nix-windows
- #robotnix
- #spectrum

infinisil changed the topic of #nix-lang to: Channel for discussing Nix as a language - https://nixos.org/nix/manual/#chap-writing-nix-expressions - Logs: https://logs.nix.samueldr.com/nix-lang/

<V>
so... -9223372036854775808 is possible to represent (and obtain by addition/subtraction), but not as a literal? cursed

<ekleog>
(though interestingly enough… I'd bet any breakage that would happen would only currently be relying on nix code being UB because signed int addition is UB in c++?)

<V>
I mean, if it is indeed implemented directly using C++ primitives, Nix-lang can now directly invoke UB

<ekleog>
TBF signed int overflow being UB is probably actually ID by GCC to mean wrapping on amd64; anything else would most likely break so much real-world software

<V>
indeed. if you actually took advantage of that, increment w/out bounds check could cause portions of code to be completely eliminated

<niksnut>
well, there have been some security bugs because the compiler removed code under the assumption that integers don't wrap around

<V>
but I'm also not relying on them deciding to enable this for -std=c++<future year>, with the argument that this wouldn't apply to "existing software", etc

<niksnut>
nickel only has 64-bit floating-point numbers, which is probably a good idea since they're more standard

<V>
siraben: pow = x: y: builtins.fromJSON (builtins.readFile (runCommand "" {} "echo $((${builtins.toString x} ** ${builtins.toString y})) >$out"))

<sterni>
> exp = base: pow: if pow > 0 then base * (exp base (pow - 1)) else if pow < 0 then 1.0 / exp base (abs pow) else 1;

<sterni>
> exp = base: pow: if pow > 0 then base * (exp base (pow - 1)) else if pow < 0 then 1.0 / exp base (abs pow) else 1

<sterni>
> exp = base: pow: if pow > 0 then base * (exp base (pow - 1)) else if pow < 0 then 1.0 / exp base (abs pow) else 1;

<sterni>
> exp = base: pow: if pow > 0 then base * (exp base (pow - 1)) else if pow < 0 then 1.0 / exp base (abs pow) else 1

<edef>
> fastExp = base: exp: if exp < 0 then fastExp (1 / x) -exp else if exp == 1 then 1 else if isOdd exp then base * fastExp (exp - 1) else fastExp (x * x) (x / 2)

<edef>
> fastExp = x: exp: if exp < 0 then fastExp (1 / x) -exp else if exp == 1 then 1 else if isOdd exp then x * (fastExp x (exp - 1)) else fastExp (x * x) (x / 2)

<edef>
i'm definitely somewhat out of it, but also, i just realised everyone's impl for negative exponents is wrong

<edef>
> fastExp = x: exp: if exp < 0 then fastExp (1 / x) -exp else if exp == 1 then x else if isOdd exp then x * (fastExp x (exp - 1)) else fastExp (x * x) (x / 2)

<V>
mine just flat out breaks b/c bash doesn't allow for negative exponents. would be trivial to fix though

<edef>
> fastExp = x: exp: if exp < 0 then fastExp (1.0 / x) -exp else if exp == 1 then x else if isOdd exp then x * (fastExp x (exp - 1)) else fastExp (x * x) (x / 2)

<edef>
> fastExp = x: exp: if exp < 0 then fastExp (1.0 / x) -exp else if exp == 0 then 1 else if isOdd exp then x * (fastExp x (exp - 1)) else fastExp (x * x) (x / 2)

<edef>
> fastExp = x: exp: if exp < 0 then fastExp (1.0 / x) -exp else if exp == 0 then 1 else if isOdd exp then x * (fastExp x (exp - 1)) else fastExp (x * x) (exp / 2)

<edef>
i think we might want bit shifts for that? i forget what the implementation techniques are exactly

<V>
exp = x: y: builtins.fromJSON (builtins.readFile (runCommand "" {} "${ruby}/bin/ruby -e 'print ${builtins.toString x} ** ${builtins.toString y}' >$out"))

<edef>
https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Approximations_that_depend_on_the_floating_point_representation

<V>
> expRuby = x: y: builtins.fromJSON (builtins.readFile (runCommand "" {} "${ruby}/bin/ruby -e 'print ${builtins.toString x} ** ${builtins.toString y}' >$out

<edef>
although i think you'd want to use the fast inverse sqrt algo and follow it with one or two iterations of newton's method

<V>
> expRuby = x: y: builtins.fromJSON (builtins.readFile (runCommand "" {} "${ruby}/bin/ruby -e 'print ${builtins.toString x} ** ${builtins.toString y}' >$out"))

<V>
> expRuby = x: y: builtins.fromJSON (builtins.readFile (pkgs.runCommand "" {} "${ruby}/bin/ruby -e 'print ${builtins.toString x} ** ${builtins.toString y}' >$out"))

<V>
> expRuby = x: y: builtins.fromJSON (builtins.readFile (pkgs.runCommand "" {} "${pkgs.ruby}/bin/ruby -e 'print ${builtins.toString x} ** ${builtins.toString y}' >$out"))

<{^_^}>
cannot read '/nix/store/aqsdpp1wqxqjldw2pmdh4x51yph8i1aw-unknown', since path '/nix/store/g4cmabksbbsnzxpv0bk1qq2a9ckwyikv-unknown.drv' is not valid, at (string):157:37

<sterni>
if I was using guix I wouldn't have an endless supply of cursed facts about my package manager's expression language

<sterni>
siraben: indeed nix is being to strict in that case because the string constructor should come first

<sterni>
one thing I found really strange when I last had a look in the code is that in the implementation builtins and functions are different things and behave differently, but they have the same type (lambda) in the language

<sterni>
which has the consequence for example that builtins.functionArgs throws an exception on nix stable

<niksnut>
there are values of type string, but you don't know that the argument to builtins.isString is a string value until you've evaluated it, hence the exception

<sterni>
niksnut: well you don't have to evaluate the strings contents to know it's a string; depends on implemantion

<sterni>
siraben: yes, I think a few people are using it, you have to swap out nix-daemon as well though

<niksnut>
in the absence of a static type system, you can't really conclude whether the argument to builtins.isString will be a string without evaluating its argument

<simpson>
Nix doesn't evaluate strictly enough for that problem to be fixed by simply putting a static type on every value. Same issue as Haskell, where the computational category isn't the one used for intuitive reasoning: https://wiki.haskell.org/Hask

<__monty__>
niksnut: But can anything that parses as a string literal ever turn out not to be a string?

<sterni>
you just can't decide builtins.isString if it is something like "foo" + builtins.throw "lol"

<{^_^}>
sqrt = a: let iter = x: let x' = (x + a / x) / 2; d = x' - x; in if d < 0.00001 && d > -0.00001 then x' else iter x'; in iter (a / 2.0 + 0.5)