Skip to content
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

Support additional builtin (global) names with scopedImport #72

Open
sivizius opened this issue Apr 12, 2023 · 0 comments
Open

Support additional builtin (global) names with scopedImport #72

sivizius opened this issue Apr 12, 2023 · 0 comments
Labels
A-nameres Area: name resolution A-ty Area: type system C-feature Catagory: feature

Comments

@sivizius
Copy link

sivizius commented Apr 12, 2023

Due to the scopedImport-builtin, nix-files can be imported with additional symbols. I use this mechanic for constructors e.g. here: https://github.com/sivizius/nixfiles/blob/development/services/printing/default.nix: It prevents importing such files from an unintended place while reducing some boilerplate like { Constructor, ... }:/with (import ./constructors.nix)/let inherit(import ./constructors) …;/…. Perhaps rust-like attributes, e.g. #![with(Foo,Bar)], might be a solution.

Besides scopedImport, the scope of a nix-file depends on other factors like version and settings (e.g. enableNativeCode enables __importNative and __exec, pureEval enables __currentTime and __currentSystem). On the other hand one might prefer an explicit let inherit(builtins) trace; in trace … over the usage of e.g. __trace. However, let inherit(builtins) true false null; in … is too much boilerplate.

Therefore I suggest to add an option implicitScope which defaults to null but could be set to e.g. [ "builtins", "false", "null", "true" ]. The former should mean: Determine implicit scope as before; and the latter: Throw undefined_name for every symbol not defined as a parameter, in a let … in, in implicitScope or with #![with(…)]…unless with is used, which IMHO should not be used outside foo = with bar; [ baz ]; anyway. I further suggest to allow type-parameters, e.g. #![with(foo:string,bar:int->bool)] and "implicitScope": [ "builtins:set", "false:bool", "null:null", "true:bool" ].

@oxalica oxalica added A-ty Area: type system C-feature Catagory: feature labels Apr 12, 2023
@oxalica oxalica changed the title Allow additional known symbols. Support additional builtin (global) names with scopedImport Apr 17, 2023
@oxalica oxalica added the A-nameres Area: name resolution label Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-nameres Area: name resolution A-ty Area: type system C-feature Catagory: feature
Projects
None yet
Development

No branches or pull requests

2 participants