Loïc Grenié on Fri, 26 May 2017 08:28:08 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Getting my script to wait


On 2017-05-25 at 23:50 GMT+02:00 Bill Allombert wrote:
On Wed, May 24, 2017 at 05:58:22PM +0200, Dirk Laurie wrote:
> I'm writing a tutorial in GP that has little sections with a pattern
> of print text, print a Pari-GP _expression_, print its evaluation,
> print a little more text, wait until the reader is ready, go to the
> next section.
>
> I thought "input()" would wait for the user as it does in an interactive
> session. But no, if I invoke "gp tutorial.gp", it just continues as if the
> user typed an empty line, and the whole tutorial just fast-forwards by.
>
> I can understand why it does that: "tutorial.gp" becomes standard
> input, and there is nothing of it left.
>
> I can think of several workarounds, e.g. make a function of the whole
> tutorial which is invoked at the prompt, but also wonder whether I am
> missing something.

You are close tu the solution: make a function of the whole tutorial
and then execute the function as the last line of the script.

tut()=
{
  print("part 1");
  input();
  print("part 2");
  input();
  print("part 3");
}
tut()

     Wouldn't it be better if input() took its input from gp's stdin instead of the current
  script? What you have just written works because it is the last line of the script,
  however if the script is called from another (before its last line), it won't work
  anymore. Ex: I want to make several tutorial scripts, I can't make a script that
  calls each one in order. This does not sound right to me.

        Loïc