"read" question



----maxima-bounces at math.utexas.edu wrote: -----

>It didn't change things for me.  I also tried
>various combinations of
>load-reset-etc.
>
>What should the usage be?
>
>Here is how I used it.
>
>The new Interactive.mac:
>
>Restart():= block( while (foo # "q") do
>            (foo: read("Enter a number to
>continue, \"q\" to quit. "),
>                 print(" you entered ",foo)
>             ),
>          print(" Bye!")
>        )$

Make 'foo' local to the block. Otherwise, the
second time you run Restart, foo still has the
value "q". So the while immediately terminates.

Restart():= block([foo], while (foo # "q") do
           (foo: read("Enter a number to continue, \"q\" to quit. "),
                print(" you entered ",foo)
            ),
         print(" Bye!")
       )$

This time, I tested the code; it seems to work:

(%i1) load("q.mac")$
(%i2) Restart();
Enter a number to continue, "q" to quit.  0;
 you entered  0
Enter a number to continue, "q" to quit.  "q";
 you entered  q
 Bye!
(%o2)  Bye!
(%i3) Restart();
Enter a number to continue, "q" to quit.  sqrt(2);
 you entered  sqrt(2)
Enter a number to continue, "q" to quit.  42;
 you entered  42
Enter a number to continue, "q" to quit.  "q";
 you entered  q
 Bye!
(%o3)  Bye!

Barton