[英]A way to use conjunctions and adverbs tacitly?
Here's a naive Fibonacci sequence: 这是一个天真的斐波那契序列:
(,[:+/_2&{.)^:10]0 1 NB. 10 + 2 elements
0 1 1 2 3 5 8 13 21 34 55 89
And here's its explicit monadic version: 这是明确的monadic版本:
3 :'(,[:+/_2&{.)^:y 0 1' 10
0 1 1 2 3 5 8 13 21 34 55 89
The questions is: in tacit definition, can I somehow supply rightmost argument to ^:
conjunction, so as (off top of my head): 问题是:在默认定义中,我可以以某种方式为
^:
连接提供最右边的参数,以及(在我的头顶):
((,[:+/_2&{.)^:y 0 1)10
0 1 1 2 3 5 8 13 21 34 55 89
Will yield the expected result? 会产生预期的结果吗? Or, more correct definition (again, off top of my head):
或者,更正确的定义(再次,我的头脑):
((,[:+/_2&{.)^:(y-2)1 1)10
1 1 2 3 5 8 13 21 34 55
More generally: is it possible to tacitly define adverbs and conjunctions in J, or is it possible only with explicit definitions? 更一般地说:是否有可能在J中默认定义副词和连词,或者只有明确的定义才有可能?
My gut (and material from this question) tells me that I should go to the dark side and learn more about gerunds and `
/ `:
conjunctions. 我的直觉(和这个问题的材料)告诉我,我应该走向黑暗的一面,了解更多关于动名词和
`
/ `:
连词。 Is that correct? 那是对的吗? If so, I would appreciate any newbie-friendly material on this matter :)
如果是这样,我会很感激任何有关这件事的新手友好材料:)
I think that my natural approach would be to create a dyadic verb where the left argument is the number of iterations and the right argument is the initial string. 我认为我的自然方法是创建一个二元动词,其中左参数是迭代次数,右参数是初始字符串。 This allows me to extend the string easily.
这允许我轻松扩展字符串。
fib0=: (,[:+/_2&{.)@]^:[
10 fib0 0 1
0 1 1 2 3 5 8 13 21 34 55 89
11 fib0 0 1
0 1 1 2 3 5 8 13 21 34 55 89 144
I can create a verb monadically by filling in the (,[:+/_2&{.)
as the left argument to ^:
and 10
as the left argument. 我可以通过填充
(,[:+/_2&{.)
作为左参数^:
和10
作为左参数来单独创建一个动词。 Not too flexible in extending the string though. 虽然扩展字符串不太灵活。
fib1=: (,[:+/_2&{.)^: 10
fib1 0 1
0 1 1 2 3 5 8 13 21 34 55 89
And I end up faking the result that you may be looking for by attaching 0 1
in the definition and creating a monadic verb looking for the number of iterations. 我最后通过在定义中附加
0 1
并创建一个查找迭代次数的monadic动词来伪造您可能正在寻找的结果。
fib2=: ((,[:+/_2&{.)@](^: [))& 0 1
fib2 10
0 1 1 2 3 5 8 13 21 34 55 89
fib2 11
0 1 1 2 3 5 8 13 21 34 55 89 144
But you wanted to know if there was a way to do this using adverbs tacitly. 但你想知道是否有办法默认使用副词。 Taking what I have shown above you can create an adverb from the conjunction
^:
by adding the verb (,[:+/_2&{.)
to the left. 根据我上面显示的内容,你可以从连词
^:
创建一个副词^:
通过在左边添加动词(,[:+/_2&{.)
。
afib=: (,[:+/_2&{.) ^:
(10 afib) NB. an adverb takes its left argument creating a conjunction.
(, ([: +/ _2&{.))^:10
(10 afib) 0 1
0 1 1 2 3 5 8 13 21 34 55 89
(11 afib) 0 1
0 1 1 2 3 5 8 13 21 34 55 89 144
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.