June 03, 2020
On Wednesday, 3 June 2020 at 14:10:21 UTC, Stefan Koch wrote:
> Try to print an enum please.

That's a separate case. There's branches of writeln that could definitely be improved.

But the simple string one isn't too bad, and the 0.04s you pay for the check means things like printing enums actually work, even if that branch isn't as well done.

puts has no hope of handling these cases.
June 03, 2020
On Wednesday, 3 June 2020 at 14:13:47 UTC, Paul Backus wrote:
> On Wednesday, 3 June 2020 at 11:22:23 UTC, Stefan Koch wrote:
>>
>> Oh yes.
>> sumType does not need to introduce new symbols.
>> Therefore it should be handled in a way which does not introduce new symbols.
>
> In other words, we want a way to give our templates AST-macro-like evaluation semantics. It's the same thing with Manu's `...` and staticMap. :)
>
> I wonder if a DIP to add something like "Macros: the Good Parts" to D would be accepted?

I doubt that it would have any more success than type functions.

June 03, 2020
On Wednesday, 3 June 2020 at 03:19:37 UTC, Walter Bright wrote:

> The thing is, `writeln("hello")` can be expanded to `core.stdc.stdio.puts("hello")`. Done.
>
> Phobos seems to do a lot of "going around the Horn" instead of taking the canal.

A good `writeln` would not call into C  at all. Nor would it copy its arguments like four times (therefore potentially not printing what it was given). But Phobos' `writeln` is actually a `encumber_you_with_dependencies_and_thread_safety_because_it_must_be_good_for_you_roundabout_writeln`. So it's OK, we're only missing a plain `writeln`.
June 03, 2020
On Wednesday, 3 June 2020 at 11:22:23 UTC, Stefan Koch wrote:
>[snip]
> Oh yes.
> sumType does not need to introduce new symbols.
> Therefore it should be handled in a way which does not introduce new symbols.
>
> type functions are one way to make this happen.
> However changes to the language are hard justify therefore I am currently revisiting,
> approaches to infer type-function-like behavior and transform them behind the scenes.
> (Which is a HUGE pain, because you have to transform recursion into loops, which is a hard problem in itself, AND the user probably would rather have written a loop, but was forced by the language to use recursion. )
>
> alas having my work being useful in the language is more important than to have a better language.
>
> I will continue on type functions; if the conservative approaches don't work out.

Thanks.

The problem almost sounds like you need an inliner for types in the compiler.
June 03, 2020
On Wednesday, 3 June 2020 at 14:58:59 UTC, Stanislav Blinov wrote:
> On Wednesday, 3 June 2020 at 03:19:37 UTC, Walter Bright wrote:
>
>> The thing is, `writeln("hello")` can be expanded to `core.stdc.stdio.puts("hello")`. Done.
>>
>> Phobos seems to do a lot of "going around the Horn" instead of taking the canal.
>
> A good `writeln` would not call into C  at all. Nor would it copy its arguments like four times (therefore potentially not printing what it was given). But Phobos' `writeln` is actually a `encumber_you_with_dependencies_and_thread_safety_because_it_must_be_good_for_you_roundabout_writeln`. So it's OK, we're only missing a plain `writeln`.

To be fair, C's `puts` also includes thread-safety. You need to use non-standard functions like `fputs_unlocked` if you want to avoid that overhead.
June 03, 2020
On 6/3/2020 1:06 AM, Nick Treleaven wrote:
> How does writeln tell that a zero terminated string has been passed?

D string literals always have a 0 terminator.
June 03, 2020
On 6/3/2020 7:04 AM, Adam D. Ruppe wrote:
> tbh I think this case looks worse than it is.

Not if you look at the code generated by:

  import std.stdio;

  void test()
  {
    writeln("hello");
  }

It's embarrassing.
June 03, 2020
On 6/3/2020 7:58 AM, Stanislav Blinov wrote:
> A good `writeln` would not call into C  at all.

C's puts() is thread safe. No reason to not use it.


> So it's OK, we're only missing a plain `writeln`.

Doing the basic, common cases by going around the horn is not good engineering.
June 03, 2020
On Wednesday, 3 June 2020 at 20:05:39 UTC, Walter Bright wrote:
> On 6/3/2020 7:58 AM, Stanislav Blinov wrote:
>> A good `writeln` would not call into C  at all.
>
> C's puts() is thread safe. No reason to not use it.

A thread-safe writeln would be threadsafe_writeln. Or, alternatively there would be a writeln and a not_threadsafe_writeln. No reason to pay for something you're not using. And still neither implementation would call into C, the OS is right there.
I guess this is where, in Phobos, one could use the output range format API with a custom sink. But that wouldn't help against all the unnecessary copying.

>> So it's OK, we're only missing a plain `writeln`.
>
> Doing the basic, common cases by going around the horn is not good engineering.

On that, we're in agreement.
June 03, 2020
On Wednesday, 3 June 2020 at 20:02:29 UTC, Walter Bright wrote:
> On 6/3/2020 7:04 AM, Adam D. Ruppe wrote:
>> tbh I think this case looks worse than it is.
>
> Not if you look at the code generated by:
>
>   import std.stdio;
>
>   void test()
>   {
>     writeln("hello");
>   }
>
> It's embarrassing.

Yes!

and now look at std.traits and std.meta :)