-
Notifications
You must be signed in to change notification settings - Fork 90
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
Convert import
to statement instead of pseudo-fun
#1293
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable. We should add the requirement for parentheses around import
statements (when they get combined with something else) into the breaking changes list in the release notes.
Will do. There's also one spot I've missed in tests. |
I don't see why the added parentheses are needed, can you elaborate on this part? |
Currently |
Ah, I see, I misunderstood the context, but reading your original comment again, I see that this is entirely a parsing issue. Specifically, you want to create more parsing rules around I don't know which is most valuable: to be able to use In a sense your proposal has the advantage of forward compatibility: if we go for your more restrictive parsing rule, then we can always change our minds later, and make |
Another benefit of this approach is that we don't pretend that import is a function even though in Nickel it's a language construct.
Exactly. We can work around this in nickel-nix right now, for example, but without this change there would be no hope to add more functionality to |
Currently `import` is treated as a very special function that only accepts literal string as its first argument. It has following downsides: * Special handling of `import` is hidden. User can assume that its just a function while it's a special keyword. User might expect to be able to pass variables to it while it is only handled before typechecking and evaluation. * We can't extend `import` functionality without introducing new keywords which is not backward-compatible. This change makes `import` into another statement like `let` or `fun`, which means it cannot be confused with a function anymore. It also means that expressions like `import "foo.ncl" bar` and `import "foo.ncl" & {..}` are invalid, and `import` statement need to be put in parethesis: `(import "foo.ncl") bar`. For more context, see discussion in #329 (comment)
@vkleen I've added a line to the release notes, also fixed issue in benchmarks. |
I'm not sure what the original reason was for not having the benchmark typechecking be configured in the flake checks. If there even is a reason 😆 |
I guess, it was just easier. I see that there is |
I really wouldn't use this terminology. “Parsing at the same level as functions” and “pretending that it's a function” are completely different things. And it's actually what caused me to be confused at first. |
@@ -40,6 +40,7 @@ Breaking changes | |||
- Stdlib `string.Stringingable` -> `string.Stringable` by @vkleen in https://github.com/tweag/nickel/pull/1180 | |||
- Fix the type of `array.elem` by @yannham in https://github.com/tweag/nickel/pull/1223 | |||
- Change the enum tag start delimiter from backtick to single-quote by @vkleen in https://github.com/tweag/nickel/pull/1279 | |||
- `import` is now a statement, `import "foo.ncl" arg1 arg2` requires parenthesis now: `(import "foo.ncl") arg1 arg2`, see https://github.com/tweag/nickel/pull/1293 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a detail, but we should refrain from using statement I think. Everything is an expression in Nickel, including imports, which do have a value (as opposed to an if statement in e.g. C). It's not too bad in RELEASES.md, but just as a general note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. We should probably rephrase it in RELEASES as well, although I'm not sure how to properly put it to words.
Currently
import
is treated as a very special function that only accepts literal string as its first argument. It has following downsides:import
is hidden. User can assume that its just a function while it's a special keyword. User might expect to be able to pass variables to it while it is only handled before typechecking and evaluation.import
functionality without introducing new keywords which is not backward-compatible.This change makes
import
into another statement likelet
orfun
, which means it cannot be confused with a function anymore. It also means that expressions likeimport "foo.ncl" bar
andimport "foo.ncl" & {..}
are invalid, andimport
statement need to be put in parethesis:(import "foo.ncl") bar
.For more context, see discussion in #329 (comment)