February 02, 2016
On Tuesday, 2 February 2016 at 08:31:07 UTC, Robert M. Münch wrote:
> No, my point is that CTFE and meta-programming seems to be much simpler and powerful if I can use a more functional programming approach for it. Working with powerful lists and data = code and code = data concept would simplify this.

Ultimately a restricted deductive programming language would be the better option. There is no need for compile time evaluation to be turing complete; after all, you want the compiler to finish within a fixed time limit.

February 02, 2016
On 02.02.2016 09:27, Robert M. Münch wrote:

> ==> BEGIN
[...]
> enum A {afoo, bfoo, cfoo};

(Aside: In D no semicolon is needed here.)

> string generateEnums(T...)(string type){
>     string code = "enum " ~ type ~ " {";
>
>     // this is a static foreach (compile time)
>     foreach(m; T){
>       debug pragma(msg, m ~ ","); // check what code we get at compile time
>       code ~= m ~ ",";
>     }
>
>     return(code ~ "}");

(Aside: Those parentheses are misleading. return is not a function.)

> }
>
> int main(){
[...]
>     mixin(generateEnums!members1("B"));
>     B switch_var_b = chomp(user_input).to!B; // get rid of terminating
> chars
>
[...]
> }
>
> <== END

I'm not saying that everything is perfect as it is, but that code can be made nicer with what we have right now:

----
template generateEnums(string[] members)
{
    // 'join' variant:
    import std.array: join;
    mixin("enum generateEnums {" ~ members.join(",") ~ "}");

    // 'format' variant:
    // import std.format;
    // mixin(format(q{ enum generateEnums {%-(%s, %)} }, members));
}

void main()
{
    alias B = generateEnums!([members1]);
    B switch_var_b = chomp(readln()).to!B;
    /* ... */
}
----

> How about being able to write something like "ensure_final_switch B;"
> and have this call a CTF that generates the necessary code and has
> access to tool for building D structured code, AST etc.? And has a
> compile-time state I can later access in a upcoming CTF.

So you're asking for AST macros, I suppose. There are two DIPs for them:

http://wiki.dlang.org/DIP50 - AST Macros
http://wiki.dlang.org/DIP78 - AST Macros Lite

I don't know where they stand, as I'm not really interested in the whole thing, but maybe one of those matches your vision.

If that's not what you have in mind, please be more concrete about what you think of. Maybe show some pseudo code showing how you'd like to be able to solve the example of generating enums.
February 02, 2016
On 2016-02-02 08:39:34 +0000, deadalnix said:

> That is definitely true that the compile time API is kind of screwy. That's definitively not you. I think the best path forward at this stage is to provide nice API as a library on top of it.

And if we do this, it's only a small step to add a functional layer to deal with this API where I can chain tranformations to generate my code.

My point to discuss was, that I think the combination "compile time API" + "compile time suited language" is something different than the road currently followed.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster

February 08, 2016
On 2016-01-31 13:59:06 +0000, Robert M. Münch said:

> I like CTFE and the meta programming idea for languages like D.
> 
> However, I'm wondering why most (everyone?) is trying to do meta-programming using the same language as the one getting compiled. IMO the use-cases a pretty different and doing CTFE, code-generation etc. needs some other approach. If you look at all the strange template syntax, strange hacks etc. it's all far from being obvious.
> 
> Why not have a CTL (compile-time-language) that has access to some compiler internals, that follows a more functional concept? We are evaluating sequences of things to generate code, include / exclude code etc.
> 
> From my experience with the different approaches, functional thinking is much better suited and simpler to use for CTFE goals.
> 
> IMO that would really be a big step ahead. Because you know a hammer, not everything is a nail...

Here is a link http://terralang.org/ where these guys mix Lua and their compiled language, to achieve what I was thinking about in the same line:

"In this use-case, Lua serves as a powerful meta-programming language. You can think of it as a replacement for C++ template metaprogramming3 or C preprocessor X-Macros4 with better syntax and nicer properties such as hygiene5."

Maybe this better explains, where I think it makes sense to seperate the two levels: language for the buidling-step, and language for the actual solution.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster

1 2
Next ›   Last »