digitalmars.D.learn - What is "stringImportPaths"
- mrphobby (10/10) Dec 06 2017 Can anyone explain what "stringImportPaths" is? I have seen this
- =?UTF-8?Q?Ali_=c3=87ehreli?= (5/6) Dec 06 2017 That's the import statement. -J compiler switch is about the import
- Atila Neves (3/9) Dec 06 2017 I went looking for that and didn't find it! I searched for
- Atila Neves (20/30) Dec 06 2017 stringImportPaths are to -J what importPaths are to -I. In D you
- Jacob Carlborg (12/22) Dec 07 2017 There are two kinds of language constructs that uses the "import"
- mrphobby (7/18) Dec 08 2017 Ok thanks! I couldn't find that in the docs so kudos for pointing
- =?UTF-8?Q?Ali_=c3=87ehreli?= (20/22) Dec 08 2017 We don't want any more keywords. :) (D's keywords are context-independen...
Can anyone explain what "stringImportPaths" is? I have seen this being used in dub.json files and I think I kind of know what it does, but I haven't been able to find a clear explanation in any documentation of what it does. It does not look like anything I'm familiar with from other languages. I understand it can be used for resources but I have seen it being used with both text files and binary files so I'm a bit confused. The documentation says I can import "whatever", but that feels a bit weird since importing is a construct used for importing symbols, right?
Dec 06 2017
On 12/06/2017 11:05 AM, mrphobby wrote:importing is a construct used for importing symbols, right?That's the import statement. -J compiler switch is about the import expression: https://dlang.org/spec/expression.html#import_expressions Ali
Dec 06 2017
On Wednesday, 6 December 2017 at 20:17:55 UTC, Ali Çehreli wrote:On 12/06/2017 11:05 AM, mrphobby wrote:I went looking for that and didn't find it! I searched for "string imports" but apparently that doesn't quite work.importing is a construct used for importing symbols, right?That's the import statement. -J compiler switch is about the import expression: https://dlang.org/spec/expression.html#import_expressions Ali
Dec 06 2017
On Wednesday, 6 December 2017 at 19:05:24 UTC, mrphobby wrote:Can anyone explain what "stringImportPaths" is? I have seen this being used in dub.json files and I think I kind of know what it does, but I haven't been able to find a clear explanation in any documentation of what it does. It does not look like anything I'm familiar with from other languages. I understand it can be used for resources but I have seen it being used with both text files and binary files so I'm a bit confused. The documentation says I can import "whatever", but that feels a bit weird since importing is a construct used for importing symbols, right?stringImportPaths are to -J what importPaths are to -I. In D you can import a string directly into your program, similarly to #include in C and C++. Imagine it as kind of a mixin(read("filename")) (which you can't do). For security concerns, dmd only looks for "filename" in directories passed in with -J. A silly example: foo.d: import std.stdio; void main() { mixin(`auto values = [` ~ import("foo.txt") ~ `];`); writeln(values); } foo.txt: 1, 2, 3, 4, 5 $ dmd -J. foo.d $ ./foo [1, 2, 3, 4, 5] Atila
Dec 06 2017
On 2017-12-06 20:05, mrphobby wrote:Can anyone explain what "stringImportPaths" is? I have seen this being used in dub.json files and I think I kind of know what it does, but I haven't been able to find a clear explanation in any documentation of what it does. It does not look like anything I'm familiar with from other languages. I understand it can be used for resources but I have seen it being used with both text files and binary files so I'm a bit confused. The documentation says I can import "whatever", but that feels a bit weird since importing is a construct used for importing symbols, right?There are two kinds of language constructs that uses the "import" keyword. One is the "Import Declaration" [1] which is the most common one and is used to import other symbols. The other language construct is the "Import Expression" [2], which is used to read a file at compile time and put its content into a string literal in your source code. Anything specified to the "stringImportPaths" build setting will be sent to the compiler with the -J flag. [1] https://dlang.org/spec/module.html#ImportDeclaration [2] https://dlang.org/spec/expression.html#import_expressions -- /Jacob Carlborg
Dec 07 2017
On Thursday, 7 December 2017 at 09:47:31 UTC, Jacob Carlborg wrote:On 2017-12-06 20:05, mrphobby wrote: There are two kinds of language constructs that uses the "import" keyword. One is the "Import Declaration" [1] which is the most common one and is used to import other symbols. The other language construct is the "Import Expression" [2], which is used to read a file at compile time and put its content into a string literal in your source code. Anything specified to the "stringImportPaths" build setting will be sent to the compiler with the -J flag. [1] https://dlang.org/spec/module.html#ImportDeclaration [2] https://dlang.org/spec/expression.html#import_expressionsOk thanks! I couldn't find that in the docs so kudos for pointing me to it. I still think using the word "import" is confusing. Would rather have it called "load" or something. But at least I understand it now :)
Dec 08 2017
On 12/08/2017 12:10 PM, mrphobby wrote:I still think using the word "import" is confusing. Would rather have it called "load" or something. But at least I understand it now :)We don't want any more keywords. :) (D's keywords are context-independent.) An unfortunate example was the "body", which is on its way out of being a keyword. Instead, the "do" keyword is overloaded to take "body"s responsibility: int foo(int i) in { assert(i < 100); } out(result) { assert(result > i); } do { auto body = i + 7; // YAY! :) return body; } void main() { foo(42); } Of course the same can be said about any other keyword but life is not fair. :) Ali
Dec 08 2017