I'm writing a small tool in Nim and ran into the compiler error "expression ... has no type (or is ambiguous)".
Here's a simplified example that still gives the error message: https://play.nim-lang.org/#ix=1Z5M
Granted, the cleanedXmi proc has no return type, but usually that's not a problem. Why would I need one here? Or am I misinterpreting the error message? Anyway, I can't figure out why I get this error and how I can fix it. Please help. :-)
Granted, the cleanedXmi proc has no return type, but usually that's not a problem.
Of course that is the problem.
You try to assign to a variable the result of a proc call, but the proc does not return a value. That should be always a compile error. What have you expected?
The compiler complains to you, because the you assign the cleanXmi call to newNode.
Thus cleanXmi has to return a type.
my proc has a return type specified, yet i still get the same error.
Error: expression 'stripLineEnd(returnString)' has no type (or is ambiguous)
#calling code.
var returnString = genImageLink(link, title, imageFilename, altText)
let strippedString = returnString.stripLineEnd
#genImageLink.nimf
#? stdtmpl(subsChar = '$', metaChar = '#')
#proc genImageLink*(link: string, title: string, imageFilename: string, altText: string): string =
# result = ""
<a href="${link}" title="${title}"><img src="${imageFilename}" alt="${altText}" /></a>
If that's stripLineEnd from std/strutils, it operates in-place and doesn't return anything.
Consider using it with dup from std/sugar.
Thank a lot! Yes, it is from strutils. The following code works.
var returnString = genImageLink(link, title, imageFilename, altText)
let strippedString = returnString.dup(strutils.stripLineEnd)
return strippedString