[apluslist] Prompt for user input...using the windows display classes in a layout

Andrew Reilly aar at wadsworth.org
Thu Apr 15 16:39:02 EDT 2004


Brian and alaska:

Firstly, you can put a question in a window with:

 $mode ascii
 $load s
 QQwin q:{.p:=20 rho ' ';// initialize
          `.p s.is `scalar;// display class for any A+ object
          `.p s.has (`title`shelltitle`titlefg;(q;'Please Provide the Following Value';`blue));// provide 
user prompts
          s.show `.p}

The value returned after typing an answer in the window is stored in .p.

If you have a function which takes a single input value and outputs a character matrix
you can combine the above window in a layout with a view of the function's results using
a dependency. The resulting layout is interactive; changing the answer to the question
displays a new output.  A function to establish the layout is:

question RunWin func:{QQwin question;// Both arguments are strings
                      eval ".tr:",func," .p";// create the dependency of func on .p
                      `.tr s.is `view;// display class for char matrix output
                      .L:=`.p`.tr;`.L s.is `layout;// Combine .p's scalar and .tr's view classes into 
layout L
                      `.tr s.has (`title;"Output of ",func,":");// micro amount of documentation
                      `.L s.has (`title`shelltitle;("Provide the Following Value";"To Run Program 
",func));// provide user prompts
                      s.show each `.L`.tr}

Example: Here's a trivial function that turns an input vector into an 8 row char matrix with each row a 
copy of the input.

                 foo stg:{8/(1, rho stg) rho stg}
         
         To run foo in a window, execute 

                "What is a Noun?" RunWin "foo"

------------------------------
I have no idea if this is the 'right way...' but I'd appreciate any improvements.
As for exiting, I'm an $off kind of guy.  Is sys.exit(0) better in a way similar
to how kill -TERM is better than kill -9?

On Apr 14, 2004, at 5:23 AM, asubedi wrote:

> Hi,
>
> How would one prompt for user input and get it from command line in an
> A+ script? I have skimmed through the ref. manual and the tutorial but
> did not find any function to do this. Also, what is the preferred 
> method
> for exiting from the script: sys.exit(0), _exit 0, or $off?
>
> I am totally new to A+/APL so please bare my silly questions!
>
> Thanks,
> alaska
>
         

                  Andrew A. Reilly

           Internet: Andrew.Reilly at Wadsworth.Org 
           Voice: 518-473-3493 FAX:518-474-2769
                    Beeper:518-498-9394.  
      Wadsworth Center for Labs and Research. Rm. C543
             Empire State Plaza. P.O. Box 509.  
                   Albany, NY 12201-0509





More information about the apluslist mailing list