"Ran into a RPAREN where it wasn't expected" 使用“->>”时

"Ran into a RPAREN where it wasn't expected" when using "->>"

我有以下代码:

(require [hyrule [-> ->>]])

(defn static/freezer [value freezer]
                      (cond [(not value) (setv freezer [])]
                            [(isinstance value list)
                             (do (if (not (isinstance freezer list)) (setv freezer []))
                                 (.extend freezer value)
                                 (setv freezer (->> (lfor i
                                                          (lfor j freezer :if j j)
                                                          (if (isinstance i list) i [i]))
                                                    (list)
                                                    (chain #*))))]
                            [True (raise (TypeError f"Sorry! The 'm/freezer' can only accept lists or non-truthy values!"))])
  (return freezer))

(print (static/freezer [[1 2] [3 4] 5))

...但出现以下错误:

Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 267, in run_path
    code, fname = _get_code_from_file(run_name, path_name)
  File "/home/shadowrylander/bakery/test.hy", line 12
    (chain #*))))]
             ^
hy.lex.exceptions.LexException: Ran into a RPAREN where it wasn't expected.

我假设 ->> 宏没有生效,因为每个括号都检查过了,但 eval-when-compileeval-after-compile 都没有帮助。

如错误消息所示,(chain #*) 在词法上不合法。 #*#** 后面必须跟一个表格。基本思想是 #*#**,就像 (" 一样,它们本身不是形式,而是可以与其他一些字符一起使用来构造形式的字符,即 (unpack-iterable …)(unpack-mapping …)#1730讨论了一些相关问题。无论如何,词法分析发生在任何宏展开之前,因此 ->> 无法解决这个问题。