Remove `{.discardable.}`. Don't use that pragma if you don't understand how Nim
works.
> When trying to compile without {.Discardable.} I get an error - van2.nim(49,
> 24) Error: expression 'splitstring(new_string, split_by, accu)' is of type
> 'seq[string ]' and has to be discarded; start of expression here:
> van2.nim(39, 8)
Return values of a function can't be implicitly ignored in Nim without
`{.discardable.}`
> How do I return a copy of the resulting sequence of string?
Nim's sequences use value semantics, so they are always copied, for example
([run on playground](https://play.nim-lang.org/#ix=1P24)):
var
a = @[1, 2, 3, 4]
b = a
b.add 5
echo a # @[1, 2, 3, 4]
echo b # @[1, 2, 3, 4, 5]
Run
> It seems like the function is returning too early - I'm assuming because
> result is being used in the if block?
The function is not returning too early. The problem is that you dropped the
return value of your recursion calls (which you didn't notice thanks to
`{.discardable.}`), so they disappeared.
It's worth noting that `result` is just like any ordinary variable and will
**not** cause any control-flow changes.
Here's my simplification of the function you presented:
[https://play.nim-lang.org/#ix=1P25](https://play.nim-lang.org/#ix=1P25). But
please just use `strutils.split` instead.