Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequence code on Page 42 unable to compile #14

Open
andrewgohlk opened this issue Aug 6, 2023 · 1 comment
Open

Sequence code on Page 42 unable to compile #14

andrewgohlk opened this issue Aug 6, 2023 · 1 comment

Comments

@andrewgohlk
Copy link

The below sequence code on Page 42 is not able to compile in nim 2.0:

let list = @[4, 8, 15, 16, 23, 42]
for i in 0 .. <list.len:
stdout.write($list[i] & " ")


Encountered the following error:
D:\nimTest\seqTest.nim(2, 15) Error: type mismatch
Expression: <=len(list)
[1] len(list): int

Expected one of (first mismatch at [position]):
[1] proc <=(x, y: bool): bool
[1] proc <=(x, y: char): bool
[1] proc <=(x, y: float): bool
[1] proc <=(x, y: float32): bool
[1] proc <=(x, y: int16): bool
[1] proc <=(x, y: int32): bool
[1] proc <=(x, y: int8): bool
[1] proc <=(x, y: pointer): bool
[1] proc <=(x, y: string): bool
[1] proc <=(x, y: uint): bool
[1] proc <=(x, y: uint16): bool
[1] proc <=(x, y: uint32): bool
[1] proc <=(x, y: uint64): bool
[1] proc <=(x, y: uint8): bool
[1] proc <=[Enum: enum](x, y: Enum): bool
[1] proc <=[T: tuple](x, y: T): bool
[1] proc <=[T](x, y: ref T): bool
[1] proc <=[T](x, y: set[T]): bool
[2] proc <=(x, y: int): bool
[2] proc <=(x, y: int64): bool

========================

However, removing the space after the '..' fix the issue.

let list = @[4, 8, 15, 16, 23, 42]
for i in 0 ..< list.len:
stdout.write($list[i] & " ")

@dlesnoff
Copy link

dlesnoff commented Aug 6, 2023

Before nim 1.4.0 (not sure of the exact version), the operator was .. and < was a template symbol for the substraction by 1.
This is true for all listings in Nim in Action and most of ancient Nim code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants