[Jprogramming] Input from keyboard, output text to screen?
Raul Miller
rauldmiller at gmail.com
Sun Jan 1 20:15:01 HKT 2012
I am not sure this is good advice.
in j6.2, prompt is implemented using 1!:1]1
in my copy of j7.1, require'misc' does not work and prompt does not
exist. I do not know how other people are getting it to work in j7.1
--
Raul
On Sat, Dec 31, 2011 at 9:09 PM, bill lam <bbill.lam at gmail.com> wrote:
> From my understanding, 1!1[1 only works under ide session (ijx or jconsole),
> but not for standalone scripts. If your applications will always run inside an
> ide session I think prompt or 1!:1]1 will both work with minor difference
> as you noticed. Just use prompt if you prefer.
>
> Сбт, 31 Дек 2011, PackRat писал(а):
>> bill lam wrote:
>> > I'm puzzled. If prompt works for you, why 1!:1]1 didn't?
>>
>> Just to make sure that all info is known, this is NOT from jconsole,
>> which I never use. Rather, this is in a J session in .ijx and where
>> code is developed in .ijs.
>>
>> I tried the 1!:1]1 two different ways, using a cover verb (test1 and
>> test2) and using in-line code (test3):
>>
>> --------------------------------------
>> require 'files strings'
>>
>>
>> test1=: 3 : 0
>> d=. input 'enter something: '
>> smoutput < d
>> )
>>
>> test2=: 3 : 0
>> d=. input2 'enter something: '
>> smoutput < d
>> )
>>
>> test3=: 3 : 0
>> d=. 'enter something: ' 1!:1 ]1
>> smoutput < d
>> )
>>
>> input=: 3 : 0
>> y
>> entry=. 1!:1 ]1
>> )
>>
>> input2=: 3 : 0
>> y
>> 1!:1 ]1
>> )
>> --------------------------------------
>>
>>
>> It turns out from further testing that J does NOT hang when using this
>> approach. It only SEEMED that way because J was actually waiting for
>> input. Somewhere along the line, I thought I'd try pressing the ENTER
>> key--and, lo and behold, it seemed to break out of the "hang up" and
>> returned me to the normal session condition of waiting for a command.
>> Then I thought, "Maybe it was really waiting for input of some kind",
>> and so I typed some random letters before pressing the ENTER key. Lo
>> and behold (again!), it was working and was really waiting for input
>> all the time.
>>
>> The reason I originally didn't pursue this any further is that the
>> Dictionary misled me (is this a bug in the Dictionary?) when page
>> dx001.htm clearly stated, "read from the keyboard (does not work within
>> a script)". The behavior I described above fit into the Dictionary's
>> statement (because the seeming misbehaviors were in a script), and so I
>> didn't pursue it any further but asked here for alternatives instead.
>>
>> So, in answer to your question, bill: yes, it really does work; I just
>> didn't realize it. Well, almost...
>>
>> The reason I didn't realize it is that I thought that (in input and
>> input2) the literal y would display, and it didn't. By inserting
>> "smoutput" ahead of the y's, the prompts displayed. With test3, the
>> first line had to be split in two: the first displaying the prompt
>> using smoutput, and the second the desired code. Because the prompt
>> literals didn't display originally, I thought the code wasn't working,
>> when in fact J was waiting for input. (The reason I thought the
>> prompts would display in the code at the top of this email is that
>> single literals usually seem to display in J, and I didn't realize that
>> the safest approach apparently is to always use "smoutput" or "1!:2]2"
>> to display them.)
>>
>> The lingering problem with this approach is that, in contrast to the
>> "prompt" verb, the prompt literal and the user input are on separate
>> lines--not a good thing. Here's the visual difference, using an
>> underscore to indicate the location of the cursor:
>>
>> Your 1!:1]1 approach: The "prompt" verb:
>>
>> This is the data prompt: This is the data prompt: _
>> _
>>
>> Or is there some documentation somewhere that indicates how your
>> approach can be made to look like the "prompt" verb approach?
>>
>> I hope this extra information helps explain the situation more clearly.
>>
>>
>> Harvey
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> regards,
> ====================================================
> GPG key 1024D/4434BAB3 2008-08-24
> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list