Closed RetiredWizard closed 3 years ago
Sorry, I've got some conflicts in prohram.py, perhaps because of changes made by brickbots. Grateful if you could take a quick look, thanks
Well I guess I don't understand why @brickbots is using the __str__ method here, perhaps it's useful for the terminal abstraction. In any case I'm going to need brickbots help. As far as I can see, this Pull Request requires the listing to be printed a single line at a time, however it appears to me that if the __str__ method is used, it will print the entire program object as a single object.
I guess the other option would be to create a couple new class variables for the line number/range to be listed. Perhaps that's a more appropriate technique than passing the arguments as I had originally done?
Hi @RetiredWizard ! Yeah... I saw this come through and I was excited, as I've been meaning to add selecting listing myself... but I also realized my restructuring of the list/save logic would break your PR :-/
My initial commit for loading/saving from disk just copied the listing logic into the save routine, which just really bothered me. So I put the logic for turning a program object into a text representation into the str method of the program object itself so it could be used in both places. Also allows you to just print(Program) to get the listing, which I thought was cute.
The way I propose handling this short term is to make a function to take a token list representing one 'line' and string-if it, then use this in the str for the program listing.
Then this could also be used in the list() method to actually list line by line. I'll grab your interpreter.py portion for calling list with params, reconfigure the string-ify business and issue a PR to get that functionality working as you originally designed and showcased in your awesome PyDos video.
Longer term, I'd like to experiment with a Statement class. That would be the logical place for the str method and I think it could be a neat solution to allow both compound statements (these would be decomposed on load and recomposed on stringification) and renumbering if desired. My only concern would be the increased memory usage, but I'm not sure how much cost there would be there.
Cool thanks @brickbots , I'll go ahead and close this PR :)
brickbots inspired me to try and get some of my changes in as pull requests in case you want to try and incorporate them. I'm very new to using github like this so just let me know if I'm doing something wrong :-)
This is a minor change which allows the list command to accept a line number or range of lines to be listed.