Search code examples
nim-lang

Nim is to assign variable in or beside other expression once


How Nim's way assign variable in or beside other expression at once, the one that'd always led to:

 Error: expression 's = "foo"' has no type (or is ambiguous)

when trying like c/c++ code if (s = "foo").len > 5 { cout<< "Yes" ;} or some else?
the point was that, how to have variable assignment in some expressions at once,


Solution

  • if (let s = "foo"; s).len > 5:
      echo "Yes"
    

    or

    var s: string
    if (s = "foo"; s).len > 5:
      echo "Yes"