www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - writeln and write at CTFE

reply Andrey <saasecondbox yandex.ru> writes:
Hello all,
Tell me please how can I "writeln" and "write" in function that 
is used in CTFE?
At the moment I get this:
 import\std\stdio.d(4952,5): Error: variable impl cannot be 
 modified at compile time
Or may be exist some other ways to do it?
Jan 13 2021
parent reply Guillaume Piolat <first.last gmail.com> writes:
On Wednesday, 13 January 2021 at 08:35:09 UTC, Andrey wrote:
 Hello all,
 Tell me please how can I "writeln" and "write" in function that 
 is used in CTFE?
 At the moment I get this:
 import\std\stdio.d(4952,5): Error: variable impl cannot be 
 modified at compile time
Or may be exist some other ways to do it?
pragma(msg, <compile-time-expr>);
Jan 13 2021
parent reply Bastiaan Veelo <Bastiaan Veelo.net> writes:
On Wednesday, 13 January 2021 at 09:11:53 UTC, Guillaume Piolat 
wrote:
 On Wednesday, 13 January 2021 at 08:35:09 UTC, Andrey wrote:
 Hello all,
 Tell me please how can I "writeln" and "write" in function 
 that is used in CTFE?
 At the moment I get this:
 import\std\stdio.d(4952,5): Error: variable impl cannot be 
 modified at compile time
Or may be exist some other ways to do it?
pragma(msg, <compile-time-expr>);
This may however not do what you wish it to do: https://forum.dlang.org/post/mailman.4526.1499573493.31550.digitalmars-d-learn puremagic.com — Bastiaan.
Jan 13 2021
parent reply Andrey <saasecondbox yandex.ru> writes:
On Wednesday, 13 January 2021 at 11:31:16 UTC, Bastiaan Veelo 
wrote:
 On Wednesday, 13 January 2021 at 09:11:53 UTC, Guillaume Piolat 
 wrote:
 On Wednesday, 13 January 2021 at 08:35:09 UTC, Andrey wrote:
 Hello all,
 Tell me please how can I "writeln" and "write" in function 
 that is used in CTFE?
 At the moment I get this:
 import\std\stdio.d(4952,5): Error: variable impl cannot be 
 modified at compile time
Or may be exist some other ways to do it?
pragma(msg, <compile-time-expr>);
This may however not do what you wish it to do: https://forum.dlang.org/post/mailman.4526.1499573493.31550.digitalmars-d-learn puremagic.com — Bastiaan.
Function "ctfeWriteln" doens't exist. pragma(msg, ...) is used only for CT values. Today is 2021. Dlang still doesn't have ctfe write functions?
Jan 13 2021
next sibling parent z <z z.com> writes:
On Wednesday, 13 January 2021 at 11:50:26 UTC, Andrey wrote:
 Function "ctfeWriteln" doens't exist.

 pragma(msg, ...) is used only for CT values.

 Today is 2021. Dlang still doesn't have ctfe write functions?
Yes.(afaik) It has shot me on the foot once, to the point i abandoned the idea of ever accomplishing what i wanted to do at compile-time and instead just did it at module construction-time, and i must admit that it was immediately easier to debug.
Jan 13 2021
prev sibling parent reply tsbockman <thomas.bockman gmail.com> writes:
On Wednesday, 13 January 2021 at 11:50:26 UTC, Andrey wrote:
 Today is 2021. Dlang still doesn't have ctfe write functions?
You make it sound like D is behind the times. Is CTFE I/O a standard feature in other languages? How many other languages even have a CTFE feature comparable to D's?
Jan 13 2021
parent reply oddp <oddp posteo.de> writes:
On 13.01.21 21:47, tsbockman via Digitalmars-d-learn wrote:
 Is CTFE I/O a standard feature in other languages? How many other languages
even have a CTFE 
 feature comparable to D's?
Just two langs I use from time to time: 1) nim via forced ctfe; way faster than d by running through a vm: const foo = fib(42) static: echo "foobar" 2) crystal via macros: {{ puts "foobar" }} Another one would be zig via comptime, but never tried that.
Jan 13 2021
parent tsbockman <thomas.bockman gmail.com> writes:
On Wednesday, 13 January 2021 at 23:38:54 UTC, oddp wrote:
 Just two langs I use from time to time:

 1) nim via forced ctfe; way faster than d by running through a 
 vm:

 const foo = fib(42)
 static:
   echo "foobar"

 2) crystal via macros:

 {{ puts "foobar" }}

 Another one would be zig via comptime, but never tried that.
Good to know... doesn't sound like it's some kind of standard "2021" feature, though. Those are all lesser-known languages (like D), not industry standard stuff like C++, Java, etc.
Jan 13 2021