给定一个动量,如何计算f1(f2(... fn(x)...))?

问题描述 投票:2回答:1

一个人可以将f1(f2(f3(x)))计算为

*: +: >: 4                 NB. 100

给出“未知”长度的格伦德(例如m1 =: *:`+:`>:m2 =: +:`>:),如何计算f1(f2(...(fn(x)) ...))

到目前为止,我只能使用evoke来将Gerund m `: 0

(*:`+:`>: `: 0) 4         NB. 16 8 5
j
1个回答
0
投票

此解决方案不是很好,但是可以。

[首先使用外来连接定义(5!:0)副词和原子表示(5!:1)将gerund转换为字符串形式,然后使用Raze(;)取消装箱。

然后使用默认格式(":)将y参数转换为字符串,并在空格前加上空格以为gerund字符串留出空格。

使用追加(,)创建一个字符串,并将Do(".)应用于该字符串以得到结果。

g=: 4 : 0
s=: ; (5!:1 <'t'[t=.x) 5!:0  NB. changes gerunds to string
a=:' ' , ": y                NB. makes argument into a string prefixed by blank
". s,a
)

或一行

g1=: 4 : ' ". (; (5!:1 <''t''[t=.x) 5!:0 ), '' '' , ": y'

   *:` +:` >: g 4
100
   *:` +:` >: g1 4
100
© www.soinside.com 2019 - 2024. All rights reserved.