4 ms·
Python doesn't work well for repl development. You cannot set the current module in Python as you can do in Lisp. So you're restricted to make changes to the cu
by coliveira 3y ago
Python doesn't work well for repl development. You cannot set the current module in Python as you can do in Lisp. So you're restricted to make changes to the current module. Also, debugging in the repl is not as powerful in Python.
- sillysaurusx 3y agoSure it does. Just paste the defs into the repl. You can also use `from importlib import reload` and then have an expression like reload(foo).bar() to constantly reload your foo library.
- kqr 3y agoBut this means you have to litter your application with support for it, doesn't it? In Common Lisp, I can stop at a breakpoint, paste in a new definition of any function in the application, and then resume and it will use the new definition everywhere rather than the one that existed when the breakpoint was triggered: https://two-wrongs.com/debugging-common-lisp-in-slime.html https://two-wrongs.com/debugging-common-lisp-in-slime.html
- vindarel 3y ago*and not only paste, but write, in the source file, the new definition, re-compile it (C-c C-c), and resume execution from a stackframe before this call. (a clarification for folks who would think we must paste in the REPL) That's useful not only for breakpoints but also for errors. We can fix an error without re-running everything from zero. https://www.youtube.com/watch?v=jBBS4FeY7XM https://www.youtube.com/watch?v=jBBS4FeY7XM
- oalae5niMiel7qu 3y agoReload only reloads one copy of the module. If there are other modules that imported the same module, your new definition will not be seen by them unless you find all the copies of foo in memory and reload them also. Since there's no reliable way to do that, you're more likely to just restart Python all the time.
- gilch 3y agoNot accurate as worded. Python caches module imports in `sys.modules`, so all imports get the same one. A `reload()` will reuse the same dict object that was being used as the module's namespace, so everything with a reference to the module object will see the same namespace and get the updates.
- mathisfun123 3y ago[flagged]
- dang 3y agoWhoa, please don't take HN threads into programming language flamewars, "slap fights", or attacks on other users. We're trying to avoid all that here. https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html
- mathisfun123 3y agoI didn't say this should be a slap fight - I said the last one was. I'm always at a loss with how reading comprehension should lead people to conclude X here but instead they conclude Y. Like it literally says the previous one ie I don't know how I could've made it any clearer. Also you're perpetual quoting of the rule book under the guise of "here's our credo" doesn't accomplish anything because it doesn't clarify what rule was broken (and just serves to obscure the censure under "we don't like your kind around here"). At minimum you should cite exactly what rule was broken.
- dang 3y agoYou broke the rules against flamebait and calling names. If you'd just make your comments less aggressive, it would be much better.
- forward-slashed 3y agoCheck out lpy-mode
- gilch 3y agoWhat? Yes you can. I do it all the time. import code; code.interact(local=vars(foo)) where `foo` is the module object you want to set as current. This launches a subREPL in that module's namespace. (EOF kills the subREPL and returns to main.) Python has a debugger in the standard library that can also do post-mortem inspections.