Hi -

this is a recurring question but the answer keeps changing as Raul
indicated.  The extensive answer here -
http://www.jsoftware.com/jwiki/RicSherlock/Temp/InteractivePrompt - is
out of date with J7, so I attempted to figure out how to update it.

It looks like you can do this from the J7 GTK interface:
   load '~addons/gui/gtkwd/jinput.ijs'
   input_result=: 3 : 'RESPONSE=: y'
   create_jinput_ 'Hi"

to create a window with the prompt "Hi" and return the result in the
global "RESPONSE".  Unfortunately, this breaks silently on the "try."
line in "a_ok_button_jinput_" because "COCREATOR" is not defined; this
is supposed to be a callback to the user-defined "input_result" verb
(as in the example shown above) in the namespace that created the
prompt.

My klugy fix for it is to re-define "a_ok_button_jinput_" as follows -
by hard-coding the "base" namespace - then ensuring that you run from
this (which is the default) namespace:

a_ok_button_jinput_=: 3 : 0
wd 'pclose'
try. input_result_base_ edit catch. end.
destroy''
)

So, after loading "jinput.ijs", re-defining as shown and creating
"input_result" as shown, when you run
   create_jinput_ 'Hi'
you'll get a (character vector) variable "RESPONSE" with the user's input.

On Mon, May 7, 2012 at 10:58 AM, Raul Miller <[email protected]> wrote:
> On Mon, May 7, 2012 at 10:20 AM, James Bragg <[email protected]> wrote:
>> First, I'm really enjoying learning J.
>
> That is good to hear.
>
>> Is there a prompt verb? Would "get input" be a prompt verb? Is it possible
>> to get input from a user in the J Term gtk window or J console and assign it
>> to a variable?
>
> There is, but it's ... it's not exactly deprecated, but "neglected"
> might be accurate.
>
> For most purposes, the J command line is the best "prompt verb".
>
> For many other purposes, you should be building a "UI" rather than a
> command line interface.  If you are going to stick to a command line
> interface, the J command line is usually the best tool for the job.
>
> This leaves a neglected niche for the spurious cases where you want a prompt.
>
> In j6.02, this worked in the GUI and I think worked in jconsole on
> linux/mac (but not in jconsole on windows):
>
>   require'misc'
>   prompt '$ '
> $ 1 2 3
> 1 2 3
>
> In J7.01, with its various front ends for jconsole (including the
> browser, via jhs) I do not think that this mechanism is supported
> robustly.  (But I have not kept up to date on everything that's going
> on in J7.01 so maybe that aspect has been built out.)
>
> FYI,
>
> --
> Raul
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm



-- 
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to