digitalmars.D.learn - import and call
- Amex (24/24) Jun 02 2019 Tired of having to import a single function to call it.
- Basile B. (3/27) Jun 02 2019 Expression based import is possible using mixin, see
- Adam D. Ruppe (4/6) Jun 02 2019 That is wrong. Importing is always done of the whole module.
Tired of having to import a single function to call it. Since mod.foo(x); doesn't work since mod is not defined. we have to do import mod : foo; foo(x); Why not mod:foo(x)? or mod#foo(x) or mod foo(x) or whatever Reduces 50% of the lines and reduces the import symbol. I realize that we could do import m = mod; m.foo(x); but the idea is to only import the single function. I'm not sure if it matters. I thought importing single functions were suppose to be faster. Am I wrong? The idea is to reduce having to litter the code with imports which I find I'm always having to do, or to make them global... just for a few calls in to them.
Jun 02 2019
On Sunday, 2 June 2019 at 19:38:11 UTC, Amex wrote:Tired of having to import a single function to call it. Since mod.foo(x); doesn't work since mod is not defined. we have to do import mod : foo; foo(x); Why not mod:foo(x)? or mod#foo(x) or mod foo(x) or whatever Reduces 50% of the lines and reduces the import symbol. I realize that we could do import m = mod; m.foo(x); but the idea is to only import the single function. I'm not sure if it matters. I thought importing single functions were suppose to be faster. Am I wrong? The idea is to reduce having to litter the code with imports which I find I'm always having to do, or to make them global... just for a few calls in to them.Expression based import is possible using mixin, see https://dlang.org/blog/2017/02/13/a-new-import-idiom/
Jun 02 2019
On Sunday, 2 June 2019 at 19:38:11 UTC, Amex wrote:I thought importing single functions were suppose to be faster. Am I wrong?That is wrong. Importing is always done of the whole module. All the `: func` thing does is limit the things introduced to the namespace.
Jun 02 2019