我对 J 很陌生(学习它是为了好玩),我正在尝试从键盘读取数据。我尝试制作一个小脚本来读取字符串并反转它:
|.(1!:1 3)
当我运行它时,我收到排名错误。 (我使用 1!:1 3 而不是定义动词,因为 codegolf...) 有没有命令可以检查 1!:1 3 的排名?
最佳答案
这是外国人常犯的错误。
definition对于外国 1!:1
没有帮助,因为它实际上是:
1!:1 y Read. y is a file name or a file number (produced by 1!:21); the result is a string of the file contents., e.g. 1!:1 <'abc.q'. The following values for y are also permitted: 1 read from the keyboard (does not work within a script) 3 read from standard input (stdin)
And so replacing y
with 3
should work, right? Well, not quite, because what you're really giving as an argument in writing:
1!:1 3
是一个由1 3
组成的数组。有点像给予它:
1!:(1 3)
当你想要的时候:
1!:1 (3)
出于代码高尔夫的目的,请使用右括号:
1!:1]3
关于input - 从 J 中的行读取输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13693806/