May 02, 2022
On 5/2/2022 2:10 AM, Max Samukha wrote:
> On Monday, 2 May 2022 at 01:42:19 UTC, Walter Bright wrote:
> 
>>
>> A language designed for native compilation draws a hard distinction between compile time and run time. You'll see this in the grammar for the language, in the form of a constant-expression for compile time, and just expression for run time. The constant-expression does constant folding at compile time. The runtime does not include a compiler.
> 
> Nope, Nemerle doesn't require a compiler runtime at runtime (however, you can include it if you need to). The Nemerle compiler compiles the const-expressions into a dll (yes, the target is bytecode, but it could be native code - it doesn't matter) and then loads the compiled code back and executes it *at compile time*. It could as well do interpretation the way D does. Both approaches have their pros and cons, but they do fundamentally the same thing.

It sounds just like how Lisp, Java, and C# work. Nemerle even uses the same interpreter/code generator as C#.
May 02, 2022
On 5/2/2022 2:57 AM, Max Samukha wrote:
> There is nothing big about CTFE. )

It completely transformed how D code is written.

Check out this, for example:

https://github.com/dlang/dmd/blob/master/src/dmd/backend/oper.d#L388

DMD used to do this initialization as a separate program, which did what the lambda did here, and wrote out a file which was then compiled in as part of DMD. The Digital Mars C++ did the same thing for its tables.
May 02, 2022
On 5/2/2022 12:04 AM, Patrick Schluter wrote:
>  From wikipedia
> ````
> Unlike the LEFT$(), MID$() and RIGHT$() functions used in the ubiquitous Microsoft BASIC dialects for home computers, parts of strings in Sinclair BASIC are accessed by numeric range. For example, a$(5 TO 10) gives a substring starting with the 5th and ending with the 10th character of the variable a$. Thus, it is possible to replace the LEFT$() and RIGHT$() commands by simply omitting the left or right array position respectively; for example a$( TO 5) is equivalent to LEFT$(a$,5). Further, a$(5) alone is enough to replace MID$(a$,5,1).
> ````
> and what's not mentioned in the wikipedia is that the slicing also worked as lvalue. ´a$(5 TO 7)="12"´ was possible.
> 

Nice. Slices are a huge deal.
May 02, 2022

On Monday, 2 May 2022 at 21:31:28 UTC, Walter Bright wrote:

>

Nice. Slices are a huge deal.

Why? Old languages like Simula have it for strings (aka substrings), to save space or maybe reduce the need for GC by having strings ref counted. For other containers you might as well use a library type. Never thought of it as something special, and I have written a lot of Python code. What would be more impactful is to have one line generators like Python, give D ranges som dedicated syntax.

In general: improve on those features existing users think are language defining.

May 02, 2022
On 5/2/2022 7:34 AM, claptrap wrote:
> Genius isn't having the idea, it's more often than not making the idea work.

Yup. I've heard endless arguments that Edison didn't really invent the light bulb, the Wrights did not invent the airplane, Musk did not invent reusable rockets, etc.

An idea ain't worth spit if it is not implemented.

The value in D's CTFE is after we demonstrated it, it suddenly became a "must have" feature in the other mainstream native languages.
May 03, 2022
On Tuesday, 3 May 2022 at 03:55:34 UTC, Walter Bright wrote:
> Yup. I've heard endless arguments that Edison didn't really invent the light bulb, the Wrights did not invent the airplane, Musk did not invent reusable rockets, etc.
>
> An idea ain't worth spit if it is not implemented.
>
> The value in D's CTFE is after we demonstrated it, it suddenly became a "must have" feature in the other mainstream native languages.


Wilzbach ask Andrei Alexandrescu to comment at this link 4 year ago without answer: https://github.com/dlang/dmd/pull/8460#issuecomment-438920811


Don't ask for it but earn it.

Don't ask people to respect without respect the others first.
May 03, 2022
On Monday, 2 May 2022 at 20:30:36 UTC, Walter Bright wrote:
> On 5/2/2022 2:57 AM, Max Samukha wrote:
>> There is nothing big about CTFE. )
>
> It completely transformed how D code is written.
>
> Check out this, for example:
>
> https://github.com/dlang/dmd/blob/master/src/dmd/backend/oper.d#L388
>
> DMD used to do this initialization as a separate program, which did what the lambda did here, and wrote out a file which was then compiled in as part of DMD. The Digital Mars C++ did the same thing for its tables.

I've been using D in-and-out since around 2006 and might be aware of every existing use case of CTFE. Lambdas work well for simple cases like the one you mentioned, but not so well for more involved ones:

alias format(A...) = (string format, A args...)
{
    string[] r;
    r ~= "bar";
    return r;
};

enum s = format("...", 1, 2);

1. Can't make it a normal function, because it needs to be usable with -betterC, and ~= prevents that.
3. Can't make it a lambda, because there's no way to express variadics for lambdas without loosing IFTI.



May 03, 2022
On Tuesday, 3 May 2022 at 07:29:24 UTC, Max Samukha wrote:

> alias format(A...) = (string format, A args...)

alias format(A...) = (string format, A args)
May 03, 2022
On Monday, 2 May 2022 at 20:24:29 UTC, Walter Bright wrote:

>
> It sounds just like how Lisp, Java, and C# work. Nemerle even uses the same interpreter/code generator as C#.

C# can't do CTFE. For example, in C#, you can't generate code (without resorting to hacks) at compile time based on UDAs the way you can in Nemerle or D. In C#, you usually process UDAs at runtime. I guess that is what you mean when you say "it needs compiler runtime at runtime". Yes, C# needs one because it must defer code generation to runtime.
May 03, 2022
On Tuesday, 3 May 2022 at 07:29:24 UTC, Max Samukha wrote:
> On Monday, 2 May 2022 at 20:30:36 UTC, Walter Bright wrote:
>> [...]
>
> I've been using D in-and-out since around 2006 and might be aware of every existing use case of CTFE. Lambdas work well for simple cases like the one you mentioned, but not so well for more involved ones:
>
> alias format(A...) = (string format, A args...)
> {
>     string[] r;
>     r ~= "bar";
>     return r;
> };
>
> enum s = format("...", 1, 2);
>
> 1. Can't make it a normal function, because it needs to be usable with -betterC, and ~= prevents that.
> 3. Can't make it a lambda, because there's no way to express variadics for lambdas without loosing IFTI.


You can use it with betterC if you put the format into a separate di file.