News for hackers. Stuff that matters.
Re:What is special about Nim? by RaecKK on Thursday January 01, 2015 @03:17PM (#8824111)
Agreed. When the manual says you can pattern match with term rewriting macros, I think of Erlang pattern matching. Would something like this be possible?

    template mysum{a = @[]}(a: seq[int]): int = 0
    template mysum{a}(a: seq[int]): int =
      while a.low <= a.high:
        a[a.low] + mysum(a[a.low + 1 .. a.high])

    var x: seq[int] = @[1, 2, 3]

    echo mysum(x)
Re:What is special about Nim? by def- on Thursday January 01, 2015 @03:44PM (#8824233)
Term rewriting templates are only supposed to be optimizations, not change the semantics. They happen on the AST, so the pattern matches are on the AST as well. You won't get the actual values of any variables, they aren't even known at compile-time anyway.