Stefan Ram wrote:
One might wish to implement a small language with these commands:
Explain why. What is the advantage?
F - move forward B - move backward L - larger stepsize S - smaller stepsize . One could start with the following pseudocode for a dictionary: { 'F': lambda: myturtle.forward( s ), 'B': lambda: myturtle.backward( s ), 'L': lambda: global s; s *= 2, 'S': lambda: global s; s /= 2 } . But lambda-expressions cannot contain statements. In real Python one could write something like (untested): def f(): myturtle.forward( s ) def b(): myturtle.backward( s ) def l(): global siz size *= 2 def s(): global siz size /= 2 { 'F': f, 'B': b, 'L': l, 'S': s } . Is this more readable or less readable? Any other suggestions?
-- https://mail.python.org/mailman/listinfo/python-list