input - 从 J 中的行读取输入

标签 input j

我对 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/

相关文章:

javascript - Javascript 运行时更新 html 文本框

javascript - 嘿!我如何解决我的代码显然没有从浏览器的 KeyboardEvent 正确获取 .key 属性?

j - 究竟是什么#^ :_1

规范排序的 J 语法?

reactjs - 将光标重置到 &lt;textarea&gt; React 的开头

input - 在 JavaFX 文本字段中限制输入的推荐方法

html - 仅更改输入占位符 * 颜色

嵌套显式定义

j - 排名如何运作?

j - 如何从 J 中的数组创建动名词?