1

我不清楚outer提供给的功能walk应该如何工作。

此处引用的文档中的示例: https ://docs.hylang.org/en/stable/contrib/walk.html

建议该outer函数可以first返回通过映射生成的集合的第一个元素 with inner

但是,当我尝试在outer(例如sumfirst)中汇总结果时,我收到如下错误-抱怨int不可迭代-查看源代码我怀疑这是因为(type form)在宏定义中:

((type form) (outer (HyExpression (map inner form))))

任何人都可以确认并建议是否有办法outer将不同的类型返回到输入form?即可以按照我(walk inc sum [1 2 3 4 5])的期望提供列表的总和吗?[2 3 4 5 6]

=> (walk inc identity [1 2 3 4 5])
[2, 3, 4, 5, 6]
=> (walk inc accumulate [1 2 3 4 5])
[2, 5, 9, 14, 20]
=> (walk inc sum [1 2 3 4 5])
Traceback (most recent call last):
  File "stdin-75eb4a20707c49e8c921e986e7d6164d36b7e4b2", line 1, in <module>
    (walk inc sum [1 2 3 4 5])
  File "/home/phil/.local/lib/python3.6/site-packages/hy/contrib/walk.hy", line 22, in walk
    ((type form) (outer (HyExpression (map inner form))))]
TypeError: 'int' object is not iterable
=> (walk inc first [1 2 3 4 5])
Traceback (most recent call last):
  File "stdin-710dcc990bf071fe1a9a4c5501831c41867f1879", line 1, in <module>
    (walk inc first [1 2 3 4 5])
  File "/home/phil/.local/lib/python3.6/site-packages/hy/contrib/walk.hy", line 22, in walk
    ((type form) (outer (HyExpression (map inner form))))]
TypeError: 'int' object is not iterable
=> 
4

1 回答 1

2

这是一个错误。不如说(sum (map inc [1 2 3 4 5]))

于 2019-12-21T14:48:08.603 回答