public override bool subst(ref Object a_term, VarBind binding) { System.Collections.Generic.List <Erlang.Object> result = new System.Collections.Generic.List <Erlang.Object>(); bool changed = false; foreach (Erlang.Object term in this.elems) { Erlang.Object obj = null; if (term.subst(ref obj, binding)) { result.Add(obj); } else { changed = true; result.Add(term); } } if (!changed) { return(false); } a_term = new Erlang.Tuple(result.ToArray()); return(true); }
public override bool match(Erlang.Object pattern, VarBind binding) { if (pattern is Erlang.Var) { pattern.match(this, binding); } else if (!(pattern is Erlang.Tuple)) { return(false); } Erlang.Tuple tup = pattern as Erlang.Tuple; if (arity() != tup.arity()) { return(false); } for (int i = 0; i < arity(); ++i) { if (!elems[i].match(tup[i], binding)) { return(false); } } return(true); }
internal static Erlang.Object create( char[] fmt, ref int pos, ref int argc, params object[] args) { var items = new System.Collections.Generic.List<Erlang.Object>(); Erlang.Object result = null; pos = skip_null_chars(fmt, pos); switch (fmt[pos++]) { case '{': if (State.ERL_OK != ptuple(fmt, ref pos, ref items, ref argc, args)) throw new FormatException( string.Format("Error parsing tuple at pos {0}", pos)); result = new Erlang.Tuple(items.ToArray()); break; case '[': if (fmt[pos] == ']') { result = new Erlang.List(); pos++; break; } else if (State.ERL_OK == plist(fmt, ref pos, ref items, ref argc, args)) { result = new Erlang.List(items.ToArray()); break; } throw new FormatException( string.Format("Error parsing list at pos {0}", pos)); case '$': /* char-value? */ result = new Erlang.Char(fmt[pos++]); break; case '~': if (State.ERL_OK != pformat(fmt, ref pos, ref items, ref argc, args)) throw new FormatException( string.Format("Error parsing term at pos {0}", pos)); result = items[0]; break; default: char c = fmt[--pos]; if (char.IsLower(c)) { /* atom ? */ string s = patom(fmt, ref pos); result = createAtom(s); } else if (char.IsUpper(c) || c == '_') { TermType t; string s = pvariable(fmt, ref pos, out t); result = new Erlang.Var(s, t); } else if (char.IsDigit(c) || c == '-') { /* integer/float ? */ string s = pdigit(fmt, ref pos); if (s.IndexOf('.') < 0) result = new Erlang.Long(long.Parse(s, CultureInfo.InvariantCulture)); else result = new Erlang.Double(double.Parse(s, CultureInfo.InvariantCulture)); } else if (c == '"') { /* string ? */ string s = pstring(fmt, ref pos); result = new Erlang.String(s); } else if (c == '\'') { /* quoted atom ? */ string s = pquotedAtom(fmt, ref pos); result = createAtom(s); } break; } return result; }
public override bool subst(ref Object a_term, VarBind binding) { System.Collections.Generic.List<Erlang.Object> result = new System.Collections.Generic.List<Erlang.Object>(); bool changed = false; foreach (Erlang.Object term in this.elems) { Erlang.Object obj = null; if (term.subst(ref obj, binding)) result.Add(obj); else { changed = true; result.Add(term); } } if (!changed) return false; a_term = new Erlang.Tuple(result.ToArray()); return true; }
internal static Erlang.Object create( char[] fmt, ref int pos, ref int argc, params object[] args) { var items = new System.Collections.Generic.List <Erlang.Object>(); Erlang.Object result = null; pos = skip_null_chars(fmt, pos); switch (fmt[pos++]) { case '{': if (State.ERL_OK != ptuple(fmt, ref pos, ref items, ref argc, args)) { throw new FormatException( string.Format("Error parsing tuple at pos {0}", pos)); } result = new Erlang.Tuple(items.ToArray()); break; case '[': if (fmt[pos] == ']') { result = new Erlang.List(); pos++; break; } else if (State.ERL_OK == plist(fmt, ref pos, ref items, ref argc, args)) { result = new Erlang.List(items.ToArray()); break; } throw new FormatException( string.Format("Error parsing list at pos {0}", pos)); case '$': /* char-value? */ result = new Erlang.Char(fmt[pos++]); break; case '~': if (State.ERL_OK != pformat(fmt, ref pos, ref items, ref argc, args)) { throw new FormatException( string.Format("Error parsing term at pos {0}", pos)); } result = items[0]; break; default: char c = fmt[--pos]; if (char.IsLower(c)) /* atom ? */ { string s = patom(fmt, ref pos); result = createAtom(s); } else if (char.IsUpper(c) || c == '_') { TermType t; string s = pvariable(fmt, ref pos, out t); result = new Erlang.Var(s, t); } else if (char.IsDigit(c) || c == '-') /* integer/float ? */ { string s = pdigit(fmt, ref pos); if (s.IndexOf('.') < 0) { result = new Erlang.Long(long.Parse(s, CultureInfo.InvariantCulture)); } else { result = new Erlang.Double(double.Parse(s, CultureInfo.InvariantCulture)); } } else if (c == '"') /* string ? */ { string s = pstring(fmt, ref pos); result = new Erlang.String(s); } else if (c == '\'') /* quoted atom ? */ { string s = pquotedAtom(fmt, ref pos); result = createAtom(s); } break; } return(result); }