Hy 有内联 if 吗?

发布于 2025-01-14 15:18:25 字数 366 浏览 2 评论 0原文

Python 的 a if condition else b 的 Hy 等价物是什么? 我正在尝试将这样的东西转换

return (quicksort(under) if under else []) + same + (quicksort(over) if over else [])

为 Hy。如果列表为空,它会避免调用 quicksort()。我知道我可以

(if under
   (quicksort under)
   [])

,但我宁愿把它写在一行上

What is the Hy equivalent of Python's a if condition else b?
I'm trying to convert something like this

return (quicksort(under) if under else []) + same + (quicksort(over) if over else [])

to Hy. It avoids calling quicksort() if the list is empty. I know I can do

(if under
   (quicksort under)
   [])

but I'd rather have it on one line

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲凉≈ 2025-01-21 15:18:25

Hy 是一种自由形式的语言(与大多数编程语言类似,但与 Python 不同)。您可以像这样在一行中编写 (if under (quicksort under) []) ,这对解析器没有任何影响。

Hy 编译器是否为您的 Hy if 表单生成 Python if 表达式或 Python if 语句应该是您不需要的实现细节不必担心。

Hy is a free-form language (like most programming languages, but unlike Python). You can write (if under (quicksort under) []) in one line, like so, and it makes no difference to the parser.

Whether the Hy compiler produces a Python if expression or a Python if statement for your Hy if form is supposed to be an implementation detail that you don't have to worry about.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文