cost 336 ms
導入的模塊不能使用宏(不再)

[英]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 ...

2023-01-07 01:15:30   1   36    pytest / hy  
有效的 Hy 代碼拋出意外的輸入錯誤結束?

[英]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,在 ...

2022-12-28 04:42:41   1   9    hy  
如何將 Numpy 特殊語法轉換為 Hy

[英]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]轉換為 ...

如何在 Hy 中輸入提示

[英]How to type-hint in Hy

是否可以用 Hy 語言輸入提示變量和函數返回值?# in python we can do this def some_func() -> str: return "Hello World" ...

如何在 Hy 中一次設置兩個變量

[英]How to set two variables at once in Hy

我剛開始學習 Hy(我第一次嘗試 Lisp 方言)。 我有一個返回 2 個值的元組的 function,但我不知道如何接收它: 所以,在 Python 中,它看起來像這樣:def function(): return "Hello", "World" # This is what I have ...

2022-08-14 02:00:14   1   25    python / hy  
在另一個宏中需要來自同一文件的宏

[英]Require macros from the same file in another macro

在下面的代碼中,鑒於hy似乎在未明確需要宏的依賴宏時給出NameError ,我如何在另一個宏中需要同一文件中的宏? 在名為oreo oreo.hy文件中,我使用(require oreo.oreo [with-cwd])嘗試了以下方法,但均未奏效: 更新:根據要求,我已將代碼修改為原始問題仍然存在 ...

2022-07-22 17:44:20   1   46    hy  
不存在的 hy 宏運行斷言,但其他一切都失敗了

[英]Non-existent hy macros runs assertions, but fails appropriately with everything else

在以下代碼中: 同樣,任何依賴於缺失宏的函數或宏都會以同樣的方式出錯,例如,如果我正在導入或需要依賴於缺失宏的函數或宏,也會發生同樣的事情; 基本上,我必須手動導入或需要函數或宏及其依賴項。 這是一個錯誤,還是我錯過了關於 Python / Hy 斷言順序的一些東西? 我預計第一個案例也會因N ...

2022-07-20 03:17:54   1   24    hy  
__init__.py 用於具有相對導入的 hy 模塊

[英]__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 ...

2022-07-19 03:05:49   1   22    hy  
在宏中模擬“let”語句

[英]Mimic `let' statement in a macro

在以下目錄結構中: 以下代碼打印了錯誤的路徑: 它應該打印以下內容: 雖然它正在打印: 為什么b在做(quasiquote (let ~vars (with-cwd ~dir ~@body)))時沒有正確分配? ...

2022-07-18 07:07:13   1   20    hy  
使用 for 循環在宏中運行主體與在主體上映射 `exec' 之間的區別

[英]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中已經改變了,所以現在可以了嗎? 我只是想使用更簡潔的東西; 我不擅長命名變量。 更新: ...

2022-07-18 04:46:39   1   24    hy  
顯示是否從字節碼加載 Python 模塊

[英]Show whether a Python module is loaded from bytecode

我正在嘗試調試Hy對字節碼的使用。 特別是,每次導入模塊時,我都想查看它實際導入的路徑,無論是源代碼還是字節碼。 在底層,Hy 使用importlib管理模塊。 它沒有明確地讀取或寫入字節碼; 這由importlib.machinery.SourceFileLoader 。 所以看起來我想要做的是猴 ...

從 hy 中的當前文件夾導入模塊

[英]importing module from current folder in hy

Hy 版本 1.0a4+199.g22021c56 中的 import 有變化嗎? 我正在嘗試從同一文件夾(或 cwd)導入文件,但出現 ModuleNotFoundError: No module named 'thenameofthefile' 即使我 append 當前路徑到 sys.pat ...

2022-05-20 08:35:31   1   45    hy  
從負值 integer 剪切到 Hy 列表中的最后一項

[英]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 ...

2022-04-28 18:58:03   1   35    hy  
在 Hy 中使用 let 進行動態綁定?

[英]Dynamic bindings with let in Hy?

來自 Common Lisp,我正在嘗試使用 let 來動態隱藏全局變量的值。 有沒有辦法讓這個工作,以便第二次調用 callee 給出 39? [編輯] 根據 gilch 的回復,我使用 contextvars 編寫了以下草稿: 感謝您的回答! ...

2022-03-25 13:09:43   2   94    hy  
Hy 有 inline if 嗎?

[英]Does Hy have inline if?

Python 的a if condition else b的 Hy 等價物是什么? 我正在嘗試轉換這樣的東西return (quicksort(under) if under else []) + same + (quicksort(over) if over else []) 到海伊。 如果 ...

將 python literal_eval 字符串轉換為 hy

[英]Convert python literal_eval string to hy

我想將以下內容轉換為 Hy,但我似乎不知道該怎么做; 有沒有辦法將 python 代碼的字符串轉換為 hy 語法? 我不知道py是否可以工作,因為f_back的評估結果可能不安全。import ast, inspect def test(f_back): return ast.litera ...

2022-02-16 02:50:24   1   40    hy  
將損壞的 hy 屬性名稱呈現為常規字符串

[英]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 ...

2022-01-19 21:06:42   1   16    hy  

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