private string printSValue(SValue re, ExecEnvironment env, int padding) { if (re is SList) { return("(" + String.Join(" ", from v in re.Get <List <SValue> >() select printSValue(v.Evaluate(env), env, padding)) + ")"); } else if (re is SDict) { return("\n" + "(".PadLeft(padding - 1) + "\n" + String.Join("\n", re.Get <Dictionary <String, SValue> >().Select(kv => "".PadLeft(padding) + kv.Key + "=" + printSValue(kv.Value.Evaluate(env), env, padding + 2) )) + "\n" + ")".PadLeft(padding - 1)); } else if (re is SNull) { return("null"); } else { return(String.Format("{0}", re.Underlying)); } }
private SValue convert(SValue num) { if (num is SNumber) { var n = num.Get <Decimal>(); if (convertChr) { return(new SString(((char)n).ToString())); } else { return(new SString(n.ToString())); } } else if (num is SBool) { return(new SString(num.Get <bool>().ToString())); } else if (num is SList) { return(new SList((num as SList).Get <List <SValue> >().Select(n => convert(n)).ToList())); } else { return(num); } }
private SValue convert(SValue str) { if (str is SString) { var s = str.Get <String>(); if (convertAsc && s.Length >= 1) { return(new SNumber(s[0])); } else { Decimal tmp; if (Decimal.TryParse(s, out tmp)) { return(new SNumber(tmp)); } else { return(new SNull()); } } } else if (str is SList) { return(new SList((str as SList).Get <List <SValue> >().Select(n => convert(n)).ToList())); } else { return(str); } }
public override SValue Evaluate(ExecEnvironment env) { SValue lenValue = argument.Evaluate(env); if (lenValue is SString) { return(new SNumber(lenValue.Get <string>().Length)); } else if (lenValue is SList) { return(new SNumber(lenValue.Get <List <SValue> >().Count)); } else { return(new SNumber(0)); } }
public override SValue Evaluate(ExecEnvironment env) { SValue lenValue = dict.Evaluate(env); if (lenValue is SDict) { return(new SList((from k in lenValue.Get <Dictionary <string, SValue> >().Keys.ToList() select(SValue) new SString(k)).ToList())); } else { throw new VMException("it only take a dict as the argument", headAtom); } }