Skip to content

Commit 4e32693

Browse files
committed
add lambdas for nix
1 parent 6648085 commit 4e32693

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

specs/~lambdas.json

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"clojure": "(fn [] \"world\")",
1818
"lisp": "(lambda () \"world\")",
1919
"pwsh": "\"world\"",
20-
"go": "func() string { return \"world\" }"
20+
"go": "func() string { return \"world\" }",
21+
"nix": "v: \"world\""
2122
}
2223
},
2324
"template": "Hello, {{lambda}}!",
@@ -39,7 +40,8 @@
3940
"clojure": "(fn [] \"{{planet}}\")",
4041
"lisp": "(lambda () \"{{planet}}\")",
4142
"pwsh": "\"{{planet}}\"",
42-
"go": "func() string { return \"{{planet}}\" }"
43+
"go": "func() string { return \"{{planet}}\" }",
44+
"nix": "v: \"{{planet}}\""
4345
}
4446
},
4547
"template": "Hello, {{lambda}}!",
@@ -61,7 +63,8 @@
6163
"clojure": "(fn [] \"|planet| => {{planet}}\")",
6264
"lisp": "(lambda () \"|planet| => {{planet}}\")",
6365
"pwsh": "\"|planet| => {{planet}}\"",
64-
"go": "func() string { return \"|planet| => {{planet}}\" }"
66+
"go": "func() string { return \"|planet| => {{planet}}\" }",
67+
"nix": "v: \"|planet| => {{planet}}\""
6568
}
6669
},
6770
"template": "{{= | | =}}\nHello, (|&lambda|)!",
@@ -82,7 +85,8 @@
8285
"clojure": "(def g (atom 0)) (fn [] (swap! g inc))",
8386
"lisp": "(let ((g 0)) (lambda () (incf g)))",
8487
"pwsh": "if (($null -eq $script:calls) -or ($script:calls -ge 3)){$script:calls=0}; ++$script:calls; $script:calls",
85-
"go": "func() func() int { g := 0; return func() int { g++; return g } }()"
88+
"go": "func() func() int { g := 0; return func() int { g++; return g } }()",
89+
"nix": "v: state @ { count ? 1 }: { result = count; state = state // { count = count + 1; }; }"
8690
}
8791
},
8892
"template": "{{lambda}} == {{{lambda}}} == {{lambda}}",
@@ -103,7 +107,8 @@
103107
"clojure": "(fn [] \">\")",
104108
"lisp": "(lambda () \">\")",
105109
"pwsh": "\">\"",
106-
"go": "func() string { return \">\" }"
110+
"go": "func() string { return \">\" }",
111+
"nix": "v: \">\""
107112
}
108113
},
109114
"template": "<{{lambda}}{{{lambda}}}",
@@ -125,7 +130,8 @@
125130
"clojure": "(fn [text] (if (= text \"{{x}}\") \"yes\" \"no\"))",
126131
"lisp": "(lambda (text) (if (string= text \"{{x}}\") \"yes\" \"no\"))",
127132
"pwsh": "if ($args[0] -eq \"{{x}}\") {\"yes\"} else {\"no\"}",
128-
"go": "func(text string) string { if text == \"{{x}}\" { return \"yes\" } else { return \"no\" } }"
133+
"go": "func(text string) string { if text == \"{{x}}\" { return \"yes\" } else { return \"no\" } }",
134+
"nix": "text: if text == \"{{x}}\" then \"yes\" else \"no\""
129135
}
130136
},
131137
"template": "<{{#lambda}}{{x}}{{/lambda}}>",
@@ -147,7 +153,8 @@
147153
"clojure": "(fn [text] (str text \"{{planet}}\" text))",
148154
"lisp": "(lambda (text) (format nil \"~a{{planet}}~a\" text text))",
149155
"pwsh": "\"$($args[0]){{planet}}$($args[0])\"",
150-
"go": "func(text string) string { return text + \"{{planet}}\" + text }"
156+
"go": "func(text string) string { return text + \"{{planet}}\" + text }",
157+
"nix": "text: \"${text}{{planet}}${text}\""
151158
}
152159
},
153160
"template": "<{{#lambda}}-{{/lambda}}>",
@@ -169,7 +176,8 @@
169176
"clojure": "(fn [text] (str text \"{{planet}} => |planet|\" text))",
170177
"lisp": "(lambda (text) (format nil \"~a{{planet}} => |planet|~a\" text text))",
171178
"pwsh": "\"$($args[0]){{planet}} => |planet|$($args[0])\"",
172-
"go": "func(text string) string { return text + \"{{planet}} => |planet|\" + text }"
179+
"go": "func(text string) string { return text + \"{{planet}} => |planet|\" + text }",
180+
"nix": "text: \"${text}{{planet}} => |planet|${text}\""
173181
}
174182
},
175183
"template": "{{= | | =}}<|#lambda|-|/lambda|>",
@@ -190,7 +198,8 @@
190198
"clojure": "(fn [text] (str \"__\" text \"__\"))",
191199
"lisp": "(lambda (text) (format nil \"__~a__\" text))",
192200
"pwsh": "\"__$($args[0])__\"",
193-
"go": "func(text string) string { return \"__\" + text + \"__\" }"
201+
"go": "func(text string) string { return \"__\" + text + \"__\" }",
202+
"nix": "text: \"__${text}__\""
194203
}
195204
},
196205
"template": "{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}",
@@ -212,7 +221,8 @@
212221
"clojure": "(fn [text] false)",
213222
"lisp": "(lambda (text) (declare (ignore text)) nil)",
214223
"pwsh": "$false",
215-
"go": "func(text string) bool { return false }"
224+
"go": "func(text string) bool { return false }",
225+
"nix": "v: false"
216226
}
217227
},
218228
"template": "<{{^lambda}}{{static}}{{/lambda}}>",

