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

Fab*_*ien 6 bitwise-operators nimrod nim-lang

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

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

if x and 1:
Run Code Online (Sandbox Code Playgroud)

这不编译:

Error: type mismatch: got (range 0..1(int)) but expected 'bool'
Run Code Online (Sandbox Code Playgroud)

如果我尝试:

if and(x, 1)
Run Code Online (Sandbox Code Playgroud)

我明白了

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
Run Code Online (Sandbox Code Playgroud)

有什么诀窍?

Yan*_*ier 7

and按位; 问题是if期望a bool,而不是整数.如果你想要C类比较为0,只需添加它:

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