4 ms·
Consider a generator that yields results indefinitely, or even merely millions of results. Are you still sure you want those printed to the repl? :)
by zephjc 13y ago
Consider a generator that yields results indefinitely, or even merely millions of results. Are you still sure you want those printed to the repl? :)
- gizmo686 13y agoThat is the approach that Haskell takes. If the repl responds to ^C by aborting whatever line it was evaluating then infinite results are little more than annoying, and you quickly learn to restrict what it prints to the first few elements (in python this would just involve appending [:n]). Ultimatly this is a question of which uses you want to optimize. Personally, I find Haskell's approach more useful as a calculator. A middle ground that I have not seen is automatically evaluating the first few elements and showing those as part of the <object> output.
- reuven 13y agoThe Python interactive shell could check the user's input: If it'll take infinitely long to run (e.g., an infinite generator), then it'll halt. If the code will eventually return, then it'll be run, displaying results to the user. Seems simple enough, no?
- hyperpape 13y agoYou'll need some killer heurstics: https://en.wikipedia.org/wiki/Halting_Problem https://en.wikipedia.org/wiki/Halting_Problem
- reuven 13y agoEr, I sorta knew that I was describing the halting problem, and was wondering if someone would fail to realize my sarcasm...
- hyperpape 13y agoYeah, I see that "should be easy enough" at the end. My bad.
- sitkack 13y agoThat is all programs in general, checking a specific program is totally within bounds.