1 module orelang.operator.PrintOperator; 2 import orelang.operator.IOperator, 3 orelang.Engine, 4 orelang.Value; 5 import std.algorithm, 6 std.range, 7 std.stdio, 8 std.conv; 9 10 class PrintOperator : IOperator { 11 /** 12 * call 13 */ 14 public Value call(Engine engine, Value[] args) { 15 foreach (arg; args) { 16 Value item = engine.eval(arg); 17 18 if (arg.type == ValueType.String || (arg.type == ValueType.SymbolValue && (item.type == ValueType.IExpression || item.type == ValueType.ImmediateValue || item.type == ValueType.IOperator))) { 19 item = arg; 20 } 21 22 if (item.type == ValueType.Array) { 23 write("("); 24 write(item.getArray.map!(e => e.toString).join(" ")); 25 write(")"); 26 } else { 27 write(item.toString()); 28 } 29 } 30 31 return new Value(0.0); 32 } 33 } 34 35 class PrintlnOperator : IOperator { 36 /** 37 * call 38 */ 39 public Value call(Engine engine, Value[] args) { 40 foreach (arg; args) { 41 Value item = engine.eval(arg); 42 43 if (arg.type == ValueType.String || (arg.type == ValueType.SymbolValue && (item.type == ValueType.IExpression || item.type == ValueType.ImmediateValue || item.type == ValueType.IOperator))) { 44 item = arg; 45 } 46 47 if (item.type == ValueType.Array) { 48 write("("); 49 write(item.getArray.map!(e => e.toString).join(" ")); 50 write(")"); 51 } else { 52 write(item.toString()); 53 } 54 } 55 56 writeln; 57 58 return new Value(0.0); 59 } 60 }