Skip to content

New Python simulator UI and library#1

Open
isaacev wants to merge 51 commits intodaniel3735928559:masterfrom
isaacev:master
Open

New Python simulator UI and library#1
isaacev wants to merge 51 commits intodaniel3735928559:masterfrom
isaacev:master

Conversation

@isaacev
Copy link

@isaacev isaacev commented Sep 23, 2015

Includes:

  • Pratt parser
  • Interpreter
  • Booleans, numbers, strings, arrays
  • Subscript notation (for arrays and strings)

To do:

  • No functions
  • Error system needs better messages

@daniel3735928559
Copy link
Owner

This looks awesome!

I'd rather wait on merging until I have factored out the simulator entirely into an AngularJS directive, as this will make configuration much cleaner and leave room for things like "make this instance not allow functions". I planned to do that this week but it's now looking more like next week.

In the meanwhile, some nits:

  • /sim/py/python{,_full}.html both include .../CodeMIrror/codemirror.css rather than .../CodeMirror/codemirror.css.
  • I think having two versions--one for the homework and one for the text--will probably create confusion, so I'd rather have the homework sim updated in the same PR. (This gets eventually included from /homework/homework.html, but you'll probably have to change /sim/quest/quest.html.)
  • In the tutorial in this version, when you modify a program, then click away to another section of the tutorial, then click back to the section whose program you modified, the modification is gone. (The way this works in the current version is Angular events, but this will hopefully change when the refactoring happens, so maybe don't worry about this for now unless it's trivial.)
  • There should be a reset button that restores the program to its original state (for in-line simulators, this is so that if readers make modifications then they don't have to refresh the page to get back to the original example if they mess it up and want the original back).
  • I think I'd rather not have an actual window alert when single-stepping through the program and it finishes. The box that shows up in the program editor is probably sufficient.

@isaacev
Copy link
Author

isaacev commented Sep 25, 2015

I'll work on getting some of your suggestions implemented soon. I just have a couple of questions:

  • What methods should be included for manipulating or inspecting arrays?
  • What syntax should be implemented for appending/removing array elements (if any)?
  • I was thinking about forcing functions to explicitly return a value to prevent functions that return None and functions that return functions. Thoughts?

@daniel3735928559
Copy link
Owner

Officially the only array function that was covered in class was + for concatenation. I additionally support len(arr) and del arr[i] (though these are not part of the current incarnation of the course).

The way I currently handle returns is that you can return nothing, but then using the function call in an expression will create an error. For example, 2*print("hi") will cause an error. On the other hand, I do want to be able to do, for example:

def f(x):
   print(x)
   print(x+1)
   print("Whew; enough maths for today")
   return
f(4)

Whether omitting the return statement should be allowed is a question, but it probably doesn't matter either way.

isaacev added 22 commits October 3, 2015 16:56
+ constant DOM manipulation slows down fast program execution
@isaacev
Copy link
Author

isaacev commented Oct 9, 2015

Should the simulator changes be moved to the Spy repo?

@daniel3735928559
Copy link
Owner

I think here is right. What I've tried to do with the reorg is spin off spy as a separate project that is included and loaded in like any other third-party library (CodeMirror, for example). (I know I haven't quite got around to expressing this properly with a package.json and npm dependencies, but that's the eventual goal.) My thinking on this PR is to add in MiniPy as another library, replace all references to spy with references to MiniPy, and, ideally, remove the spy dependency entirely. (I guess in that world, spy will continue to exist, but I can mark it deprecated and make it a pointer. And this way, in the ideal future you can maintain the MiniPy npm package separately and discovering-cs can just depend on it.)

To this end, the simplest thing would be to wrap MiniPy in an Angular directive, say simPy (or maybe miniPy) with the same interface as the simPy directive described in the README to spy (which actually requires a bit of updating--let me do that quickly).

Then the files can go in /lib/MiniPy/minipy.js and similar, whereupon changing the <script> tags in /homework and /sim/quest from lib/spy/sim.js to lib/Minipy/minipy.js (and seemingly there are a few other js file to include as well--that's of course fine) should be the extent of the change to and interaction with existing code.

A quick glance leaves me unsure that mimicking that interface verbatim really makes sense, but have a look and we'll see if we can figure out something close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants