I have a long loop going. It solves a solitaire board-game by brute force 
search, and depending on the initial configuration it could take seconds or 
years to finish, I never know.

I would like to be able to interrupt the loop at any time and save its 
state (basically the values in an Array the loop operates on). That would 
allow me to resume the loop later from where it left, instead of starting 
all over again.

Of course Ctrl-C is no good because I lose the state of the loop. My idea 
is something like:

   while true
      # do stuff #
      if (keyboard was pressed) && (key was 'p')      # for "pause"
         save Array to hard disk
         return
      end
   end

But I don't know how to check if "keyboard was pressed" and what key it 
was. I cannot use  chomp(readline())  because this waits until the user 
hits Enter, which stops the loop going (unless I leave a spoon pressing the 
Enter key :-). I need something that looks at the keyboard stack to see if 
a key was recently pressed, and if none was pressed, it does nothing and 
lets the loop continue without delay.

I normally work at the REPL.

Any ideas?

Like always, sorry if my Q is too basic, but I did check the documentation 
and the web and could not solve it.
And a big thank you to the Julia developers and community. I am loving it.

Reply via email to