嵌套显式定义
Nested explicit definitions
为了争论,假设我想要以下程序:
foo =: monad define
bar =. dyad define
x * y
)
bar/ y * 2 3
)
理想情况下,对于输入 3
,这将产生 54
。但是,将其放入控制台时,两个 )
中的第一个被视为第一个 define
的结尾。有什么办法可以防止这种情况发生吗?我想避免使用内联动词,例如 monad def 'x * y'
。我的实际动词示例比这更复杂。
你不能有嵌套的多行定义,因为没有检查定义的内容。定义结束并 保存 在第一次遇到 ^)LF
.
a multiline body is a script terminated by a solo right parenthesis, so we cannot have one such body inside another.
有(混乱的)方法可以解决这个问题,例如通过形成字符串并对其求值:
foo =: monad define
str =. 'x * y'
bar =. 4 : (str,:'')
bar /y * 2 3
)
foo 3
54
也许形成一个辅助副词是个更好的主意。
(编辑) 分别定义bar
的主体的示例:
bar_body =: 0 : 0
c=. x + y
c * y
)
foo =: 3 : 0
bar =. 4 : bar_body
bar/y * 2 3
)
foo 3
135
嵌套的终止符 ')'s 有问题,但这可行
foo =: monad define
bar =. 4 : 'x * y'
bar/ y * 2 3
)
foo 3
54
Multiple lines in bar definition could just be consecutive boxed
strings.
foo =: monad define
bar =. 4 : ('t=.x * y';'t+1') NB. parenthesis required
bar/ y * 2 3
)
foo 3
55
没有嵌套块是一个有意的设计决定。
这个想法是为了给开发者施加压力来命名块。 (而且,更一般地说,开发人员面临着偏爱简洁、简单代码的巨大压力。)
也就是说,副词(和连词)可用于将块连接在一起。
为了争论,假设我想要以下程序:
foo =: monad define
bar =. dyad define
x * y
)
bar/ y * 2 3
)
理想情况下,对于输入 3
,这将产生 54
。但是,将其放入控制台时,两个 )
中的第一个被视为第一个 define
的结尾。有什么办法可以防止这种情况发生吗?我想避免使用内联动词,例如 monad def 'x * y'
。我的实际动词示例比这更复杂。
你不能有嵌套的多行定义,因为没有检查定义的内容。定义结束并 保存 在第一次遇到 ^)LF
.
a multiline body is a script terminated by a solo right parenthesis, so we cannot have one such body inside another.
有(混乱的)方法可以解决这个问题,例如通过形成字符串并对其求值:
foo =: monad define
str =. 'x * y'
bar =. 4 : (str,:'')
bar /y * 2 3
)
foo 3
54
也许形成一个辅助副词是个更好的主意。
(编辑) 分别定义bar
的主体的示例:
bar_body =: 0 : 0
c=. x + y
c * y
)
foo =: 3 : 0
bar =. 4 : bar_body
bar/y * 2 3
)
foo 3
135
嵌套的终止符 ')'s 有问题,但这可行
foo =: monad define
bar =. 4 : 'x * y'
bar/ y * 2 3
)
foo 3
54
Multiple lines in bar definition could just be consecutive boxed strings.
foo =: monad define
bar =. 4 : ('t=.x * y';'t+1') NB. parenthesis required
bar/ y * 2 3
)
foo 3
55
没有嵌套块是一个有意的设计决定。
这个想法是为了给开发者施加压力来命名块。 (而且,更一般地说,开发人员面临着偏爱简洁、简单代码的巨大压力。)
也就是说,副词(和连词)可用于将块连接在一起。