specs/~lambdas.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ tests:
2626
lisp: '(lambda () "world")'
2727
pwsh: '"world"'
2828
go: 'func() string { return "world" }'
29+
nix: 'v: "world"'
2930
template: "Hello, {{lambda}}!"
3031
expected: "Hello, world!"
3132

@@ -44,6 +45,7 @@ tests:
4445
lisp: '(lambda () "{{planet}}")'
4546
pwsh: '"{{planet}}"'
4647
go: 'func() string { return "{{planet}}" }'
48+
nix: 'v: "{{planet}}"'
4749
template: "Hello, {{lambda}}!"
4850
expected: "Hello, world!"
4951

@@ -62,6 +64,7 @@ tests:
6264
lisp: '(lambda () "|planet| => {{planet}}")'
6365
pwsh: '"|planet| => {{planet}}"'
6466
go: 'func() string { return "|planet| => {{planet}}" }'
67+
nix: 'v: "|planet| => {{planet}}"'
6568
template: "{{= | | =}}\nHello, (|&lambda|)!"
6669
expected: "Hello, (|planet| => world)!"
6770

@@ -79,6 +82,7 @@ tests:
7982
lisp: '(let ((g 0)) (lambda () (incf g)))'
8083
pwsh: 'if (($null -eq $script:calls) -or ($script:calls -ge 3)){$script:calls=0}; ++$script:calls; $script:calls'
8184
go: 'func() func() int { g := 0; return func() int { g++; return g } }()'
85+
nix: 'v: state @ { count ? 1 }: { result = count; state = state // { count = count + 1; }; }'
8286
template: '{{lambda}} == {{{lambda}}} == {{lambda}}'
8387
expected: '1 == 2 == 3'
8488

@@ -96,6 +100,7 @@ tests:
96100
lisp: '(lambda () ">")'
97101
pwsh: '">"'
98102
go: 'func() string { return ">" }'
103+
nix: 'v: ">"'
99104
template: "<{{lambda}}{{{lambda}}}"
100105
expected: "<&gt;>"
101106

@@ -114,6 +119,7 @@ tests:
114119
lisp: '(lambda (text) (if (string= text "{{x}}") "yes" "no"))'
115120
pwsh: 'if ($args[0] -eq "{{x}}") {"yes"} else {"no"}'
116121
go: 'func(text string) string { if text == "{{x}}" { return "yes" } else { return "no" } }'
122+
nix: 'text: if text == "{{x}}" then "yes" else "no"'
117123
template: "<{{#lambda}}{{x}}{{/lambda}}>"
118124
expected: "<yes>"
119125

@@ -132,6 +138,7 @@ tests:
132138
lisp: '(lambda (text) (format nil "~a{{planet}}~a" text text))'
133139
pwsh: '"$($args[0]){{planet}}$($args[0])"'
134140
go: 'func(text string) string { return text + "{{planet}}" + text }'
141+
nix: 'text: "${text}{{planet}}${text}"'
135142
template: "<{{#lambda}}-{{/lambda}}>"
136143
expected: "<-Earth->"
137144

@@ -150,6 +157,7 @@ tests:
150157
lisp: '(lambda (text) (format nil "~a{{planet}} => |planet|~a" text text))'
151158
pwsh: '"$($args[0]){{planet}} => |planet|$($args[0])"'
152159
go: 'func(text string) string { return text + "{{planet}} => |planet|" + text }'
160+
nix: 'text: "${text}{{planet}} => |planet|${text}"'
153161
template: "{{= | | =}}<|#lambda|-|/lambda|>"
154162
expected: "<-{{planet}} => Earth->"
155163

@@ -167,6 +175,7 @@ tests:
167175
lisp: '(lambda (text) (format nil "__~a__" text))'
168176
pwsh: '"__$($args[0])__"'
169177
go: 'func(text string) string { return "__" + text + "__" }'
178+
nix: 'text: "__${text}__"'
170179
template: '{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}'
171180
expected: '__FILE__ != __LINE__'
172181

@@ -185,5 +194,6 @@ tests:
185194
lisp: '(lambda (text) (declare (ignore text)) nil)'
186195
pwsh: '$false'
187196
go: 'func(text string) bool { return false }'
197+
nix: 'v: false'
188198
template: "<{{^lambda}}{{static}}{{/lambda}}>"
189199
expected: "<>"

0 commit comments

Comments
 (0)