Thread overview
cannot call impure function
Oct 04, 2020
Michael
Oct 04, 2020
Paul Backus
Oct 04, 2020
Michael
Oct 04, 2020
Michael
Oct 04, 2020
Mathias LANG
Oct 04, 2020
Michael
Oct 04, 2020
Michael
Oct 04, 2020
Mathias LANG
Oct 04, 2020
Imperatorn
October 04, 2020
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
October 04, 2020
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?
October 04, 2020
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

October 04, 2020
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

October 04, 2020
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?
October 04, 2020
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 ?
October 04, 2020
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
October 04, 2020
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!
October 04, 2020
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).