开发者

Wrapping J's Adverse primitive (::)

开发者 https://www.devze.com 2023-02-05 06:47 出处:网络
Usually, I will use the :: primitive thus: SomeVariable\"_ :: ] DefaultValue I\'m looking for a way to wrap that ugly SOB. I\'m trying to reason it. Normally, it would be with a tacit definition. T

Usually, I will use the :: primitive thus:

SomeVariable"_ :: ] DefaultValue

I'm looking for a way to wrap that ugly SOB. I'm trying to reason it. Normally, it would be with a tacit definition. This, for example:

default =: 13 : 'x"_ :: ] y'

fails miserably. Because, of course, in this context:

SomeVar开发者_JS百科iable default DefaultValue

if SomeVariable doesn't exist, J will throw a valence error.

So, how can you wrap ::?


You can indeed wrap :: but if you want to give it a verb argument, you need to deal with the syntactic issues.

For example, you can use an adverb:

fault=:1 :0
  u"_ :: ]
)

Or you could convert the verb you are manipulating into a gerund and pass that in (but that would be ugly, so I do not think you want that).


I use,

ORdef_z_ =: ".@[^:(_1< 4!:0@<@[)

 'asd' ORdef 3  NB. asd not assigned, returns right.
3
 asd =. 'asd' ORdef 3
asd=.'asd' ORdef 22  NB. will return 3 due to previous assignment
asd

3

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号