Jump to page: 1 2 3
Thread overview
Introduction to programming with compile time sequences in D
Aug 25, 2020
data pulverizer
Aug 25, 2020
data pulverizer
Aug 25, 2020
data pulverizer
Aug 25, 2020
data pulverizer
Aug 28, 2020
data pulverizer
Sep 01, 2020
data pulverizer
Sep 01, 2020
data pulverizer
Sep 01, 2020
data pulverizer
Sep 03, 2020
data pulverizer
Aug 25, 2020
data pulverizer
Aug 25, 2020
data pulverizer
Aug 25, 2020
data pulverizer
Aug 27, 2020
Twilight
Aug 28, 2020
data pulverizer
August 25, 2020
I have a draft new blog article "Introduction to programming with compile time sequences in D", it's on Github and I would appreciate feedback before it goes live https://gist.github.com/dataPulverizer/67193772c52e7bd0a16414cb01ae4250

Comment welcome.

Many thanks
August 25, 2020
On Tuesday, 25 August 2020 at 02:11:42 UTC, data pulverizer wrote:
> I have a draft new blog article "Introduction to programming with compile time sequences in D", it's on Github and I would appreciate feedback before it goes live https://gist.github.com/dataPulverizer/67193772c52e7bd0a16414cb01ae4250
>
> Comment welcome.
>
> Many thanks

Nice article! I haven't had the chance to read it fully, so far now I have just one quick suggestion regarding removing items from sequences [0]. I think it would be much simpler (and likely more efficient) to avoid both recursion and static foreach and simply use slicing + concatenation. Here's an example:

template removeFromSeqAt(size_t idx, seq...)
{
    static if (seq.length > 0 && idx < seq.length)
    	alias removeFromSeqAt = AliasSeq!(seq[0 .. idx], seq[idx + 1 .. $]);
    else
        static assert (0);
}

You can find a full example of this here:
https://run.dlang.io/gist/run-dlang/80e120e989a6b0f72fd7244b17021e2f


[0]: https://gist.github.com/dataPulverizer/67193772c52e7bd0a16414cb01ae4250#removing-items-from-a-compile-time-sequence
August 25, 2020
On Tuesday, 25 August 2020 at 14:02:33 UTC, Petar Kirov [ZombineDev] wrote:
> Nice article! I haven't had the chance to read it fully, so far now I have just one quick suggestion regarding removing items from sequences [0]. I think it would be much simpler (and likely more efficient) to avoid both recursion and static foreach and simply use slicing + concatenation. Here's an example:
>
> template removeFromSeqAt(size_t idx, seq...)
> {
>     static if (seq.length > 0 && idx < seq.length)
>     	alias removeFromSeqAt = AliasSeq!(seq[0 .. idx], seq[idx + 1 .. $]);
>     else
>         static assert (0);
> }
>
> You can find a full example of this here:
> https://run.dlang.io/gist/run-dlang/80e120e989a6b0f72fd7244b17021e2f
>
>
> [0]: https://gist.github.com/dataPulverizer/67193772c52e7bd0a16414cb01ae4250#removing-items-from-a-compile-time-sequence

I could probably apply the same thing to some if not all the other template operations. Many Thanks!
August 25, 2020
On Tuesday, 25 August 2020 at 14:02:33 UTC, Petar Kirov [ZombineDev] wrote:
> Nice article! I haven't had the chance to read it fully, so far [snip]

I though of writing at the beginning that it was long and that readers could dip in and out of the article as they wished but decided that people could decide that for themselves and that placing a length warning might be counter-productive.

Thanks

August 25, 2020
On Tuesday, 25 August 2020 at 15:30:17 UTC, data pulverizer wrote:
> On Tuesday, 25 August 2020 at 14:02:33 UTC, Petar Kirov [ZombineDev] wrote:
>> Nice article! I haven't had the chance to read it fully, so far [snip]
>
> I though of writing at the beginning that it was long and that readers could dip in and out of the article as they wished but decided that people could decide that for themselves and that placing a length warning might be counter-productive.
>
> Thanks

I think your article is quite valuable is it covers many aspects of template programming in D, while being quite approachable as well. May I suggest contributing it in some form to https://tour.dlang.org? Contributing is as easy as opening a pull request to this repo: https://github.com/dlang-tour/english. Just check the format of some of the other *.md and *.yml files there and you'll figure it out.
We already have a section on templates there, but I think it's way too brief and doesn't do justice to the D's extensive template features. Perhaps it could be organized as a fully separate section with different articles, corresponding to each paragraph in your article.
August 25, 2020
On Tuesday, 25 August 2020 at 14:02:33 UTC, Petar Kirov [ZombineDev] wrote:
> ...
> You can find a full example of this here:
> https://run.dlang.io/gist/run-dlang/80e120e989a6b0f72fd7244b17021e2f
>
There is an issue with `AliasTuple` though, you can't directly print its collections with pragma:

