Sounds like we're in violent agreement. :-)<br><br>On Monday, September 28, 2015, Random832 <<a href="mailto:random832@fastmail.com">random832@fastmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Guido van Rossum <<a href="javascript:;" onclick="_e(event, 'cvml', 'guido@python.org')">guido@python.org</a>> writes:<br>
> I would at least define different classes for the uptalk versions.<br>
><br>
> But my main complaint is using the parse tree as a spec at all<br>
<br>
Like I said, I actually came up with that structure *before* seeing that<br>
it mirrored a grammar element - it honestly seems like the most natural<br>
way to embody the fact that evaluating it requires the whole context as<br>
a unit and can short-circuit halfway through the list, depending on if<br>
the 'operator' at that position is an uptalk version.<br>
<br>
The evaluation given this structure can be described in pseudocode:<br>
<br>
def evaluate(expr):<br>
  Â  value = expr.atom.evaluate()<br>
  Â  for trailer in trailers:<br>
  Â  Â  Â  if trailer.uptalk and value is None:<br>
  Â  Â  Â  Â  Â  return None<br>
  Â  Â  Â  value = trailer.evaluate_step(value)<br>
<br>
The code generation could work the same way, iterating over this and<br>
generating whatever instructions each trailer implies. In CPython, The<br>
difference between the uptalk and non-uptalk version would be that<br>
immediately after the left-hand value is on the stack, insert opcodes:<br>
DUP_TOP LOAD_CONST(None) COMPARE_OP(is) POP_JUMP_IF_TRUE(end), with the<br>
jump being to the location where the final value of the expression is<br>
expected on the stack.<br>
<br>
Assuming I'm understanding the meaning of each opcode correctly, this<br>
sequence would basically be equivalent to a hypothetical JUMP_IF_NONE<br>
opcode.<br>
<br>
I don't think a recursive definition for the structure would work,<br>
because evaluating / code-generating an uptalk operator needs to have<br>
the top-level expression in order to escape from it to yield None.<br>
<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'Python-ideas@python.org')">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote><br><br>-- <br>--Guido van Rossum (on iPad)<br>