DylanSp / wheel-lang

A small toy imperative language (with some OOP features) for demonstrating and practicing language design/implementation.
MIT License
14 stars 0 forks source link

Add built-in print function #18

Closed DylanSp closed 4 years ago

DylanSp commented 4 years ago

Add some sort of print function as a built-in to allow output beyond just the returned value.

DylanSp commented 4 years ago

How to incorporate into type of evaluate? Instead of just returning Value, return (Array<Value>, Value), where the first part is the printed outputs and the second part is the returned value?

Alternatively, drop the mandatory top-level return?

DylanSp commented 4 years ago

Instead of returning Either<RuntimeError, (Array<Value>, Value)> like I was thinking above, evaluate should return (Array<Value>, Either<RuntimeError, Value>), allowing for output before hitting a runtime error. (First element as print output, second element as either error or top-level returned value)

DylanSp commented 4 years ago

Separate print functions for different types

DylanSp commented 4 years ago

Final implementation just has evaluate as an impure function, not changing its type.