@-patterns
Section 2.13.4, @-patterns
T282828
left Tb4b4b4@ Tb4b4b4{ rightTb4b4b4, Tff7b72.Tff7b72.Tff7b72. Tb4b4b4}
The left hand side is binding the whole right side to a name.
The right side is describing the structure or pattern to which the left must match.
The pattern is binding it to names, too. This is more obvious with assignment.
T282828
whole Tb4b4b4@ Tb4b4b4[headTb4b4b4] Tff7b72= Tb4b4b4[T79c0ff1 T79c0ff2 T79c0ff3Tb4b4b4]
T8b949e# whole = [1 2 3]
T8b949e# head = 1
Using it in an assignment, the pattern is binding it to names, too.
My confused journey to a definition
Going through the mhwombat's nix-book, I just reached @-patterns. I have no idea what these are. Section 2.13.4.
It sounds like it's a way to get the whole set as well as something out of it?
T282828
Tb4b4b4[headTb4b4b4] Tff7b72= Tb4b4b4[T79c0ff1 T79c0ff2 T79c0ff3Tb4b4b4]
T8b949e# head = 1
whole Tb4b4b4@ Tb4b4b4[headTb4b4b4] Tff7b72= Tb4b4b4[T79c0ff1 T79c0ff2 T79c0ff3Tb4b4b4]
T8b949e# head = 1, whole = [1 2 3]
But the example provided makes it too complicated and associates it with a named lambda expression?
T282828
Ta5d6ffformatPoint Tff7b72= pTb4b4b4@Tb4b4b4{ xTb4b4b4, yTb4b4b4, Tff7b72.Tff7b72.Tff7b72. Tb4b4b4}Tb4b4b4:
Tffa657builtinsTff7b72.toXML p
nix-replTff7b72> formatPoint Tb4b4b4{ Ta5d6ffxTff7b72=T79c0ff5Tb4b4b4; Ta5d6ffyTff7b72=T79c0ff3Tb4b4b4; Ta5d6ffzTff7b72=T79c0ff2Tb4b4b4; Tb4b4b4}
Ta5d6ff"Ta5d6ff<?xml version='1.0' encoding='utf-8'?>Tffea00\nTa5d6ff<expr>Tffea00\nTa5d6ff <attrs>Tffea00\nTa5d6ff <attr
name=Tffea00\"Ta5d6ffxTffea00\"Ta5d6ff>Tffea00\nTa5d6ff <int value=Tffea00\"Ta5d6ff5Tffea00\"Ta5d6ff />Tffea00\nTa5d6ff </attr>Tffea00\nTa5d6ff <attr
name=Tffea00\"Ta5d6ffyTffea00\"Ta5d6ff>Tffea00\nTa5d6ff <int value=Tffea00\"Ta5d6ff3Tffea00\"Ta5d6ff />Tffea00\nTa5d6ff </attr>Tffea00\nTa5d6ff <attr
name=Tffea00\"Ta5d6ffzTffea00\"Ta5d6ff>Tffea00\nTa5d6ff <int value=Tffea00\"Ta5d6ff2Tffea00\"Ta5d6ff />Tffea00\nTa5d6ff </attr>Tffea00\n
Ta5d6ff </attrs>Tffea00\nTa5d6ff</expr>Tffea00\nTa5d6ff"
So this defines a function named formatPoint,
It takes a point p, and that point must have (at least) an x and a y.
p@{ x, y, ...}: builtins.toXML p
The left hand side is binding the whole right side to a name. The right side is describing the structure and it has to validate against it?
So it sounds like the @-pattern is really just an unbound name and a structure of some kind. Optionally, more structure can be put around the unbound name.
Maybe it's more apt to say that the @-pattern is a way to provide a name and a structure that it has to adhere to. Then how it can be used still provides unifying the name to a value. Sounds like magic is used to make sure the structure matches.
Tags: nix
Tags
Navigation