我正在玩 APL 做这个问题。
我定义了以下功能:
∇ r ← smallestFactor n
⍝ Find smallest factor of n
r ← (0 = r) + r ← 1 ↑ (0 = r | n) / r ← 1 ↓ ⍳ n
∇
∇ r ← factors n; sf
⍝ List of all prime factos of n, repeated according to their power
r ← ⍳ 0
→ (1 = n) / 0
r ← sf, factors n ÷ sf ← smallestFactor n
∇
∇ r ← c count iter
⍝ Count occurances of c in iter
r ← +/ (c = iter) / 1
∇
现在,当我执行以下操作时,我得到了预期的结果(232792560):
×/ twenty * ⌈/ twenty ∘.count facs ← factors ¨ twenty ← 1 ↓ ⍳ 20
但是,当我省略分配给facs
它时,它会严重失败:
×/ twenty * ⌈/ twenty ∘.count factors ¨ twenty ← 1 ↓ ⍳ 20
==============================================================================
Assertion failed: 0
in Function: init
in file: Cell.cc:47
Call stack:
----------------------------------------
-- Stack trace at Cell.cc:47
----------------------------------------
0x7f713e200ea5 __libc_start_main
0x4314dc main
0x4f34bd Workspace::immediate_execution(bool)
0x4545cd Command::process_line()
0x452f26 Command::process_line(UCS_string&)
0x44030f Bif_OPER2_PRODUCT::eoc_outer_product(Token&, _EOC_arg&)
0x43ffac Bif_OPER2_PRODUCT::finish_outer_product(OUTER_PROD&)
0x44a309 Cell::init(Cell const&)
0x43c2ca do_Assert(char const*, char const*, char const*, int)
========================================
SI stack:
Depth: 0
Exec: 0x9f3310
Pmode: ◊ ×/ twenty * ⌈/ twenty ∘.count factors ¨ twenty ← 1 ↓ ⍳ 20
PC: 12 /
Stat: ×/ twenty * ⌈/ twenty ∘.count factors ¨ twenty ← 1 ↓ ⍳ 20
err_code: 0x0
thrown: at StateIndicator.cc:38
e_msg_1: 'No Error'
e_msg_2: ''
e_msg_3: ''
==============================================================================
*** immediate_execution() caught other exception ***
我正在使用 GNU APL,所以我没有花哨的 dfun。
我实际上看不出这两种说法之间的区别。
这个错误从何而来?