只是想添加到乔丹的答案:如果你没有打开盒子显示,你可以用这种方式明确地格式化东西5!:2
f =. <.@-:@#{/:~
5!:2 < 'f'
┌───────────────┬─┬──────┐
│┌─────────┬─┬─┐│{│┌──┬─┐│
││┌──┬─┬──┐│@│#││ ││/:│~││
│││<.│@│-:││ │ ││ │└──┴─┘│
││└──┴─┴──┘│ │ ││ │ │
│└─────────┴─┴─┘│ │ │
└───────────────┴─┴──────┘
还有一个树显示:
5!:4 <'f'
┌─ <.
┌─ @ ─┴─ -:
┌─ @ ─┴─ #
──┼─ {
└─ ~ ─── /:
参见词汇页面5!: Representation和9!: Global Parameters以更改默认值。
此外,对于它的价值,我自己阅读 J 的方法是手动重新输入表达式,从右到左构建它,并在我去的时候查找碎片,并在需要时使用恒等函数形成临时火车至。
例如:
/:~ i.5
0 1 2 3 4
NB. That didn't tell me anything
/:~ 'hello'
ehllo
NB. Okay, so it sorts. Let's try it as a train:
[ { /:~ 'hello'
┌─────┐
│ehllo│
└─────┘
NB. Whoops. I meant a train:
([ { /:~) 'hello'
|domain error
| ([{/:~)'hello'
NB. Not helpful, but the dictionary says
NB. "{" ("From") wants a number on the left.
(0: { /:~) 'hello'
e
(1: { /:~) 'hello'
h
NB. Okay, it's selecting an item from the sorted list.
NB. So f is taking the ( <. @ -: @ # )th item, whatever that means...
<. -: # 'hello'
2
NB. ??!?....No idea. Let's look up the words in the dictionary.
NB. Okay, so it's the floor (<.) of half (-:) the length (#)
NB. So the whole phrase selects an item halfway through the list.
NB. Let's test to make sure.
f 'radar' NB. should return 'd'
d
NB. Yay!
附录:
NB. just to be clear:
f 'drara' NB. should also return 'd' because it sorts first
d