December 21, 2021

On Tuesday, 21 December 2021 at 15:42:59 UTC, russhy wrote:

>

Please keep us updated, that'll be interesting to see how a pure D printf would look like!

Glad someone is interested! I'm actually planning to make a whole library ;)

Check my thread were I'm asking about your opinion on formatting and what is my current approach.

December 21, 2021

On 12/21/21 4:28 AM, rempas wrote:

>

On Tuesday, 21 December 2021 at 08:42:35 UTC, vit wrote:

>

You can use switch + static foreach:

import std.stdio;

    //this print args in reverse order:
    void print(T...)(string prompt, T args)
    {
        void print_arg(size_t index){
            switch(index){
                static foreach(i, a; args){
                    case i:
                        // handle your other types
                        write(a);
                        return;
                }
                default:
                    assert(0, "no impl");
            }
        }

        write(prompt);
        size_t len = args.length;
        while(len --> 0)
            print_arg(len);
    }

    void main(){
        print("Prompt (ignored): ", "Hello", " world!\n", 123);
    }

Cool! That's probably what I wanted to do! It seems that when looping inside a "static foreach" and taking the index, then I can compare it with a value that is not calculated at compile time. This way I can also check for the type of the variables and do my original plan which will make the function even better! Thanks a lot for the help dude!!!

The reason your original isn't working is that indexing a list of differently-typed things cannot be done using a runtime index.

I'd say that an inner function + static foreach + switch is the best way to convert from runtime to compile-time values. And in general, I would say having function templates that handle each arg type are usually conducive to clean and easy code.

But in the case you are suggesting, as long as you don't need to iterate them out of order, what you can do is foreach the args tuple, and do something like:

foreach(arg; args)
{
   writeUpToNextDelimeter(prompt); // updates prompt to point at next delimiter
   processArg(arg, prompt);
}

-Steve

December 21, 2021

On Tuesday, 21 December 2021 at 17:33:09 UTC, Steven Schveighoffer wrote:

>

The reason your original isn't working is that indexing a list of differently-typed things cannot be done using a runtime index.

I'd say that an inner function + static foreach + switch is the best way to convert from runtime to compile-time values. And in general, I would say having function templates that handle each arg type are usually conducive to clean and easy code.

But in the case you are suggesting, as long as you don't need to iterate them out of order, what you can do is foreach the args tuple, and do something like:

foreach(arg; args)
{
   writeUpToNextDelimeter(prompt); // updates prompt to point at next delimiter
   processArg(arg, prompt);
}

-Steve

Got that! Thanks a lot Steve!

December 21, 2021

On Tuesday, 21 December 2021 at 15:42:59 UTC, russhy wrote:

>

Please keep us updated, that'll be interesting to see how a pure D printf would look like!

It already exists, it's called std.format.write.formattedWrite, in terms of which things like std.stdio.writef are implemented.

December 21, 2021

On Tuesday, 21 December 2021 at 18:51:38 UTC, Stanislav Blinov wrote:

>

On Tuesday, 21 December 2021 at 15:42:59 UTC, russhy wrote:

>

Please keep us updated, that'll be interesting to see how a pure D printf would look like!

It already exists, it's called std.format.write.formattedWrite, in terms of which things like std.stdio.writef are implemented.

I took a look and to be honest, it's the same story as everything in the STD, they try to do everything at the same time, so they up end calling each other, you end up lost in multiple 8k LOC modules, not understanding what the function is doing anymore, it's a rotten place

Plus they are not nogc

OP's attempt is clean, you know what's up, you can read the code, free of dependencies (for now), and hopefully nogc

i want to encourage more code like that

December 22, 2021

On Tuesday, 21 December 2021 at 22:50:57 UTC, russhy wrote:

>

I took a look and to be honest, it's the same story as everything in the STD, they try to do everything at the same time, so they up end calling each other, you end up lost in multiple 8k LOC modules, not understanding what the function is doing anymore, it's a rotten place

Finally someone said it!!! No offense to the Phobos developers but the library is a huge mess in runtime/compile performance and its API is not always clean and consistent making the library annoying to use some times. Hell, even libc is not very good as it is very bare bones and believe it or not, we could achieve better performance for most staff from libc. We need a new system library that won't depend on anything ASAP! No garbage collector, no exceptions, no complicated struct types etc. Just a simple, clean, consistent, really fast and easy to use library!

>

Plus they are not nogc

Yeah, Seriously D's developers and user really underestimate the fact that the biggest percent of people not using D are doing so because of the Garbage Collector. D's community makes it like it's not much of a big deal but it actually is.

>

OP's attempt is clean, you know what's up, you can read the code, free of dependencies (for now), and hopefully nogc

i want to encourage more code like that

Thanks! Code readability and a clean and easy to use API is the plan for the library. I want people to enjoy using the library while they will have the best possible runtime and compile performance at the same time. I am a novice even to the easier high level programming and so I will not a lot of help. But this will not stop me and hopefully we can make something great together!

December 22, 2021

sorry for intervening... :)

On Wednesday, 22 December 2021 at 08:17:03 UTC, rempas wrote:

>

No garbage collector, no exceptions

GOLDEN WORDS!!!

>

Yeah, Seriously D's developers and user really underestimate the fact that the biggest percent of people not using D are doing so because of the Garbage Collector. D's community makes it like it's not much of a big deal but it actually is.

Exactly!

1 2
Next ›   Last »