How to get user input in the J programming language

298 Views Asked by At

I'm very new to the J programming language, so I got interested in array programming languages and decided to give it a go. Unfortunately, It's a very niche language, meaning that there aren't many learning resources available. For that reason, I haven't figured out how to get user input in J, I'm making a simple program where the program asks the user for a name and greets them.

I tried asking ChatGPT for the solution, However, It didn't work. I'll still show the code it told me: insertVariableNameHere =: 1!:1]0 I also tried searching for it, but it gave me results on java, jquery, javascript, and other unrelated languages.

2

There are 2 best solutions below

2
bob On BEST ANSWER

ChatGPT is close, but in terse languages like J, close is not good enough. It does use 1!:1 which is the 'read from files' foreign conjunction, but it needs to have the argument 1 and not 0.

   read=: 1!:1  NB. read becomes a verb to read from file
   variable=: read 1 NB. 1 designates keyboard as the source to be read
1 2 3 4    NB. indented waiting for input
   variable  NB. Now contains what you entered.
1 2 3 4

Nothing that you are asking here is obvious or dumb. There is a lot of information about J in the J wiki and a really good place to start is here: https://code.jsoftware.com/wiki/For_New_Users or for more learning materials: https://code.jsoftware.com/wiki/Books

If you move off of jconsole onto either JQt or JHS environments you also get the benefit of the J labs which are interactive tutorials. Enjoy your journey with J.

0
user3234709 On

Something like this perhaps?

greeting=:3 : 0
input=:1!:1[1
echo 'Hello ',input
)

Sample run:

greeting ''
Jason

Output:

Hello Jason