From 667cbfe2ba105858f2dabb55f0772c6769a2323a Mon Sep 17 00:00:00 2001 From: Chris Martin Date: Mon, 9 Oct 2017 18:51:02 -0400 Subject: [nix/en] document using ? to test set membership --- nix.html.markdown | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'nix.html.markdown') diff --git a/nix.html.markdown b/nix.html.markdown index ef59a135..ba122a46 100644 --- a/nix.html.markdown +++ b/nix.html.markdown @@ -208,6 +208,12 @@ with builtins; [ { a = 1; b = 2; }.a #=> 1 + # The ? operator tests whether a key is present in a set. + ({ a = 1; b = 2; } ? a) + #=> true + ({ a = 1; b = 2; } ? c) + #=> false + # The // operator merges two sets. ({ a = 1; } // { b = 2; }) #=> { a = 1; b = 2; } -- cgit v1.2.3 From 7dd95d99f010f49c6d94499d13fdd6844dd35aec Mon Sep 17 00:00:00 2001 From: Rommel Martinez Date: Thu, 1 Mar 2018 21:45:50 +0800 Subject: [nix/en]: remove and update broken link --- nix.html.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'nix.html.markdown') diff --git a/nix.html.markdown b/nix.html.markdown index ba122a46..d078395a 100644 --- a/nix.html.markdown +++ b/nix.html.markdown @@ -3,6 +3,7 @@ language: nix filename: learn.nix contributors: - ["Chris Martin", "http://chris-martin.org/"] + - ["Rommel Martinez", "https://ebzzry.io"] --- Nix is a simple functional language developed for the @@ -356,5 +357,5 @@ with builtins; [ * [James Fisher - Nix by example - Part 1: The Nix expression language] (https://medium.com/@MrJamesFisher/nix-by-example-a0063a1a4c55) -* [Susan Potter - Nix Cookbook - Nix By Example] - (http://funops.co/nix-cookbook/nix-by-example/) +* [Rommel Martinez - A Gentle Introduction to the Nix Family] + (https://ebzzry.io/en/nix/#nix) -- cgit v1.2.3 From efcd37612d58baadf8821f70305e77201b5f0260 Mon Sep 17 00:00:00 2001 From: Javier Candeira Date: Sat, 31 Aug 2019 22:56:08 +1000 Subject: [nix/en] Updates for Nix 2.2.0 - nix-repl now deprecated, Nix 2 has `nix repl` - nix language now has floats, and type-preserving arithmetic - add note about immutable sets' attributes being un-redefinable - descendant sets can now have attributes added to them - fix editing loose ene in the Impurity section --- nix.html.markdown | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'nix.html.markdown') diff --git a/nix.html.markdown b/nix.html.markdown index d078395a..5941f0e6 100644 --- a/nix.html.markdown +++ b/nix.html.markdown @@ -4,6 +4,7 @@ filename: learn.nix contributors: - ["Chris Martin", "http://chris-martin.org/"] - ["Rommel Martinez", "https://ebzzry.io"] + - ["Javier Candeira", "https://candeira.com/"] --- Nix is a simple functional language developed for the @@ -12,7 +13,7 @@ Nix is a simple functional language developed for the You can evaluate Nix expressions using [nix-instantiate](https://nixos.org/nix/manual/#sec-nix-instantiate) -or [`nix-repl`](https://github.com/edolstra/nix-repl). +or [`nix repl`](https://nixos.org/nix/manual/#ssec-relnotes-2.0). ``` with builtins; [ @@ -39,18 +40,26 @@ with builtins; [ #=> "a" - # Integers + # Integers and Floats #========================================= - # Integers are the only numeric type. + # There are two numeric types: integers and floats 1 0 42 (-3) # Some integers + 123.43 .27e13 # A couple of floats + + # Operations will preserve numeric type + (4 + 6 + 12 - 2) # Addition #=> 20 + (4 - 2.5) + #=> 1.5 (7 / 2) # Division #=> 3 + (7 / 2.0) + #=> 3.5 # Strings @@ -238,13 +247,20 @@ with builtins; [ }.a.c #=> { d = 2; e = 3; } - # An attribute's descendants cannot be assigned in this - # way if the attribute itself has been directly assigned. + # Sets are immutable, so you can't redefine an attribute: + { + a = { b = 1; }; + a.b = 2; + } + #=> attribute 'a.b' at (string):3:5 already defined at (string):2:11 + + # However, an attribute's set members can also be defined piecewise + # way even if the attribute itself has been directly assigned. { a = { b = 1; }; a.c = 2; } - #=> error: attribute ‘a’ already defined + #=> { a = { b = 1; c = 2; }; } # With @@ -321,8 +337,8 @@ with builtins; [ #========================================= # Because repeatability of builds is critical to the Nix package - # manager, in which, functional purity is emphasized in the Nix - # language. But there are a few impurities. + # manager, functional purity is emphasized in the Nix language + # used to describe Nix packages. But there are a few impurities. # You can refer to environment variables. (getEnv "HOME") -- cgit v1.2.3 From 97aece4d68f286f8c3bda8cc3787f8cc90e537f8 Mon Sep 17 00:00:00 2001 From: walfie Date: Fri, 29 May 2020 20:55:46 -0400 Subject: Fix typo in nix documentation --- nix.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nix.html.markdown') diff --git a/nix.html.markdown b/nix.html.markdown index 5941f0e6..dde5dbec 100644 --- a/nix.html.markdown +++ b/nix.html.markdown @@ -279,7 +279,7 @@ with builtins; [ #=> 7 # This first line of tutorial starts with "with builtins;" - # because builtins is a set the contains all of the built-in + # because builtins is a set that contains all of the built-in # functions (length, head, tail, filter, etc.). This saves # us from having to write, for example, "builtins.length" # instead of just "length". -- cgit v1.2.3