digitalmars.D.learn - import strangeness with std.stdio.write
- psychoticRabbit (15/15) Feb 13 2018 So, strange problem below.
- rikki cattermole (3/23) Feb 13 2018 write exists in both, writeln exists only in std.stdio.
- psychoticRabbit (6/30) Feb 13 2018 oh..you must have posted as I why posting ;-)
- bauss (10/42) Feb 13 2018 What you can do is use aliases to use both functions.
- psychoticRabbit (3/11) Feb 13 2018 that's a nice simple solution.
- ixid (6/8) Feb 13 2018 It does seem a little silly to have a name clash with such a
- Seb (5/14) Feb 13 2018 Yes, I think it would be worthwhile.
- psychoticRabbit (6/21) Feb 13 2018 I should add, that this problem seems directly related to
- ketmar (7/21) Feb 13 2018 `std.file` has function named `write()` too. and local import completely...
- psychoticRabbit (16/20) Feb 13 2018 "..local import completely shadows global imports"
- ketmar (3/12) Feb 13 2018 it's easy: just take a look at `std.file.write()`. first, it require two...
- psychoticRabbit (3/18) Feb 13 2018 oh..function overloading..makes sense.
So, strange problem below. The commented-out line will not compile (if I un-comment it), unless I either move std.stdio into main, or, move std.file out of main. Whereas writeln works just fine as is. --------------------- module test; import std.stdio; void main() { import std.file; //write("hello"); writeln("hello again"); } -----------------------
Feb 13 2018
On 13/02/2018 1:46 PM, psychoticRabbit wrote:So, strange problem below. The commented-out line will not compile (if I un-comment it), unless I either move std.stdio into main, or, move std.file out of main. Whereas writeln works just fine as is. --------------------- module test; import std.stdio; void main() { import std.file; //write("hello"); writeln("hello again"); } -----------------------write exists in both, writeln exists only in std.stdio. Use named imports to pick which write you want.
Feb 13 2018
On Tuesday, 13 February 2018 at 13:52:37 UTC, rikki cattermole wrote:On 13/02/2018 1:46 PM, psychoticRabbit wrote:oh..you must have posted as I why posting ;-) That makes sense then. Thanks for clearing that up. And I should have read the compiler message more clearly..cause the answer was in that error message (more or less)So, strange problem below. The commented-out line will not compile (if I un-comment it), unless I either move std.stdio into main, or, move std.file out of main. Whereas writeln works just fine as is. --------------------- module test; import std.stdio; void main() { import std.file; //write("hello"); writeln("hello again"); } -----------------------write exists in both, writeln exists only in std.stdio. Use named imports to pick which write you want.
Feb 13 2018
On Tuesday, 13 February 2018 at 13:56:17 UTC, psychoticRabbit wrote:On Tuesday, 13 February 2018 at 13:52:37 UTC, rikki cattermole wrote:What you can do is use aliases to use both functions. import io = std.stdio; void main() { import file = std.file; file.write("hello"); io.writeln("hello again"); }On 13/02/2018 1:46 PM, psychoticRabbit wrote:oh..you must have posted as I why posting ;-) That makes sense then. Thanks for clearing that up. And I should have read the compiler message more clearly..cause the answer was in that error message (more or less)So, strange problem below. The commented-out line will not compile (if I un-comment it), unless I either move std.stdio into main, or, move std.file out of main. Whereas writeln works just fine as is. --------------------- module test; import std.stdio; void main() { import std.file; //write("hello"); writeln("hello again"); } -----------------------write exists in both, writeln exists only in std.stdio. Use named imports to pick which write you want.
Feb 13 2018
On Tuesday, 13 February 2018 at 14:21:31 UTC, bauss wrote:What you can do is use aliases to use both functions. import io = std.stdio; void main() { import file = std.file; file.write("hello"); io.writeln("hello again"); }that's a nice simple solution. thanks.
Feb 13 2018
On Tuesday, 13 February 2018 at 13:52:37 UTC, rikki cattermole wrote:write exists in both, writeln exists only in std.stdio. Use named imports to pick which write you want.It does seem a little silly to have a name clash with such a commonly used function. Would it not be better to rename std.file.write to something like writeFile and deprecate the current name?
Feb 13 2018
On Tuesday, 13 February 2018 at 16:55:10 UTC, ixid wrote:On Tuesday, 13 February 2018 at 13:52:37 UTC, rikki cattermole wrote:Yes, I think it would be worthwhile. Especially that we will allow importing all of Phobos at once in 2.079: https://dlang.org/changelog/pending.html#std-experimental-scriptingwrite exists in both, writeln exists only in std.stdio. Use named imports to pick which write you want.It does seem a little silly to have a name clash with such a commonly used function. Would it not be better to rename std.file.write to something like writeFile and deprecate the current name?
Feb 13 2018
On Tuesday, 13 February 2018 at 13:46:11 UTC, psychoticRabbit wrote:So, strange problem below. The commented-out line will not compile (if I un-comment it), unless I either move std.stdio into main, or, move std.file out of main. Whereas writeln works just fine as is. --------------------- module test; import std.stdio; void main() { import std.file; //write("hello"); writeln("hello again"); } -----------------------I should add, that this problem seems directly related to std.file. i.e. if I replace std.file, with say, std.conv, then the write function (once uncommented) will compile ok.
Feb 13 2018
psychoticRabbit wrote:So, strange problem below. The commented-out line will not compile (if I un-comment it), unless I either move std.stdio into main, or, move std.file out of main. Whereas writeln works just fine as is. --------------------- module test; import std.stdio; void main() { import std.file; //write("hello"); writeln("hello again"); } -----------------------`std.file` has function named `write()` too. and local import completely shadows global imports (i.e. it removes global imports from overload set for the given scope), hence `std.stdio.write()` is not available there. this is done by purpose, so your code won't accidentally use wrong function. you can bring `std.stdio` functions back by adding local `import std.stdio;`, for example.
Feb 13 2018
On Tuesday, 13 February 2018 at 13:57:38 UTC, ketmar wrote:`std.file` has function named `write()` too. and local import completely shadows global imports (i.e. it removes global imports from overload set for the given scope), hence `std.stdio.write()` is not available there."..local import completely shadows global imports" oh... I didn't realised imports are subject to scope rules in that way. This new knowledge will certainly prevent some ongoing confusion ;-) thanks. Also, if I do this below, how does the compiler choose the correct write function? import std.stdio; import std.file; void main() { write("hello"); writeln("hello again"); }
Feb 13 2018
psychoticRabbit wrote:Also, if I do this below, how does the compiler choose the correct write function? import std.stdio; import std.file; void main() { write("hello"); writeln("hello again"); }it's easy: just take a look at `std.file.write()`. first, it require two arguments. this is enough to rule `stf.file.write()` out in your case.
Feb 13 2018
On Tuesday, 13 February 2018 at 14:18:05 UTC, ketmar wrote:psychoticRabbit wrote:oh..function overloading..makes sense. thanks again.Also, if I do this below, how does the compiler choose the correct write function? import std.stdio; import std.file; void main() { write("hello"); writeln("hello again"); }it's easy: just take a look at `std.file.write()`. first, it require two arguments. this is enough to rule `stf.file.write()` out in your case.
Feb 13 2018