Open solo989 opened 3 years ago
Other solutions:
system.nim
.But what you propose makes sense too.
Could we prioritize based on import order, with system/other default imports being at the lowest priority? If you use from import
then only the symbols you import would have priority.
I'd prefer that users special-cased this stuff rather than having Nim always behave inconsistently merely for convenience of lazy users.
This can be worked around by putting import system except repr,$ at the top of your file but unfortunately that also drops a lot of other useful procedures.
We should instead allow specifying overloads in import/export
syntax, eg:
import foo except `$`(a: Bar)
from foo import `$`(a: Bar1), `$`(a: Bar2)
export `$(a: Bar3)`
for system this could work as follows, since string
+ friends is not yet defined:
from system import nil
import system except `$`(a: system.string)
This doesn't special case system
nor introduce a priority amongst imports, which sounds like a can of worms unless you can describe exactly how that would work.
While that sounds useful it's not required either. This works:
import system except repr
echo system.repr(12)
it's not required either.
OP also mentioned $
:
I also tried to overwrite $(type) but ultimately made by own toStr procedure for types. putting import system except repr,$ at the top of your file but unfortunately that also drops a lot of other useful procedures
We should instead allow specifying overloads in import/export syntax
Can we have a separate RFC for this? I think this could be very useful and I'd like to hear separate opinions about it.
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 30 days.
Procedures created outside of system should have higher priority then procedures created inside system. If an ambiguity error would be thrown the procedure created outside of system would be chosen over any procedures defined in system.
Any additions to the standard library shouldn't cause conflicts with procedures defined in user code. This would be minimized if user defined procedures took priority.
I noticed this problem when I recently switched from the standard gc to arc and my overwrite of repr(NimNode) was causing ambiguity errors. I also tried to overwrite $(type) but ultimately made by own toStr procedure for types.
This can be worked around by putting import system except repr,$ at the top of your file but unfortunately that also drops a lot of other useful procedures. Also requiring users of your code to do this as well in the case of generics would be tedious. You could also qualify imports with myModule.repr.