简体   繁体   English

在J中设置用户定义动词的等级

[英]Setting the rank of a user-defined verb in J

Here's a function to calculate the digital sum of a number in J: 这是一个计算J中数字的数字和的函数:

digitalSum =: +/@:("."0)@":

If I use b. 如果我使用b. to query the rank of this verb, I get _ 1 _ , ie, infinite. 查询此动词的等级,我得到_ 1 _ ,即无穷大。 (We can ignore the dyadic case since digitalSum is not dyadic.) (由于digitalSum不是二进位的,所以我们可以忽略二进位的情况。)

I would like the monadic rank of this verb to be 0, as reported by b. 我希望此动词的单调等级为0,如b. . The only way I know of to do this is to use a "shim", eg, 我唯一知道的方法是使用“垫片”,例如

ds =: +/@:("."0)@":
digitalSum =: ds"0

This works great, but I want to know whether it's the only way to do this, or if there's something else I'm missing. 这很好用,但是我想知道这是否是唯一的方法,或者我是否缺少其他东西。

Clarification 澄清

I just discovered how to change the rank of a verb that's defined thus: 我刚刚发现了如何更改这样定义的动词的等级:

digits =: 3 : 0 "0
    "."0@": y
)

Notice the "0 after the declaring 3 : 0 . You can put any adverb or conjunction you wish, and it will be applied to the verb as a whole. Pretty cool stuff! 请注意,在声明3 : 0 "0之后出现"0您可以放任何希望的副词或连词,它将作为整体应用于动词。非常棒的东西!

digitalSum =: (+/@:("."0)@":)"0 is how I would define it as well. digitalSum =: (+/@:("."0)@":)"0也是我定义它的方式。 Using " to change rank is pretty standard and works on parenthesized tacit trains. 使用"更改等级是相当标准的,并且可以在带括号的默认火车上使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM