Skip to content

Errors following the guide with latest Nim version #3

@heysokam

Description

@heysokam

This part of the guide doesn't compile with latest version:
devel, haven't tried stable

# Line
var b = cast[ptr TGenericSeq](a)

# Output
Error: expression cannot be cast to TGenericSeq

Not error, but non-matching behavior that makes the guide hard to follow

# Code
var num :int
var p = num.addr
p[] = 30
echo num.addr.repr
echo num

# Output
ptr 30
30

To "fix" this, I wrote:

template reprByte(n :int) :string=
  ## Converts the address representation to its hex ByteAddress instead
  cast[ByteAddress](n.addr).repr

template reprOld(n :int) :string=
  ## Converts the address representation to a format that looks more similar to the old output
  n.addr.repr & " " & n.reprByte

I don't think these two templates fit a simple tutorial.
Just mentioning what I used to get a behavior similar to what the guide shows, so I could reason about the guide content.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions