D vs nim

Timothee Cour thelastmammoth at gmail.com
Fri May 4 17:53:04 UTC 2018


i think the explanation in
https://nim-lang.org/docs/manual.html#statements-and-expressions-when-statement
is pretty clear. In any case you can see for yourself:
nim c -r main.nim
```nim
proc fun(a:int):auto=a*a
static: # makes sure block evaluated at CT
   when fun(1)==1: echo "ok1"
   when fun(2)==2: echo "ok2"
```
prints ok1


On Fri, May 4, 2018 at 9:40 AM Mark via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> On Thursday, 3 May 2018 at 23:09:34 UTC, Timothee Cour wrote:
> > nim supports static if (`when`) + CTFE. A simple google search
> > or searching
> > would've revealed that.
> >
> > On Thu, May 3, 2018 at 3:20 PM Mark via Digitalmars-d <
> > digitalmars-d at puremagic.com> wrote:
> >
> >> On Thursday, 3 May 2018 at 20:57:16 UTC, Dennis wrote:
> >> > On Thursday, 3 May 2018 at 19:11:05 UTC, Mark wrote:
> >> >> Funnily, none of these languages have a "static if"
> >> >> construct, nor do Rust, Swift and Nim. Not one that I could
> >> >> find, anyway.
> >> >
> >> > What qualifies under "static if"? Because Rust, Swift and
> >> > Nim do have conditional compilation.
> >> >
> >
https://doc.rust-lang.org/book/first-edition/conditional-compilation.html
> >> >
> >
https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html
(conditional compilation blocks)
> >> >
> >
https://nim-lang.org/docs/manual.html#statements-and-expressions-when-statement
> >
> >> Fair enough. I should have written "static if + CTFE".

> The little information on the official site describes `when` more
> like #ifdef in C than an actual static if. I also went over a few
> dozens of modules in the standard library and the statement seems
> to be rarely used, and when it does it's usually in an #ifdef-ish
> context (like platform specific code).

> Perhaps Nim's support for conditional compilation is as powerful
> as D's is, but you can see why my impression is currently to the
> contrary.


More information about the Digitalmars-d mailing list