[英]Imported modules not working with macros (anymore)
使用以下pytest文件:(import pytest [mark]) (import pathlib [Path]) (require oreo [with-cwd]) (defn [mark.with-cwd] test-with-cwd [cookies] (let [ cwd ...
[英]Imported modules not working with macros (anymore)
使用以下pytest文件:(import pytest [mark]) (import pathlib [Path]) (require oreo [with-cwd]) (defn [mark.with-cwd] test-with-cwd [cookies] (let [ cwd ...
[英]Valid Hy Code throws an unexpected end of input error?
這是我正在編寫的游戲代碼的一部分。 它抱怨parse error for pattern macro 'if': got unexpected end of input, expected: some(...) ,即使因此是有效的 Hy 代碼。 在 PyPy 上運行 Hy 版本 0.25.0,在 ...
[英]How to convert Numpy special syntax to Hy
我有這個 Python 代碼:import numpy as np import matplotlib.pyplot as plt X = np.random.randn(500, 2) plt.scatter(X[:,0], X[:,1]) 但我不知道如何將X[:,0]和X[:,1]轉換為 ...
[英]How to type-hint in Hy
是否可以用 Hy 語言輸入提示變量和函數返回值?# in python we can do this def some_func() -> str: return "Hello World" ...
[英]How to set two variables at once in Hy
我剛開始學習 Hy(我第一次嘗試 Lisp 方言)。 我有一個返回 2 個值的元組的 function,但我不知道如何接收它: 所以,在 Python 中,它看起來像這樣:def function(): return "Hello", "World" # This is what I have ...
[英]Requiring `hy' macro with `raise' function triggers `raise' on `require'
當試圖在另一個文件中require以下宏時, raise似乎會立即觸發: 這會導致AssertionError: True 。 重現步驟(有時有效,有時無效): ...
[英]Require macros from the same file in another macro
在下面的代碼中,鑒於hy似乎在未明確需要宏的依賴宏時給出NameError ,我如何在另一個宏中需要同一文件中的宏? 在名為oreo oreo.hy文件中,我使用(require oreo.oreo [with-cwd])嘗試了以下方法,但均未奏效: 更新:根據要求,我已將代碼修改為原始問題仍然存在 ...
[英]Non-existent hy macros runs assertions, but fails appropriately with everything else
在以下代碼中: 同樣,任何依賴於缺失宏的函數或宏都會以同樣的方式出錯,例如,如果我正在導入或需要依賴於缺失宏的函數或宏,也會發生同樣的事情; 基本上,我必須手動導入或需要函數或宏及其依賴項。 這是一個錯誤,還是我錯過了關於 Python / Hy 斷言順序的一些東西? 我預計第一個案例也會因N ...
[英]__init__.py for hy modules with relative imports
如何require __init__.py中的hy模塊中的所有函數? 我嘗試使用與hyrule __init__.py中類似的模型,但出現以下錯誤: 這就是我的__init__.py中的內容: import hy hy.macros.require('.oreo', # The Pytho ...
[英]Mimic `let' statement in a macro
在以下目錄結構中: 以下代碼打印了錯誤的路徑: 它應該打印以下內容: 雖然它正在打印: 為什么b在做(quasiquote (let ~vars (with-cwd ~dir ~@body)))時沒有正確分配? ...
[英]Difference between using a for loop to run a body in a macro versus mapping `exec' over the body
在以下代碼中使用(map exec ~body)與(for [node ~body] node)有什么區別? 哪個更安全,或者它們都好嗎? exec()似乎不再運行代碼字符串了,我相信這在Python 3中已經改變了,所以現在可以了嗎? 我只是想使用更簡潔的東西; 我不擅長命名變量。 更新: ...
[英]Show whether a Python module is loaded from bytecode
我正在嘗試調試Hy對字節碼的使用。 特別是,每次導入模塊時,我都想查看它實際導入的路徑,無論是源代碼還是字節碼。 在底層,Hy 使用importlib管理模塊。 它沒有明確地讀取或寫入字節碼; 這由importlib.machinery.SourceFileLoader 。 所以看起來我想要做的是猴 ...
[英]importing module from current folder in hy
Hy 版本 1.0a4+199.g22021c56 中的 import 有變化嗎? 我正在嘗試從同一文件夾(或 cwd)導入文件,但出現 ModuleNotFoundError: No module named 'thenameofthefile' 即使我 append 當前路徑到 sys.pat ...
[英]hy build-in with-decorator throws NameError: name 'with_decorator' is not defined
我正在嘗試運行 hy 手冊 ( https://docs.hylang.org/en/stable/language/api.html?highlight=with-decorator#with-decorator ) 中的 with-deocorator 示例: 但我遇到了一個例外: with ...
[英]Cut from negative integer to last item in list in Hy
如果(list (range 10))是[0... 9] ,並且(cut (list (range 10)) -5 -1)是[5, 6, 7, 8] ,那么我如何包括最后一個列表中的項目,即[5, 6, 7, 8, 9] ? 我試過(cut (list (range 10)) -5 0)和(cut ...
[英]Dynamic bindings with let in Hy?
來自 Common Lisp,我正在嘗試使用 let 來動態隱藏全局變量的值。 有沒有辦法讓這個工作,以便第二次調用 callee 給出 39? [編輯] 根據 gilch 的回復,我使用 contextvars 編寫了以下草稿: 感謝您的回答! ...
[英]Does Hy have inline if?
Python 的a if condition else b的 Hy 等價物是什么? 我正在嘗試轉換這樣的東西return (quicksort(under) if under else []) + same + (quicksort(over) if over else []) 到海伊。 如果 ...
[英]Why is this quicksort overflowing?
我有以下 Hy 代碼: 我從這個 Python function 粗略翻譯:def quicksort(lst: list) -> list: if len(lst) < 2: return lst else: under, same, ...
[英]Convert python literal_eval string to hy
我想將以下內容轉換為 Hy,但我似乎不知道該怎么做; 有沒有辦法將 python 代碼的字符串轉換為 hy 語法? 我不知道py是否可以工作,因為f_back的評估結果可能不安全。import ast, inspect def test(f_back): return ast.litera ...
[英]Render mangled hy attribute names as regular strings
如果我在self.internal/freezer屬性,並且我通過(raise (AttributeError f"Sorry! '{attr}' doesn't exist as an attribute!"))引發錯誤,我該如何獲取要呈現為internal/freezer而不是hyx_inter ...