yaegi icon indicating copy to clipboard operation
yaegi copied to clipboard

interp: default to None for non-valued statements

Open firelizzard18 opened this issue 3 years ago • 2 comments

Here am using 'None' to refer to the functional programming concept of an empty result. I added interp.EmptyResult since that is far clearer than 'None', especially to users not familiar with functional programming jargon.

Updates *Interpreter.ast to use val: EmptyResult as the default, instead of new(interface{}). Updates genValue to always return node.val for a block statement where the last statement is var x = 1, x := 1, or x = 1.

As a result, variable declarations and assignments return a value of interp.EmptyResult.

firelizzard18 avatar Apr 14 '21 03:04 firelizzard18

The current state is not consistent. It would be better to always disable result output for assignment rather than adding an option, for consistency and simplicity. Could you modify your PR in that direction ? Thanks

mvertes avatar May 10 '21 14:05 mvertes

@mvertes This is ready for review. Now, all variable declarations and assignments return the special value interp.EmptyResult.

firelizzard18 avatar Aug 23 '21 21:08 firelizzard18