Skip to content

Add lambdas for nix #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions specs/~lambdas.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"clojure": "(fn [] \"world\")",
"lisp": "(lambda () \"world\")",
"pwsh": "\"world\"",
"go": "func() string { return \"world\" }"
"go": "func() string { return \"world\" }",
"nix": "v: \"world\""
}
},
"template": "Hello, {{lambda}}!",
Expand All @@ -39,7 +40,8 @@
"clojure": "(fn [] \"{{planet}}\")",
"lisp": "(lambda () \"{{planet}}\")",
"pwsh": "\"{{planet}}\"",
"go": "func() string { return \"{{planet}}\" }"
"go": "func() string { return \"{{planet}}\" }",
"nix": "v: \"{{planet}}\""
}
},
"template": "Hello, {{lambda}}!",
Expand All @@ -61,7 +63,8 @@
"clojure": "(fn [] \"|planet| => {{planet}}\")",
"lisp": "(lambda () \"|planet| => {{planet}}\")",
"pwsh": "\"|planet| => {{planet}}\"",
"go": "func() string { return \"|planet| => {{planet}}\" }"
"go": "func() string { return \"|planet| => {{planet}}\" }",
"nix": "v: \"|planet| => {{planet}}\""
}
},
"template": "{{= | | =}}\nHello, (|&lambda|)!",
Expand All @@ -82,7 +85,8 @@
"clojure": "(def g (atom 0)) (fn [] (swap! g inc))",
"lisp": "(let ((g 0)) (lambda () (incf g)))",
"pwsh": "if (($null -eq $script:calls) -or ($script:calls -ge 3)){$script:calls=0}; ++$script:calls; $script:calls",
"go": "func() func() int { g := 0; return func() int { g++; return g } }()"
"go": "func() func() int { g := 0; return func() int { g++; return g } }()",
"nix": "v: state @ { count ? 1 }: { result = count; state = state // { count = count + 1; }; }"
}
},
"template": "{{lambda}} == {{{lambda}}} == {{lambda}}",
Expand All @@ -103,7 +107,8 @@
"clojure": "(fn [] \">\")",
"lisp": "(lambda () \">\")",
"pwsh": "\">\"",
"go": "func() string { return \">\" }"
"go": "func() string { return \">\" }",
"nix": "v: \">\""
}
},
"template": "<{{lambda}}{{{lambda}}}",
Expand All @@ -125,7 +130,8 @@
"clojure": "(fn [text] (if (= text \"{{x}}\") \"yes\" \"no\"))",
"lisp": "(lambda (text) (if (string= text \"{{x}}\") \"yes\" \"no\"))",
"pwsh": "if ($args[0] -eq \"{{x}}\") {\"yes\"} else {\"no\"}",
"go": "func(text string) string { if text == \"{{x}}\" { return \"yes\" } else { return \"no\" } }"
"go": "func(text string) string { if text == \"{{x}}\" { return \"yes\" } else { return \"no\" } }",
"nix": "text: if text == \"{{x}}\" then \"yes\" else \"no\""
}
},
"template": "<{{#lambda}}{{x}}{{/lambda}}>",
Expand All @@ -147,7 +153,8 @@
"clojure": "(fn [text] (str text \"{{planet}}\" text))",
"lisp": "(lambda (text) (format nil \"~a{{planet}}~a\" text text))",
"pwsh": "\"$($args[0]){{planet}}$($args[0])\"",
"go": "func(text string) string { return text + \"{{planet}}\" + text }"
"go": "func(text string) string { return text + \"{{planet}}\" + text }",
"nix": "text: \"${text}{{planet}}${text}\""
}
},
"template": "<{{#lambda}}-{{/lambda}}>",
Expand All @@ -169,7 +176,8 @@
"clojure": "(fn [text] (str text \"{{planet}} => |planet|\" text))",
"lisp": "(lambda (text) (format nil \"~a{{planet}} => |planet|~a\" text text))",
"pwsh": "\"$($args[0]){{planet}} => |planet|$($args[0])\"",
"go": "func(text string) string { return text + \"{{planet}} => |planet|\" + text }"
"go": "func(text string) string { return text + \"{{planet}} => |planet|\" + text }",
"nix": "text: \"${text}{{planet}} => |planet|${text}\""
}
},
"template": "{{= | | =}}<|#lambda|-|/lambda|>",
Expand All @@ -190,7 +198,8 @@
"clojure": "(fn [text] (str \"__\" text \"__\"))",
"lisp": "(lambda (text) (format nil \"__~a__\" text))",
"pwsh": "\"__$($args[0])__\"",
"go": "func(text string) string { return \"__\" + text + \"__\" }"
"go": "func(text string) string { return \"__\" + text + \"__\" }",
"nix": "text: \"__${text}__\""
}
},
"template": "{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}",
Expand All @@ -212,7 +221,8 @@
"clojure": "(fn [text] false)",
"lisp": "(lambda (text) (declare (ignore text)) nil)",
"pwsh": "$false",
"go": "func(text string) bool { return false }"
"go": "func(text string) bool { return false }",
"nix": "v: false"
}
},
"template": "<{{^lambda}}{{static}}{{/lambda}}>",
Expand Down
10 changes: 10 additions & 0 deletions specs/~lambdas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tests:
lisp: '(lambda () "world")'
pwsh: '"world"'
go: 'func() string { return "world" }'
nix: 'v: "world"'
template: "Hello, {{lambda}}!"
expected: "Hello, world!"

Expand All @@ -44,6 +45,7 @@ tests:
lisp: '(lambda () "{{planet}}")'
pwsh: '"{{planet}}"'
go: 'func() string { return "{{planet}}" }'
nix: 'v: "{{planet}}"'
template: "Hello, {{lambda}}!"
expected: "Hello, world!"

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

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

Expand All @@ -96,6 +100,7 @@ tests:
lisp: '(lambda () ">")'
pwsh: '">"'
go: 'func() string { return ">" }'
nix: 'v: ">"'
template: "<{{lambda}}{{{lambda}}}"
expected: "<&gt;>"

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

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

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

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

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