Introduction to programming with compile time sequences in D

Petar Petar
Tue Sep 1 16:24:29 UTC 2020


On Tuesday, 1 September 2020 at 16:00:14 UTC, data pulverizer 
wrote:
> On Saturday, 29 August 2020 at 04:41:36 UTC, Petar Kirov 
> [ZombineDev] wrote:
>> On Friday, 28 August 2020 at 11:05:09 UTC, data pulverizer 
>> wrote:
>>> On Tuesday, 25 August 2020 at 15:58:46 UTC, Petar Kirov 
>>> [ZombineDev] wrote:
>>>> [...]
>>>
>>> Just to keep you updated, I've begun to write a fresh section 
>>> on templates for dlang-tour quite separate from the blog 
>>> article - something more appropriate for the website, though 
>>> I'll take some elements of what I've already done. Once it's 
>>> finished I'll do a pull request.
>>>
>>> Thanks
>>
>> Sounds great, thank you!
>
> I've finished writing the fresh section and checked it through 
> a few times. It is pretty detailed and long and before 
> releasing it and doing a pull request I'll check it through 
> once or twice more over the next day or two. The document 
> content structure is:
>
> ```
> # Templates and Compile Time Programming in D
>
> ## Contents
>
> * Introduction
> * Templates in D
>   * Function templates
>     * Longhand and shorthand declarations
>     * Inference of parameters
>     * Access patterns for template internals
>     * Alias template parameter
>     * Variadic template functions
>     * The is() directive
>     * More on template constraints and partial specialization
>   * Struct, class, and interface templates
>     * Struct template longhand and shorthand declarations
>       * Variadic template objects
>       * Template constraints and specialization
>   * Enumeration templates
>   * Alias templates
>     * static if
>     * Traits
> * Metaprogramming in D
>   * Introduction
>   * AliasSeq!(T) compile time sequences
>     * Append, prepend and concatenating compile time lists
>     * Replacing items in compile time sequences
>     * Replacing multiple items with an individual type
>       * String mixins
>       * static foreach
>     * Replacing multiple items by a tuple of items
>       * Contained type sequences
>     * Template mixins, CTFE, and import
>       * Template mixins
>       * CTFE
>       * import("file.d")
> ```

Looking great so far!

> I have written lots of code examples in the text but there are 
> also lots of runnable files that can be in code demo "play" 
> sections. The only thing is when I look at the current coding 
> area it is quite large and separate from the text. Sometime in 
> the future, I guess it would be great to have it inline with 
> the text and smaller like the regular fenced code so that 
> multiple files can be included in separate scrollable "play" 
> areas.
>
> Thanks

Yeah, I think we should add the following feature:
Whenever there's a snippet of code (fenced code block in 
markdown), a button should appear under, which when clicked would 
replace the content of the text editor with the code snippet.

There two challenges with this:
1. Many of the code snippets that appear throughout the articles 
are not meant to be runnable, so we would need a way to provide 
the necessary scaffolding (e.g. wrap them in `void main() { /+ 
... +/ }`)
2. It may surprising and inconvenient for users to have the code 
they have potentially modified disappear. This could be solved by 
adding proper support for multiple open files to the editor 
(along the lines of commercial solutions like codesandbox, github 
workspaces, etc.). What would happen is that click [Edit] on a 
code-block would simply open another file.




More information about the Digitalmars-d-announce mailing list