```d
alias coll = AliasSeq!(s1, s2, s3, s7);
pragma(msg, coll);
```

I get the following error:

```d
onlineapp.d(29): Error: cannot interpret AliasTuple!1 at compile time
onlineapp.d(29): Error: cannot interpret AliasTuple!(1, 2) at compile time
...
tuple((__error), (__error), (__error), (__error))
```


August 25, 2020
On Tuesday, 25 August 2020 at 15:58:46 UTC, Petar Kirov [ZombineDev] wrote:
> On Tuesday, 25 August 2020 at 15:30:17 UTC, data pulverizer wrote:
> I think your article is quite valuable is it covers many aspects of template programming in D, while being quite approachable as well. May I suggest contributing it in some form to https://tour.dlang.org? Contributing is as easy as opening a pull request to this repo: https://github.com/dlang-tour/english. Just check the format of some of the other *.md and *.yml files there and you'll figure it out.
> We already have a section on templates there, but I think it's way too brief and doesn't do justice to the D's extensive template features. Perhaps it could be organized as a fully separate section with different articles, corresponding to each paragraph in your article.

I'd be happy to work on that!
August 25, 2020
On Tuesday, 25 August 2020 at 16:01:25 UTC, data pulverizer wrote:
> On Tuesday, 25 August 2020 at 14:02:33 UTC, Petar Kirov [ZombineDev] wrote:
>> ...
>> You can find a full example of this here:
>> https://run.dlang.io/gist/run-dlang/80e120e989a6b0f72fd7244b17021e2f
>>
> There is an issue with `AliasTuple` though, you can't directly print its collections with pragma:
>
> ```d
> alias coll = AliasSeq!(s1, s2, s3, s7);
> pragma(msg, coll);
> ```
>
> I get the following error:
>
> ```d
> onlineapp.d(29): Error: cannot interpret AliasTuple!1 at compile time
> onlineapp.d(29): Error: cannot interpret AliasTuple!(1, 2) at compile time
> ...
> tuple((__error), (__error), (__error), (__error))
> ```

p.s. I did include a `Tuple` - like implementation in my article at the later sections, but it was based on a template struct.
August 25, 2020
On Tuesday, 25 August 2020 at 16:10:21 UTC, data pulverizer wrote:
> On Tuesday, 25 August 2020 at 16:01:25 UTC, data pulverizer wrote:
>> On Tuesday, 25 August 2020 at 14:02:33 UTC, Petar Kirov [ZombineDev] wrote:
>>> ...
>>> You can find a full example of this here:
>>> https://run.dlang.io/gist/run-dlang/80e120e989a6b0f72fd7244b17021e2f
>>>
>> There is an issue with `AliasTuple` though, you can't directly print its collections with pragma:
>>
>> ```d
>> alias coll = AliasSeq!(s1, s2, s3, s7);
>> pragma(msg, coll);
>> ```
>>
>> I get the following error:
>>
>> ```d
>> onlineapp.d(29): Error: cannot interpret AliasTuple!1 at compile time
>> onlineapp.d(29): Error: cannot interpret AliasTuple!(1, 2) at compile time
>> ...
>> tuple((__error), (__error), (__error), (__error))
>> ```
>
> p.s. I did include a `Tuple` - like implementation in my article at the later sections, but it was based on a template struct.

Fixed it, using this now works:

```d
template AliasTuple(seq...)
{
  struct AliasTuple
  {
    alias expand = seq;
    enum length = seq.length;
  }
}
```
August 25, 2020
On Tuesday, 25 August 2020 at 16:01:25 UTC, data pulverizer wrote:
> On Tuesday, 25 August 2020 at 14:02:33 UTC, Petar Kirov [ZombineDev] wrote:
>> ...
>> You can find a full example of this here:
>> https://run.dlang.io/gist/run-dlang/80e120e989a6b0f72fd7244b17021e2f
>>
> There is an issue with `AliasTuple` though, you can't directly print its collections with pragma:
>
> ```d
> alias coll = AliasSeq!(s1, s2, s3, s7);
> pragma(msg, coll);
> ```
>
> I get the following error:
>
> ```d
> onlineapp.d(29): Error: cannot interpret AliasTuple!1 at compile time
> onlineapp.d(29): Error: cannot interpret AliasTuple!(1, 2) at compile time
> ...
> tuple((__error), (__error), (__error), (__error))
> ```

Yeah, I wrote a quick implementation, just for this example. For sure there are better ways to implement it.
« First   ‹ Prev
1 2 3