digitalmars.D.learn - Multiple selective imports on one line
- earthfront (17/17) Dec 23 2015 I'm using hackerpilot's excellent textadept plugin + DCD, Dfmt,
- Jakob Ovrum (5/22) Dec 23 2015 There's no `array` in std.algorithm, and I don't see more than
- earthfront (8/22) Dec 23 2015 Sorry, no, I didn't want that. I should have typed above:
- Basile B. (9/16) Dec 23 2015 This is not available in the grammar. You can still open a
- earthfront (37/42) Dec 24 2015 OK. I'm putting in my vote for this, and maybe even write up a
- ZombineDev (10/27) Dec 23 2015 Actually array() is from sts.array and correct way to use
- earthfront (6/15) Dec 23 2015 I hadn't compiled yet, so the array thing is indeed an error.
- ZombineDev (7/24) Dec 23 2015 Yes, it is not allowed by the grammar. I think the reason is that
- Joakim (7/24) Dec 28 2015 You really shouldn't have to do this by hand. I wish dfmt could
I'm using hackerpilot's excellent textadept plugin + DCD, Dfmt, and Dscanner. Upon saving files, it produces suggestions, much like warnings from the compiler. One suggestion is to use selective imports in local scopes. OK, I'll do that. Now I'm left with a smattering of lines which are just selective imports from a single module: void foo() { import std.exception:enforce; import std.algorithm:array; import std.algorithm.iteration:filter; import std.functional:memoize; //..Work.. } What is the proper way to combine these into one line?
Dec 23 2015
On Wednesday, 23 December 2015 at 10:51:52 UTC, earthfront wrote:I'm using hackerpilot's excellent textadept plugin + DCD, Dfmt, and Dscanner. Upon saving files, it produces suggestions, much like warnings from the compiler. One suggestion is to use selective imports in local scopes. OK, I'll do that. Now I'm left with a smattering of lines which are just selective imports from a single module: void foo() { import std.exception:enforce; import std.algorithm:array; import std.algorithm.iteration:filter; import std.functional:memoize; //..Work.. } What is the proper way to combine these into one line?There's no `array` in std.algorithm, and I don't see more than one import per module in your example, but I'm guessing what you want is: import mod : a, b, c; // import a, b and c from mod
Dec 23 2015
On Wednesday, 23 December 2015 at 11:00:19 UTC, Jakob Ovrum wrote:On Wednesday, 23 December 2015 at 10:51:52 UTC, earthfront wrote:Sorry, no, I didn't want that. I should have typed above: "I'm left with lines which are selective imports from various modules." My goal is to import several symbols from different modules on one line. I'm trying to figure out if it's possible or not. It makes the code more concise in some cases.Now I'm left with a smattering of lines which are just selective imports from a single module: import std.exception:enforce; import std.algorithm:array; import std.algorithm.iteration:filter; import std.functional:memoize; What is the proper way to combine these into one line?There's no `array` in std.algorithm, and I don't see more than one import per module in your example, but I'm guessing what you want is: import mod : a, b, c; // import a, b and c from mod
Dec 23 2015
On Wednesday, 23 December 2015 at 19:34:26 UTC, earthfront wrote:On Wednesday, 23 December 2015 at 11:00:19 UTC, Jakob Ovrum wrote: [...] My goal is to import several symbols from different modules on one line. I'm trying to figure out if it's possible or not. It makes the code more concise in some cases.This is not available in the grammar. You can still open a duplicate enhancement request. https://issues.dlang.org/show_bug.cgi?id=14704 see also: http://forum.dlang.org/post/trrxoacvpyyqrdfqxcvx forum.dlang.org I remember also another NG thread about this. A guy wanted this feature because he thought that this would allow him to write faster during a Hackathlon or something like that.
Dec 23 2015
On Wednesday, 23 December 2015 at 20:56:39 UTC, Basile B. wrote:This is not available in the grammar. You can still open a duplicate enhancement request. https://issues.dlang.org/show_bug.cgi?id=14704 see also: http://forum.dlang.org/post/trrxoacvpyyqrdfqxcvx forum.dlang.orgOK. I'm putting in my vote for this, and maybe even write up a pull request. The value from this comes when using "component-oriented" programming, as touted by AA and WB: http://www.drdobbs.com/architecture-and-design/component-programming-in-d/240008321 The combination of the good practice of local selective imports, and the use of various library functions to perform component oriented programming, results in verbose local "import" statements. View the example below. The import section is nearly as dense as the component oriented block doing the actual work. This is smelly. <CODE> void main( string args[] ) { import std.exception: enforce; import std.array: array; import std.algorithm.iteration: map,filter; import std.string: removechars; //..snip ..// auto file = File( args[1] ); auto result = file.byLineCopy( KeepTerminator.no, ',') .array .map!(a => removechars!string( a, "\"" ) ) .filter!isTriangleWord .array .length; writeln("Number of triangle words: ", result); } </CODE> Understandably, this isn't a huge priority, but a spot for improvement none-the-less. Dennis M. Ritchie's design in his comment seems to be the most concise: import {std.array:array; std.algorithm.iteration:map,filter};
Dec 24 2015
On Wednesday, 23 December 2015 at 10:51:52 UTC, earthfront wrote:I'm using hackerpilot's excellent textadept plugin + DCD, Dfmt, and Dscanner. Upon saving files, it produces suggestions, much like warnings from the compiler. One suggestion is to use selective imports in local scopes. OK, I'll do that. Now I'm left with a smattering of lines which are just selective imports from a single module: void foo() { import std.exception:enforce; import std.algorithm:array; import std.algorithm.iteration:filter; import std.functional:memoize; //..Work.. } What is the proper way to combine these into one line?Actually array() is from sts.array and correct way to use selective imports is: import std.exception : enforce; import std.array : array; import std.algorithm.iteration : filter; import std.functional : memoize; If you want to import several symbols from one module, you can list them after the column like so: import std.algorithm : any, find, sort /*, etc... */;
Dec 23 2015
On Wednesday, 23 December 2015 at 11:12:22 UTC, ZombineDev wrote:Actually array() is from sts.array and correct way to use selective imports is: import std.exception : enforce; import std.array : array; import std.algorithm.iteration : filter; import std.functional : memoize; If you want to import several symbols from one module, you can list them after the column like so: import std.algorithm : any, find, sort /*, etc... */;I hadn't compiled yet, so the array thing is indeed an error. So there's no way to combine these _selective_ imports on a single line, like I can with regular _module_ imports: import std.exception, std.array, std.functional; Correct?
Dec 23 2015
On Wednesday, 23 December 2015 at 19:27:31 UTC, earthfront wrote:On Wednesday, 23 December 2015 at 11:12:22 UTC, ZombineDev wrote:Yes, it is not allowed by the grammar. I think the reason is that the list items would become ambiguous (the difference between selected symbols and module names could only be revealed after semantic analysis). See for example: import abc : cba, dcb, bca : acb, dbc; // What is dbc? A module or a member of bca?Actually array() is from sts.array and correct way to use selective imports is: import std.exception : enforce; import std.array : array; import std.algorithm.iteration : filter; import std.functional : memoize; If you want to import several symbols from one module, you can list them after the column like so: import std.algorithm : any, find, sort /*, etc... */;I hadn't compiled yet, so the array thing is indeed an error. So there's no way to combine these _selective_ imports on a single line, like I can with regular _module_ imports: import std.exception, std.array, std.functional; Correct?
Dec 23 2015
On Wednesday, 23 December 2015 at 10:51:52 UTC, earthfront wrote:I'm using hackerpilot's excellent textadept plugin + DCD, Dfmt, and Dscanner. Upon saving files, it produces suggestions, much like warnings from the compiler. One suggestion is to use selective imports in local scopes. OK, I'll do that. Now I'm left with a smattering of lines which are just selective imports from a single module: void foo() { import std.exception:enforce; import std.algorithm:array; import std.algorithm.iteration:filter; import std.functional:memoize; //..Work.. } What is the proper way to combine these into one line?You really shouldn't have to do this by hand. I wish dfmt could do this for us, so that you develop with all the modules imported at the top, then run dfmt and it scopes all the imports and adds the selective import of symbols. I've been thinking about implementing a tool to do this myself, will get around to it someday.
Dec 28 2015
On Monday, 28 December 2015 at 14:09:30 UTC, Joakim wrote:I wish dfmt could do this for us, so that you develop with all the modules imported at the top, then run dfmt and it scopes all the imports and adds the selective import of symbols. I've been thinking about implementing a tool to do this myself, will get around to it someday.This is not formating (what DFMT is aimed to do) this is refactoring.
Dec 28 2015
On Monday, 28 December 2015 at 14:16:36 UTC, Basile B. wrote:On Monday, 28 December 2015 at 14:09:30 UTC, Joakim wrote:oops, my answer could lead to a misunderstanding. I meant: This is not formating (what DFMT is aimed to do), but rather refactoring.I wish dfmt could do this for us, so that you develop with all the modules imported at the top, then run dfmt and it scopes all the imports and adds the selective import of symbols. I've been thinking about implementing a tool to do this myself, will get around to it someday.This is not formating (what DFMT is aimed to do) this is refactoring.
Dec 28 2015
On Monday, 28 December 2015 at 14:16:36 UTC, Basile B. wrote:On Monday, 28 December 2015 at 14:09:30 UTC, Joakim wrote:You're right, I was thinking about patching Dscanner to do it, just mentioned dfmt here without thinking about that aspect.I wish dfmt could do this for us, so that you develop with all the modules imported at the top, then run dfmt and it scopes all the imports and adds the selective import of symbols. I've been thinking about implementing a tool to do this myself, will get around to it someday.This is not formating (what DFMT is aimed to do) this is refactoring.
Dec 28 2015