www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - cannot call impure function

reply Michael <trash can.edu> writes:
Dear all,

Sorry for the potentially stupid question, but I'm a complete 
newbie to D. Why does compiling the following trivial code fail?

import std.stdio;

void main()
{
     writeln(3.14);
}

Error message:

/Library/D/dmd/src/phobos/std/format.d(1601): Error: pure 
function std.format.FormatSpec!char.FormatSpec.toString cannot 
call impure function 
std.format.FormatSpec!char.FormatSpec.toString!(Appender!string).toString
/Library/D/dmd/src/phobos/std/format.d(478): Error: template 
instance std.format.FormatSpec!char error instantiating
/Library/D/dmd/src/phobos/std/stdio.d(1590):        instantiated 
from here: formattedWrite!(LockingTextWriter, char, double)
/Library/D/dmd/src/phobos/std/stdio.d(3927):        instantiated 
from here: write!(double, char)
test1.d(5):        instantiated from here: writeln!double

Cheers,
Michael
Oct 04 2020
next sibling parent reply Paul Backus <snarwin gmail.com> writes:
On Sunday, 4 October 2020 at 16:48:24 UTC, Michael wrote:
 Dear all,

 Sorry for the potentially stupid question, but I'm a complete 
 newbie to D. Why does compiling the following trivial code fail?

 import std.stdio;

 void main()
 {
     writeln(3.14);
 }
Works fine for me using DMD 2.094.0 on Linux. What OS and compiler version are you using, and how did you install DMD?
Oct 04 2020
parent reply Michael <trash can.edu> writes:
On Sunday, 4 October 2020 at 17:01:44 UTC, Paul Backus wrote:
 On Sunday, 4 October 2020 at 16:48:24 UTC, Michael wrote:
 Dear all,

 Sorry for the potentially stupid question, but I'm a complete 
 newbie to D. Why does compiling the following trivial code 
 fail?

 import std.stdio;

 void main()
 {
     writeln(3.14);
 }
Works fine for me using DMD 2.094.0 on Linux. What OS and compiler version are you using, and how did you install DMD?
DMD64 D Compiler v2.094.0 on macOS 10.15.6
Oct 04 2020
next sibling parent Michael <trash can.edu> writes:
On Sunday, 4 October 2020 at 17:05:33 UTC, Michael wrote:
 On Sunday, 4 October 2020 at 17:01:44 UTC, Paul Backus wrote:
 On Sunday, 4 October 2020 at 16:48:24 UTC, Michael wrote:
 Dear all,

 Sorry for the potentially stupid question, but I'm a complete 
 newbie to D. Why does compiling the following trivial code 
 fail?

 import std.stdio;

 void main()
 {
     writeln(3.14);
 }
Works fine for me using DMD 2.094.0 on Linux. What OS and compiler version are you using, and how did you install DMD?
DMD64 D Compiler v2.094.0 on macOS 10.15.6
I did not use any compiler flags, but just: dmd test1.d
Oct 04 2020
prev sibling parent reply Mathias LANG <geod24 gmail.com> writes:
On Sunday, 4 October 2020 at 17:05:33 UTC, Michael wrote:
 On Sunday, 4 October 2020 at 17:01:44 UTC, Paul Backus wrote:
 On Sunday, 4 October 2020 at 16:48:24 UTC, Michael wrote:
 Dear all,

 Sorry for the potentially stupid question, but I'm a complete 
 newbie to D. Why does compiling the following trivial code 
 fail?

 import std.stdio;

 void main()
 {
     writeln(3.14);
 }
Works fine for me using DMD 2.094.0 on Linux. What OS and compiler version are you using, and how did you install DMD?
DMD64 D Compiler v2.094.0 on macOS 10.15.6
I cannot reproduce locally (macOS 10.15.6 too). How did you install DMD ?
Oct 04 2020
parent reply Michael <trash can.edu> writes:
On Sunday, 4 October 2020 at 17:37:52 UTC, Mathias LANG wrote:
 On Sunday, 4 October 2020 at 17:05:33 UTC, Michael wrote:
 On Sunday, 4 October 2020 at 17:01:44 UTC, Paul Backus wrote:
 On Sunday, 4 October 2020 at 16:48:24 UTC, Michael wrote:
 Dear all,

 Sorry for the potentially stupid question, but I'm a 
 complete newbie to D. Why does compiling the following 
 trivial code fail?

 import std.stdio;

 void main()
 {
     writeln(3.14);
 }
Works fine for me using DMD 2.094.0 on Linux. What OS and compiler version are you using, and how did you install DMD?
DMD64 D Compiler v2.094.0 on macOS 10.15.6
I cannot reproduce locally (macOS 10.15.6 too). How did you install DMD ?
I used the dmg file: dmd.2.094.0.dmg
Oct 04 2020
parent reply Michael <trash can.edu> writes:
On Sunday, 4 October 2020 at 17:43:13 UTC, Michael wrote:
 On Sunday, 4 October 2020 at 17:37:52 UTC, Mathias LANG wrote:
 On Sunday, 4 October 2020 at 17:05:33 UTC, Michael wrote:
 On Sunday, 4 October 2020 at 17:01:44 UTC, Paul Backus wrote:
 On Sunday, 4 October 2020 at 16:48:24 UTC, Michael wrote:
 Dear all,

 Sorry for the potentially stupid question, but I'm a 
 complete newbie to D. Why does compiling the following 
 trivial code fail?

 import std.stdio;

 void main()
 {
     writeln(3.14);
 }
Works fine for me using DMD 2.094.0 on Linux. What OS and compiler version are you using, and how did you install DMD?
DMD64 D Compiler v2.094.0 on macOS 10.15.6
I cannot reproduce locally (macOS 10.15.6 too). How did you install DMD ?
I used the dmg file: dmd.2.094.0.dmg
I reinstalled using the installation script (install.sh) and now it works. Still don't know why the dmg-based intstallation did not work. https://dlang.org/install.html Anyway, thanks for your responses!
Oct 04 2020
parent Mathias LANG <geod24 gmail.com> writes:
On Sunday, 4 October 2020 at 18:02:11 UTC, Michael wrote:
 On Sunday, 4 October 2020 at 17:43:13 UTC, Michael wrote:
 [...]
 I used the dmg file: dmd.2.094.0.dmg
I reinstalled using the installation script (install.sh) and now it works. Still don't know why the dmg-based intstallation did not work. https://dlang.org/install.html Anyway, thanks for your responses!
I think there might have been a mismatch between the compiler used, and the Phobos library used. This might happen if you used multiple sources for installation, e.g. brew / macports / dmg (install script is self contained and never affected).
Oct 04 2020
prev sibling parent Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Sunday, 4 October 2020 at 16:48:24 UTC, Michael wrote:
 Dear all,

 Sorry for the potentially stupid question, but I'm a complete 
 newbie to D. Why does compiling the following trivial code fail?

 [...]
I have tried my best to make it fail, but can't. Maybe it's something with the combination of dmd64 and MACOS?
Oct 04 2020