On Thursday, 25 February 2016 at 12:53:37 UTC, asdf wrote:
I'm trying to make a terminal input preprocessor with alias/shortcuts and history.


import std.stdio;

void main() {
    string line;
    string[] history;

    line = readln();
    foreach(int i; 0..100) history = history + [""]; // XXX

    while(!stdin.eof) {
        writeln(line);
        if(line != history[0]) {
            history[1..100] = history[0..99];
            history[0] = line;
        }
        line = readln();
    }
}

In D the binary operator "~" is used to concatenate both strings (arrays of characters) and arrays. (also the ~= operator is equivalent to lhs = lhs ~ rhs

Nic

Reply via email to