private static object EvaluateVectorLiteral(VectorLiteral vectorLiteral, EvaluationContext context) { var vector = new double[vectorLiteral.Elements.Count]; for (int i = 0; i < vectorLiteral.Elements.Count; i++) { if (!((Evaluate(vectorLiteral.Elements[i], context) ?? 0.0) is double number)) { throw new InvalidOperationException($"A {BaseTypes.Vector} can only contain numbers."); } vector[i] = number; } return(vector); }
public WriteAction Visit(VectorLiteral vectorLiteral) { return(Format(ReservedName.__vector__ + "(@)", Translate(vectorLiteral.Items, ", "))); }
public Expression TypeCheck(VectorLiteral vectorLiteral, Scope scope) { var position = vectorLiteral.Position; var items = vectorLiteral.Items; var typedItems = TypeCheck(items, scope); var firstItemType = typedItems.First().Type; foreach (var typedItem in typedItems) Unify(typedItem.Position, firstItemType, typedItem.Type); return new VectorLiteral(position, typedItems, NamedType.Vector(firstItemType)); }
public string Visit(VectorLiteral vectorLiteral) { return(String.Format("[{0}]", Translate(vectorLiteral.Items, ", "))); }