__monty__ has quit [Read error: Connection reset by peer]
__monty__ has joined #nix-lang
__monty__ has quit [Quit: leaving]
<infinisil>
> toLinked' = prev: list: if builtins.length list == 0 then null else let this = { prev = prev; value = builtins.head list; next = toLinked' this (builtins.tail list); }; in this
<{^_^}>
error: syntax error, unexpected '=', expecting ')', at (string):172:11
<infinisil>
> toLinked2 = prev: list: if builtins.length list == 0 then null else let this = { prev = prev; value = builtins.head list; next = toLinked2 this (builtins.tail list); }; in this
<{^_^}>
toLinked2 defined
<infinisil>
> toLinked = list: toLinked2 null list
<{^_^}>
toLinked defined
<infinisil>
> test = toLinked [ 1 2 3 ]
<{^_^}>
test defined
<infinisil>
> test
<{^_^}>
{ next = <CODE>; prev = null; value = <CODE>; }
<gchristensen>
oh dear
<infinisil>
> test.next.next.prev.prev.value
<{^_^}>
1
<infinisil>
:P
<infinisil>
gchristensen: The discussion about parsing in #nixos-dev made me think of this
<infinisil>
Could be used as the input band in a parser, because looping through a [ 1 2 3 ] with an index is probably inefficient
<infinisil>
Although, maybe not
<infinisil>
Haven't tested it
<gchristensen>
does nix not use a linked list internally?
<gchristensen>
I thought that was a pretty standard optimization for FPs
<infinisil>
It might
<infinisil>
"/* Return a list consisting of everything but the first element of a list. Warning: this function takes O(n) time, so you probably don't want to use it! */"
<infinisil>
gchristensen: From the nix source code..
<gchristensen>
neat lol
<gchristensen>
which function?
<infinisil>
tail
<infinisil>
Apparently it stores stuff in an array, not a linked list
<infinisil>
> toLinkedAltHelper = linked: n: list: { value = builtins.elemAt n list; prev = if n == 0 then null else builtins.elemAt (n-1) linked; next = if n == builtins.length list - 1 then null else builtins.elemAt (n+1) linked; }
<{^_^}>
error: undefined variable 'n-1' at (string):150:122
<infinisil>
> toLinkedAltHelper = linked: n: list: { value = builtins.elemAt n list; prev = if n == 0 then null else builtins.elemAt (n - 1) linked; next = if n == builtins.length list - 1 then null else builtins.elemAt (n + 1) linked; }
<{^_^}>
toLinkedAltHelper defined
<infinisil>
> toLinkedAltHelper = linked: list: n: { value = builtins.elemAt n list; prev = if n == 0 then null else builtins.elemAt (n - 1) linked; next = if n == builtins.length list - 1 then null else builtins.elemAt (n + 1) linked; }
<{^_^}>
toLinkedAltHelper defined
<infinisil>
> toLinkedAlt = list: let linked = map (toLinkedAltHelper linked list) (lib.range 0 (builtins.length list - 1)); in linked
<{^_^}>
toLinkedAlt defined
<infinisil>
> toLinkedAlt [ 1 2 3 ]
<{^_^}>
[ <CODE> <CODE> <CODE> ]
<infinisil>
> toLinkedAlt = list: let linked = map (toLinkedAltHelper linked list) (lib.range 0 (builtins.length list - 1)); in builtins.head linked
<{^_^}>
toLinkedAlt defined
<infinisil>
> toLinkedAlt [ 1 2 3 ]
<{^_^}>
{ next = <CODE>; prev = <CODE>; value = <CODE>; }
<{^_^}>
value is a list while an integer was expected, at (string):151:192
<infinisil>
> toLinkedAltHelper = linked: n: list: { value = builtins.elemAt list n; prev = if n == 0 then null else builtins.elemAt linked (n - 1); next = if n == builtins.length list - 1 then null else builtins.elemAt linked (n + 1); }
<{^_^}>
toLinkedAltHelper defined
<infinisil>
> toLinkedAlt = list: let linked = map (toLinkedAltHelper linked list) (lib.range 0 (builtins.length list - 1)); in builtins.head linked
<{^_^}>
value is an integer while a list was expected, at (string):151:152
<infinisil>
Darn
<infinisil>
> builtins.elemAt [ 1 ] 1
<{^_^}>
list index 1 is out of bounds, at (string):177:1
<infinisil>
> builtins.elemAt [ 1 ] 0
<{^_^}>
1
<infinisil>
> toLinkedAltHelper = linked: list: n: { value = builtins.elemAt list n; prev = if n == 0 then null else builtins.elemAt linked (n - 1); next = if n == builtins.length list - 1 then null else builtins.elemAt linked (n + 1); }