namespace Eva { public class Var : Object, Term { public string name {get; construct;} public Var(string name0) { assert(name0.get_char() == '_' || name0.get_char().isupper()); Object(name: name0); } public string to_string() { return name; } internal static string alias(string key, Gee.Map aliases) { if(!(key in aliases.keys)) return key; else return alias(aliases[key], aliases); } protected bool do_match(Term o, Gee.Map vars, Gee.Map aliases) { if(name == "_") { return true; } string key = alias(name, aliases); if(o is Var) { Var v = o as Var; if(v.name == "_") { return true; } string vkey = alias(v.name, aliases); if(key == vkey) return true; if(key in vars.keys && vkey in vars.keys) return vars[key].do_match(vars[vkey], vars, aliases); else if(!(vkey in vars.keys)) { aliases[vkey] = key; return true; } else /* !(key in vars.keys) */ { aliases[key] = vkey; return true; } } else { if(key in vars.keys) { return vars[key].do_match(o, vars, aliases); } else { vars[key] = o; return true; } } } internal void encode(Buffer buffer) { assert_not_reached(); } } }