aroberge / reeborg

Enhanced Karel-the-robot clone
http://reeborg.ca/reeborg.html
Other
47 stars 36 forks source link

possibility to sync execution with inputs #289

Closed dz0 closed 8 years ago

dz0 commented 8 years ago

This might extrapolate to more abstract issues, but current problem is

I want to run:

for a in range(5):
    turn_left()
    n = int( input("How many steps?") )
    for b in range(n):
        move()

and see how robot moves after each input.

dz0 commented 8 years ago

Possible sollutions:

aroberge commented 8 years ago

On Fri, Jun 3, 2016 at 5:40 AM, dz0 notifications@github.com wrote:

Possible sollutions:

-

simple: just run it in interpreter mode (but I dont like to paste it each time) -- could be a button run in interpreter.

This would be the simplest but could lead to some difficult (for beginners) mistakes to understand if a blank line is inserted in an indented block (as the interpreter would view that as the end of the block).

-

complex: would be alternative to "runing before replaying": similary as Reeborg uses variable tracing after each statement, would be possible inject some "_wait_for_input_or_next_ifpaused()", which could do empty waiting (loop with sleep (and hooked variable for Next button)?) Then Reeborg could run directly, and pause on each line/statement (or at least on inputs :) ).

This would not work: when the code is run in the normal way, it is first translated (by Brython) into Javascript and there is no way to pause.

-

otherwise just run it when

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/aroberge/reeborg/issues/289#issuecomment-223523455, or mute the thread https://github.com/notifications/unsubscribe/AAmbwogSXaVrap6RDQzpMFDcwQEZJdQ_ks5qH-hvgaJpZM4ItUF4 .

dz0 commented 8 years ago

could be a button "run in interpreter".

This would be the simplest but could lead to some difficult (for beginners) mistakes to understand if a blank line is inserted in an indented block (as the interpreter would view that as the end of the block).

I tried empty lines, and they seem not to cause problems...

move()

for a in range(5):
    turn_left()

    n = int( input("How many steps?") )
    for b in range(n):
        move()
dz0 commented 8 years ago

By the way, if we don't need execution navigation (pause and stepping), stuff could be run directly from editor and variable watching could remain, I guess..?

aroberge commented 8 years ago

The commit made with the comment "adding canvases as per issue 289" was referencing the wrong issue.

aroberge commented 8 years ago

"Run in interpreter" yields the same behaviour as running from the normal code editor. For the example you gave, no motion takes place before input() is asked -- so we don't know where the robot will be when the input is processed.

Using the interpreter, input() works well when it is a single line statement (outside of a loop).

dz0 commented 8 years ago

ups, you are right... I must have confused sometihing.. sorry...

aroberge commented 8 years ago

This is an issue that has come up a few times with Brython's development. See for instance

https://github.com/brython-dev/brython/issues/468

(I know that Skulpt supports this, but in a way that is incompatible with Brython.)

I am going to close this issue and only look at it if/when Brython changes the way it deals with input()