Input line in J script freezes

I am writing a script in J for linux C #!

But the script freezes. After Control-D, the script displays the entered value. But regular ENTER only puts the cursor on a new line.

#!/path/jconsole a =. 1!:1]3 echo a exit '' 
+5
source share
2 answers

You cannot read one line of text while j is in script mode, but you can schedule something to run the next time j returns to immediate mode by setting the immex frame from 9!:27 and then setting the immex bit to 1 with 9!:29 . Here is an example:

 #!/usr/bin/env j NB. demo showing how to make a simple repl in j. readln =: [: (1!:01) 1: donext =: [: (9!:29) 1: [ 9!:27 main =: verb define echo '' echo 'main loop. type ''bye'' to exit.' echo '--------------------------------' while. (s:'`bye') ~: s:<input=:readln'' do. echo ".input end. echo '--------------------------------' echo 'loop complete. returning to j.' NB. or put ( exit'' ) here to exit j. ) donext 'main _' 
+3
source

The fact is that (1!:1)&3 is read to the "end of file". On Linux, pressing ctrl-D sends an EOF signal.

If that’s not what you are looking for, I’m afraid there’s nothing there but your ugly stunt

 a=. shell 'read foo; echo -n $foo' 

as (1 !: 1) & 1 only works during a session for some reason ...

+2
source

Source: https://habr.com/ru/post/1206458/


All Articles