簡體   English   中英

在線程宏中使用 get

[英]Use get in threading macro

以下三個示例失敗並出現以下錯誤:

(setv dct {1 2 3 4})
(setv dcts "dct")

;; (print (get (. (globals) [dcts]) 1))
(print (-> (globals) (. [dcts]) (get 1)))

;; (print (get (get (globals) "dct") 1))
(print (-> (globals) (get "dct") (get 1)))

;; (print (get (get (globals) dcts) 1))
(print (-> (globals) (get dcts) (get 1)))
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/test.hy", line 5
    (print (-> (globals) (. [dcts]) (get 1)))
                                         ^
hy.errors.HySyntaxError: parse error for pattern macro 'get': got unexpected end of file, expected: some(...)
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/test.hy", line 8
    (print (-> (globals) (get "dct") (get 1)))
                              ^
hy.errors.HySyntaxError: parse error for pattern macro 'get': got unexpected end of file, expected: some(...)
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/test.hy", line 11
    (print (-> (globals) (get dcts) (get 1)))
                              ^
hy.errors.HySyntaxError: parse error for pattern macro 'get': got unexpected end of file, expected: some(...)

線程宏( -> )是否不能使用get或一般的宏? 我已經多次重寫打印語句以確保括號一致,並且它們都在那里。

以下適用於我的 Hy master。 你忘了require嗎?

=> (require hyrule [->])
=> (setv dct {1 2 3 4})
=> (setv dcts "dct")
=> (print (-> (globals) (get dcts) (get 1)))
2
=> (require hyrule [->])

(setv dct {1 2 3 4})
(setv dcts "dct")

;; (print (get (. (globals) [dcts]) 1))
(print (-> (globals) (. [dcts]) (get 1)))

;; (print (get (get (globals) "dct") 1))
(print (-> (globals) (get "dct") (get 1)))

;; (print (get (get (globals) dcts) 1))
(print (-> (globals) (get dcts) (get 1)))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM