regarding the downsides, Henry's immex trick solves the startup issues.  If we 
assume that the user is running the program on his own computer, then the 
issues of potentially not following instructions are moot, since he could 
refuse to run any program.

The upside to this approach is that the same program will run on ios, jhs, and 
qt/gtk/j6 platforms

The approach may be more suited to inclusion in a lab.  But it could also be 
used to lock a console input loop to a particular context such as a controlling 
a gui window, or zork like game.  The input loop does not need to be so much a 
security measure as much as a user friendly command interface with the 
appropriate variables/context prebound to the input loop.


----- Original Message -----
From: Devon McCormick <[email protected]>
To: J-programming forum <[email protected]>
Cc: 
Sent: Sunday, April 6, 2014 11:47:07 AM
Subject: Re: [Jprogramming] Need help on "super simple" keyboard input.

There's this wiki page on this subject -
http://www.jsoftware.com/jwiki/RicSherlock/Temp/InteractivePrompt - which
also explains why we don't like to do things like this in J.


On Sun, Apr 6, 2014 at 10:46 AM, Henry Rich <[email protected]> wrote:

> Wow, that's a new one.  1!:1 at EOF during load apparently just aborts the
> sentence that is running (you want it to read from the keyboard, but you
> are really asking to read from standard input, which is the script.  If you
> had followed your line "pname ''" with another line, it would have read
> THAT, but attempting to read at EOF seems to abort).
>
> Even if your pname'' had worked, it wouldn't type anything, because the
> result of a sentence isn't automatically typed when a script is loaded.
>
> You need to run pname'' AFTER the script has been loaded.  Here's how:
>
>
> put =: (1!:2) & 2
>
> pname =: 3 : 0
> put 'What is your name?'
> name=: [(1!:1) 1
>
> 'Your name is ', name
>
> )
>
> NB. Set immex so that the following line runs AFTER load
> 9!:27 'pname 0'
> 9!:29 (1)
>
>
>
> Henry Rich
>
>
> On 4/6/2014 10:23 AM, Ray Zhao wrote:
>
>> After learning J really slowly for the past little while, I realized that
>> it was probably because all the examples had to do with array
>> manipulation,
>> which was cool, but even though I was able to do reversals and ravels and
>> stuff, I still wasn't able to make a program that can ask for the user's
>> name.
>> Yesterday, I found out that on Chapter 28 of Learning J (wow, all the way
>> back there) there was a snippet similar to this:
>>
>> put =: (1!:2) & 2
>>
>>      pname =: 3 : 0
>>
>> put 'What is your name?'
>>
>> name=.(1!:1) 1
>>
>> 'Your name is ', name
>>
>> )
>>
>>
>> When I first tried to code that, I didn't put that prompt into a function
>> and it seemed to skip the input. The second time, I put the line pname ''
>> under the function and it said syntax error, but when the program is run
>> and one types pname '', it THEN works.
>>
>> Is there a way to code this so that when the program is run, the first
>> thing that shows up is "What is your name?" and the program waits for the
>> user to input without having to run the program first and type something
>> like pname ''?
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>>  ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
Devon McCormick, CFA

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to