infinite-loop

How do I handle an infinite list of IO objects in Haskell?

拈花ヽ惹草 提交于 2019-12-04 11:18:20
问题 I'm writing a program that reads from a list of files. The each file either contains a link to the next file or marks that it's the end of the chain. Being new to Haskell, it seemed like the idiomatic way to handle this is is a lazy list of possible files to this end, I have getFirstFile :: String -> DataFile getNextFile :: Maybe DataFile -> Maybe DataFile loadFiles :: String -> [Maybe DataFile] loadFiles = iterate getNextFile . Just . getFirstFile getFiles :: String -> [DataFile] getFiles =

How can I detect elapsed time in Pascal?

拈花ヽ惹草 提交于 2019-12-04 10:12:50
I'm trying to create a simple game in Pascal. It uses the console. The goal in the game is to collect as many 'apples' as you can in 60 seconds. The game structure is a simple infinite loop. Each iteration, you can make one move. And here's the problem — before you make the move ( readKey ), time can pass as much as it wants. For example, the user can press a key after 10 seconds! Is there any way to count time? I need the program to know when user plays (before and after a key is pressed), so I don't know how to prevent user from "cheating". Here's simple structure of my game: begin repeat {*

How is this causing an endless loop?

偶尔善良 提交于 2019-12-04 08:42:43
Some legacy code I'm stuck maintaining is stuck in an infinite loop (and thus I myself seem to be in one); I can't figure out why/how, though. Here's the app's entry point, where it instantiates the main form (frmCentral): CODE EXHIBIT A public static int Main(string [] args) { try { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(GlobalExceptionHandler); string name = Assembly.GetExecutingAssembly().GetName().Name; MessageBox.Show(string.Format("Executing assembly is {0}", name)); // TODO: Remove after testing <= this

Hudson infinite loop polling for changes in Git repository?

依然范特西╮ 提交于 2019-12-04 06:55:38
The git plugin for hudson works well. However, the build script must update a version number in the files in the repository, commit, and push back to the repository. When Hudson polls next to check for changes, it goes into an infinite loop because it sees that commit as a "change" builds again, which commits a change, so it builds again, then it commits another change, etc... You get the idea. I stopped it, ran a "git log" in each repository and compared the latest commit ids are exactly the same using git ls-tree HEAD Also, Hudson runs this command to check for changes: git fetch +refs/heads

Try catch block causing infinite loop? [duplicate]

感情迁移 提交于 2019-12-04 06:48:36
问题 This question already has answers here : try/catch with InputMismatchException creates infinite loop (7 answers) Closed 4 years ago . I am writing a simple java console game. I use the scanner to read the input from the console. I am trying to verify that it I ask for an integer, I don't get an error if a letter is entered. I tried this: boolean validResponce = false; int choice = 0; while (!validResponce) { try { choice = stdin.nextInt(); validResponce = true; } catch (java.util

C++: Infinite loop with a simple menu selection

旧时模样 提交于 2019-12-04 05:48:54
问题 The script I am working on is over a page long, so I am going to link it (one simple file): http://pastebin.com/7BVHmQGp I apologize for that. My problem is I get into an infinite loop in my code, for example after I select 1 or 2 for encrypting/unencrypting it lets me enter the word, and when I next enter the "shift" for the cipher it runs an infinite loop of the menu. I had tried for so many hours to debug this, I thought it was a problem with cin , for example when you enter an invalid

Why does not my program go into infinite loop when array out of bounds occur in C

折月煮酒 提交于 2019-12-04 05:43:33
问题 int main(){ int i; int arr[4]; for(int i=0; i<=4; i++){ arr[i] = 0; } return 0; } I watched a video on youtube of CS107(lecture 13) in which this example is shown and told why the above program will lead to infinite loop by showing memory diagrams. arr[4] goes out of bounds and should lead to an address where i is stored and changing the value of i back to 0 hence leading to infinite loop. But when I tried to run this on my mac using gcc compiler, for loop executed (checked by inserting

Modification of the basic if expression in Scheme. Why does it go into an infinite loop?

冷暖自知 提交于 2019-12-04 04:22:44
问题 In Scheme, I modified the basic 'if' command as: (define (modified-if predicate then-clause else-clause) (if predicate then-clause else-clause)) And then I defined a simple factorial generating program using the modified version of if: (define (factorial n) (modified-if (= n 0) (* n (factorial (- n 1))))) Now, when I call the above function, it goes into an infinite loop. Why does that happen? 回答1: Scheme has eager evaluation. This means that, unless you're using a special form (like if ) or

Fast Repeat TakeWhile causes infinite loop

假如想象 提交于 2019-12-04 04:03:05
How can I make the following observable repeat until stream.DataAvailable is false? Currently it looks like it never stops. AsyncReadChunk and Observable.Return inside the Defer section make OnNext call then OnCompleted call. When Repeat receives the OnNext call it passes it to TakeWhile. When TakeWhile's is not satisfied it completes the observable but I think the OnCompleted that comes right after the OnNext is so fast that it makes Repeat to re-subscribes to the observable and causes the infinite loop. How can I correct this behaviour? public static IObservable<byte[]> AsyncRead(this

Scala while(true) type mismatch? Infinite loop in scala?

心不动则不痛 提交于 2019-12-04 02:43:37
Why following code def doSomething() = "Something" var availableRetries: Int = 10 def process(): String = { while (true) { availableRetries -= 1 try { return doSomething() } catch { case e: Exception => { if (availableRetries < 0) { throw e } } } } } produces following compiler error error: type mismatch; found : Unit required: String while (true) { ^ ? This works ok in C#. The while loops forever, so it cannot terminate, therefore it cannot result something else than string. Or how to make infinite loop in Scala? Unlike C# (and Java and C and C++) which are statement based languages, Scala is