March 12, 2022

On Saturday, 12 March 2022 at 19:13:33 UTC, Zach Tollen wrote:

>

On Friday, 11 March 2022 at 13:01:43 UTC, Ali Çehreli wrote:

>

Perhaps a second meaning for ..? And is : really necessary?

The character | might work too. It looks better if we close it with the same character.

   x = |std.datetime|SysTime;

I actually like this one a lot. There is some potential lexical ambiguity with | and || as binary operators. However, those operators are typically separated with whitespace in ordinary code, so I don't think it will ever be a problem. (The second | in |std.datetime|SysTime can be parsed as a part of |modname|symbol, so apart from typos, there's no syntactical problem.)

The worst you would suffer would be the visual confusion of something like this:

if (|std.something|condition(sdfd) || |some.other.inlinemodule|Test
      || |othermod.imp|mycondition) {
   myFlags = |std.something|Flagset | |std.otherthing|Flags;
}

This would be the extreme case I think. Syntax highlighting could help.

I think this is better than $std.datetime:SysTime.

Out of your new alternatives, I like this one the best.

x = :std.datetime:SysTime;
  1. It is symmetric same as ||
  2. : is already used in import x:y
  3. : is not used in expressions unlike | which is quite common.
  4. We can keep $ for some future codegen features.
March 12, 2022

On Saturday, 12 March 2022 at 19:33:16 UTC, Daniel N wrote:

>

Out of your new alternatives, I like this one the best.

x = :std.datetime:SysTime;
  1. It is symmetric same as ||
  2. : is already used in import x:y
  3. : is not used in expressions unlike | which is quite common.
  4. We can keep $ for some future codegen features.

Thanks. Those are good points. I think I even agree with you.

Regarding (3), there is an exception in the case of the conditional operator (? :), but I don't think it's a huge problem. The worst visual confusion here might be something like:

{
   auto x = :mymod.question:ask ? :another.modname:asdf
         ? :moremods:answer1 : :finalmod.three:okay
         : :mymod.answer:two
}

To do a general comparison of the versions, let's take this code snippet from phobos:

The way it is now:

if (Values.length != 0)
{
    foreach (uint i, ref v; values)
    {
        import std.functional : binaryFun;
        if (binaryFun!pred(value, v)) return i + 1;
    }
    return 0;
}

Ugh. Not my favorite.

Now let's look at the pull request which was already merged, which allows you to write the following:

if (Values.length != 0)
{
    foreach (uint i, ref v; values)
    {
        if (imported!"std.functional".binaryFun!pred(value, v)) return i + 1;
    }
    return 0;
}

I'd say this represents 70% of the total aesthetic improvement between the versions. Just being able to inline imports makes most of the difference here — not bad for a technique with no language support! (We're not talking about compilation speed, although direct language support would allow the compiler to bypass the normal lookup process and go straight to module where the import is located, so it would speed up.)

Using my language-supported long form import syntax, the result is:

if (Values.length != 0)
{
    foreach (uint i, ref v; values)
    {
        if (import.std.functional:binaryFun!pred(value, v)) return i + 1;
    }
    return 0;
}

I'll give this 5% of the total aesthetic improvement, from the previous version to this.

Finally, with :modname:symbol:

if (Values.length != 0)
{
    foreach (uint i, ref v; values)
    {
        if (:std.functional:binaryFun!pred(value, v)) return i + 1;
    }
    return 0;
}

I give this the remaining 25% of the total improvement.

I'm curious what other people think.

March 13, 2022

On Saturday, 12 March 2022 at 23:57:09 UTC, Zach Tollen wrote:

>

I'm curious what other people think.

Locality can be overdone. I think this would suffice:

if (Values.length != 0)
{
    import std.functional : binaryFun;
    foreach (uint i, ref v; values)
        if (binaryFun!pred(value, v)) return i + 1;
    return 0;
}

So any new feature is here totally superfluous IMHO.

March 13, 2022

On Sunday, 13 March 2022 at 08:23:52 UTC, Dom DiSc wrote:

>

So any new feature is here totally superfluous IMHO.

And btw. foreach doesn't even introduce a new scope, so you can't get your import more local than in my version, no matter what new syntax you invent.

March 13, 2022

On Sunday, 13 March 2022 at 08:37:15 UTC, Dom DiSc wrote:

> >

So any new feature is here totally superfluous IMHO.

Agree,
There is no need to be too local at all.
You only need to put the same imported file function into one file.

March 13, 2022
On Sunday, 13 March 2022 at 08:37:15 UTC, Dom DiSc wrote:
> And btw. foreach doesn't even introduce a new scope

Yes it does.
March 13, 2022

On Sunday, 13 March 2022 at 08:37:15 UTC, Dom DiSc wrote:

>

On Sunday, 13 March 2022 at 08:23:52 UTC, Dom DiSc wrote:

>

So any new feature is here totally superfluous IMHO.

And btw. foreach doesn't even introduce a new scope, so you can't get your import more local than in my version, no matter what new syntax you invent.

foreach does introduce a new scope

I believe it is static foreach that doesn't introduce a new scope(hence why you see static foreach(){{ /*code/* }} style code sometimes

March 15, 2022

On Sunday, 13 March 2022 at 12:47:05 UTC, Tejas wrote:

>

On Sunday, 13 March 2022 at 08:37:15 UTC, Dom DiSc wrote:

>

On Sunday, 13 March 2022 at 08:23:52 UTC, Dom DiSc wrote:

>

So any new feature is here totally superfluous IMHO.

And btw. foreach doesn't even introduce a new scope, so you can't get your import more local than in my version, no matter what new syntax you invent.

foreach does introduce a new scope

I believe it is static foreach that doesn't introduce a new scope(hence why you see static foreach(){{ /*code/* }} style code sometimes

Would be nice if we could attribute static foreach like this instead:

scope static foreach (...) { ... }

or

static foreach (...) scope { ... }

Would've been much cleaner.

March 15, 2022

On Tuesday, 15 March 2022 at 10:25:54 UTC, bauss wrote:

>
scope static foreach (...) { ... }

or

static foreach (...) scope { ... }

Would've been much cleaner.

{
   static foreach(...)
   {

   }
}
March 15, 2022

On Tuesday, 15 March 2022 at 13:53:51 UTC, Andrea Fontana wrote:

>

On Tuesday, 15 March 2022 at 10:25:54 UTC, bauss wrote:

>
scope static foreach (...) { ... }

or

static foreach (...) scope { ... }

Would've been much cleaner.

{
   static foreach(...)
   {

   }
}

The whole point is to avoid the extra brackets and/or the extra unnecessary indentation.