Adding "import unicode, strutils" triggers
error:/Volumes/T7/Nim/_my_code_ex/template_alias_reference.nim(28, 18) Error:
ambiguous call; both unicode.strip(s: string, leading: bool, trailing: bool,
runes: openArray[Rune]) [declared in
/Volumes/T5/.choosenim/toolchains/nim-1.4.6/lib/pure/unicode.nim(1049, 6)] and
strutils.strip(s: string, leading: bool, trailing: bool, chars: set[char])
[declared in
/Volumes/T5/.choosenim/toolchains/nim-1.4.6/lib/pure/strutils.nim(2878, 6)]
match for: (string)|
---|---
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
Run