gpt4 book ai didi

bitwise-operators - 在 Nimrod 中,按位运算的语法是什么?

转载 作者:行者123 更新时间:2023-12-04 14:45:55 26 4
gpt4 key购买 nike

我刚刚发现 Nimrod 并且有一个基本问题(在文档中找不到答案)。

你如何使用按位运算?我有以下代码,其中 x 定义为 int :

if x and 1:

这不编译:
Error: type mismatch: got (range 0..1(int)) but expected 'bool'

如果我尝试:
if and(x, 1)

我得到
Error: type mismatch: got (tuple[int, int])
but expected one of:
system.and(x: int16, y: int16): int16
system.and(x: int64, y: int64): int64
system.and(x: int32, y: int32): int32
system.and(x: int, y: int): int
system.and(x: bool, y: bool): bool
system.and(x: int8, y: int8): int8

有什么诀窍?

最佳答案

and按位和;问题在于 if期待 bool ,不是整数。如果您想与 0 进行类似 C 的比较,只需添加它:

>>> if 1:
... echo("hello")
...
stdin(10, 4) Error: type mismatch: got (int literal(1)) but expected 'bool'
>>> if 1!=0:
... echo("hello")
...
hello

关于bitwise-operators - 在 Nimrod 中,按位运算的语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19731492/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com