I am a beginner - so maybe this makes perfect sense... I found the code at https://forum.nim-lang.org/t/2390 I just added an extra line "import unicode, strutils"...
# import unicode, strutils # remove this comment !
template alias(original, newName: untyped): untyped =
template newName: auto = original
# easier deep referencing
type
MyObj3 = object
data: string
MyObj2 = object
obj3: MyObj3
MyObj1 = object
obj2: MyObj2
var obj1: MyObj1
alias obj1.obj2.obj3.data, data
data = "Test"
assert obj1.obj2.obj3.data == "Test"
# replacing result
import strutils
proc starredWords(curStr: string): string =
alias result, words
words = ""
for s in curStr.split(' '):
alias "*" & s.strip.capitalizeAscii & "* ", starredWord
words &= starredWord
var sw = starredWords("hello I like teapots")
echo sw
# only allow alias template in block scope
template alias(original, newName, actions: untyped): untyped =
block:
template newName: auto = original
actions
var inputStr = "abc"
alias inputStr.toUpperAscii, t:
echo t # t is only defined here
As described in the error message, both strutils and unicode define a strip procedure that matches the call. To fix this your options are:
Specify which version to call, e.g.
strutils.split(curStr,' ')
or don't import one of the strip procedures, e.g.
import strutils
import unicode except strip
Or declare an alias to strutils's strip (or the other way).
import unicode, strutils # remove this comment !
const stripStr = strutils.strip
[...]
alias "*" & s.stripStr.capitalizeAscii & "* ", starredWord
Or declare an alias to strutils's strip (or the other way).
Er, please don't. :-)