Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Consider a generator that yields results indefinitely, or even merely millions of results. Are you still sure you want those printed to the repl? :)


The 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?


You'll need some killer heurstics: https://en.wikipedia.org/wiki/Halting_Problem


Er, I sorta knew that I was describing the halting problem, and was wondering if someone would fail to realize my sarcasm...


Yeah, I see that "should be easy enough" at the end. My bad.


That is all programs in general, checking a specific program is totally within bounds.


That 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: