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

syntax request: from std/[foo1,foo2] import nil ; from "." / [foo1,foo2] import bar1, bar2, bar3 #76

Closed
timotheecour opened this issue Dec 5, 2018 · 5 comments
Labels

Comments

@timotheecour
Copy link
Member

proposal 1

accept this syntax:

from std/[foo1,foo2] import nil # equivalent to: from std/foo1 import nil; from std/foo2 import nil; 
from "." / [foo1,foo2] import nil # ditto

proposal 2

furthermore, also accept this syntax

from "." / [foo1,foo2] import bar1, bar2, bar3

with meaning:
find each symbol bar1,bar2,bar3 somewhere in import list
The semantics are clear:
CT error if one of these symbols can't be found in import list
no error if a symbol is found in more than 1 module in import list (the usual overloading rules shall apply)

benefits

  • more concise syntax
  • in particular, proposal 1 promotes better code for users of that new feature: less symbol pollution (since it requires fully qualified names) compared to import std/[foo1,foo2]
@krux02
Copy link
Contributor

krux02 commented Dec 5, 2018

I don't like it. Not importing everything from a module is rarely used feature. I don't see the need to improve the syntax for it.

@timotheecour
Copy link
Member Author

timotheecour commented Dec 5, 2018

is rarely used feature

I use it when I have a lot of imports in a module and I want to reduce likelihood of symbol clashes.
The way I intend to use this feature (from proposal 1) is:

from std/[foo1,foo2] import nil # I use only a few from these; I'll need to fully qualify them
import std/[foo3,foo4] # I use a lot of symbols from these

@narimiran narimiran transferred this issue from nim-lang/Nim Jan 2, 2019
@awr1
Copy link

awr1 commented Aug 23, 2019

I think deciding to use fully qualified imports is a matter of personal style rather than something that should be outright discouraged. I prefer to just use import too, but sometimes I need to more careful about avoiding name collisions. I like the 2nd proposal too.

Why the "." / syntax? Since we can import multiple modules in the same directory with import x, y, z, should not from a, b, c import nil suffice?

Also I feel the need to restate here that this does instigate a grammar change, albeit a small one. I'm iffy on grammar changes at this point but for this I don't really think it's too much of a big deal.

@timotheecour
Copy link
Member Author

timotheecour commented Aug 23, 2019

Why the "." / syntax?

that RFC doesn't mandate using "."/, it's an orthogonal issue: from a, b, c import nil would work as well. The reason I used it here is because import foo is ambiguous: it can either import foo.nim in path or foo in currentModule.parentDir/foo.nim

implementing this (proposal 1 in particular) is easy and makes nim's features more orthogonal

@github-actions
Copy link

github-actions bot commented Jun 6, 2023

This RFC is stale because it has been open for 1095 days with no activity. Contribute a fix or comment on the issue, or it will be closed in 7 days.

@github-actions github-actions bot added the Stale label Jun 6, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants