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