你其实并不想要那样
有一些基本的语法原因导致您无法默认地对运算符(副词和连词)的参数进行切片和切块。
Without going into detail, allowing operators to be modified by other operators, like your proposed /
modified with "1
, would require a fundamental restructuring of J's grammar. And there would be major tradeoffs, in particular to simplicity and expressiveness (i.e. notational elegance)¹,².
因此,如果您想像这样将运算符分配给动名词,则必须为其编写实用程序,而迄今为止最直接的方法是使用显式代码。在此领域中需要考虑的一个预打包实用程序是doog脚本,可在 J Wiki 和 SVN 存储库中找到 http://code.jsoftware.com/wiki/User:Dan_Bron/Snippets/DOOG.
无论如何,这就是
但是,那doog
脚本,就像你的方法一样,基本上是明确的。
因此,如果你真的想心照不宣地达到这些目的:
D =. foo`bar`baz
t =. D / (@:]) NB. Here's our "over" (/)
over =. [^:(D -: ]) L: (L.D) & (5!:1<,'t')
allOver =: (]^:[~ 1:`'' , over f.)~
3 4 5 6 allOver"1~ (A.~i.@!@#) *`+`- NB. Note the "1
9 _21 _1 _23 _41 _31
我警告过你
在不涉及太多细节的情况下,这里的技巧是使用动词]^:[
允许^:
执行任意原子表示作为输入。
那是,some_atomic_rep f^:[ data
变成f^:some_atomic_rep data
,对于合适的原子表示,它可以执行任何事情,同时使用动词可用的所有参数处理优点(特别是排名)。
剩下的只是一种优雅的(读:懒惰的)方法,将你的动名词输入(无论你为具有等级或其他参数选择机制的动词提供哪个部分)转换为适合右侧参数的原子表示^:
.
The meat of it is we have the template D / (@:])
and we replace D
with the gerund of your choice (the @:]
is necessary because by the time the gerund gets executed, it'll have two inputs: your actual input, d
, as well as itself, D
)4.
裂口
要探访这些邪恶愚蠢行为的“Ultima Thule”,请查看以下发现:dont in J http://www.jsoftware.com/pipermail/programming/2013-January/031236.html,这就像do
(".
),除了......真的,你不应该。
¹ As a quick example: puzzle out what this would mean for precedence between wordclasses.
² Having said that, Jose "Pepe" Quintana, the leader of the underground J club F^4 (The Fully Fixable Functional Faction http://www.jsoftware.com/pipermail/programming/2009-December/017070.html), once found a backdoor that actually did allow operators to take other operators as inputs. See this message in the "J Myths Puzzles" thread from 2008 http://www.jsoftware.com/pipermail/programming/2008-February/009871.html (scroll past all the spoiler-hiding blank lines). Of course, once he mentioned it, Roger took notice, and immediately plugged the gap.
³ The way I once put it http://www.jsoftware.com/pipermail/programming/2006-December/004287.html was "Yes, dcog is ugly, but I like to think of it as Messiah Code: it's ugly so that other code doesn't have to be. A sponge for sin".
4 Take note, the template gerund foo`bar`baz
can be anything you like, of any length, using any names. It doesn't matter. What does matter is that the names you use are either proverbs or undefined (which the interpreter treats like proverbs, by design). Using pronouns or pro-operators will break stuff. Alternatively, you could use another kind of noun, like simply __
or something (which I find mnemonic for fill in the ____).