public object VisitCall(Expr.Call expr) { var callee = Evaluate(expr.Callee); // Assuming 'Select' is left-to-right, we'll evaluate arguments left-to-right. // In C, this is undefined, so... /shrug. var arguments = expr.Arguments .Select(arg => Evaluate(arg)) .ToList(); var callable = callee as ILoxCallable; if (callable != null) { // JavaScript discards extra arguments and sets missing ones to 'undefined'. We'll be stricter. if (arguments.Count != callable.Arity) { throw new RuntimeError(expr.Paren, string.Format("Expected {0} arguments but got {1}", callable.Arity, arguments.Count)); } return(callable.Call(this, arguments)); } else { throw new RuntimeError(expr.Paren, "Can only call functions and classes"); } }
public object VisitCallExpr(Expr.Call expr) { var callee = Evaluate(expr.Callee); var arguments = new List <object>(); expr.Arguments.ForEach((e) => { arguments.Add(Evaluate(e)); }); if (!(callee is ILoxCallable)) { throw new RuntimeError(expr.Paren, "Can only call functions and classes."); } var function = callee as ILoxCallable; if (arguments.Count != function.Arity) { throw new RuntimeError(expr.Paren, $"Expected {function.Arity} arguments but got {arguments.Count}."); } return(function.Call(this, arguments)); }
object Expr.IVisitor <object> .VisitCallExpr(Expr.Call expr) { object callee = Evaluate(expr.callee); List <object> arguments = new List <object>(); foreach (Expr argument in expr.arguments) { arguments.Add(Evaluate(argument)); } if (!(callee is LoxCallable)) { throw new RuntimeError(expr.paren, "Can only call functions and classes."); } LoxCallable function = (LoxCallable)callee; if (arguments.Count != function.Arity()) { throw new RuntimeError(expr.paren, "Expected " + function.Arity() + " arguments but got " + arguments.Count + "."); } return(function.Call(this, arguments)); }
public object VisitCallExpr(Expr.Call expr) { Resolve(expr.Callee); expr.Arguments.ForEach(e => Resolve(e)); return(null); }
public Unit VisitCall(Expr.Call call) { Resolve(call.Callee); foreach (var arg in call.Arguments) { Resolve(arg); } return(Unit.Default); }
public Void Visit(Expr.Call expr) { Resolve(expr.Callee); foreach (var arg in expr.Arguments) { Resolve(arg); } return(Void.Instance); }
object Expr.IVisitor <object> .VisitCallExpr(Expr.Call expr) { Resolve(expr.callee); foreach (Expr argument in expr.arguments) { Resolve(argument); } return(null); }
public string VisitCall(Expr.Call call) { var builder = new StringBuilder(); builder.Append("(call "); builder.Append(call.Callee.Accept(this)); foreach (var arg in call.Arguments) { builder.Append(" "); builder.Append(arg.Accept(this)); } builder.Append(")"); return(builder.ToString()); }
public string VisitCallExpr(Expr.Call expr) { throw new NotImplementedException(); }