I'm referring to the ability of D templates beyond the ability to write 
function or struct class templates, but templates over blocks that include new 
types and variables, almost like the parameterized module system of OCaml. 
Forgive me for writing D here, I'll translate it to Future Nim soon ;-)

As with C++ D has function templates like so
    
    
    void copy(T)(out T to, T from) {
        to = from;
    }
    
    T sum(T)(T lhs, T rhs) {
        return lhs + rhs;
    }
    
    
    Run

and struct/class templates like
    
    
    struct Node(T) {
        T v;
        Node* left;
        Node* right;
    }
    
    
    Run

but D has a general code block template, in which you can declare variables and 
new types, like
    
    
    template MyTemplate(T) {
        T val;
        
        void copy(out T to, T from) {
            to = from;
        }
        
        struct Node {
            T v;
            Node* left;
            Node* right;
        }
    }
    
    
    Run

In D the function and struct templates are special cases of the more general 
code block syntax, but that's not important. What's important to me is that it 
is like a parameterized module, so I can declare variables in there.

Reply via email to