I'm getting an error that I don't understand when using setCurrentDir.
I try setting the current directory
discard setCurrentDir(newDir: "/path/that/already/exists")
which results in
Error: type expected
As a 2 day user of the language, I'm not sure what to make of that message.
Any hints? Thanks!
I managed to execute processes in particular working directories by calling osproc.startProcess() directly
proc runProcess*(cmd: string; wrkdir: string = ""): string =
var arg: set[ProcessOption]
arg = { poEvalCommand }
let runningProcess = startProcess(command = cmd, workingDir = wrkdir, options = arg)
which, ultimately, gives me more control. But, misses the convenience of nim that I had enjoyed until now. Anyway, onward!I'd love to make this error message better but it's difficult to see how to make it better for someone that's been using Nim for so long.
Let me try to explain this error:
let x: int = 4
The int is a type. In Nim : is usually followed by a type, hence "Error: type expected". Of course, you can also construct types like this:
type
Obj = object
x: int
echo Obj(x: 42)
But you cannot call procedures like this. You use = for that instead.
discard setCurrentDir(newDir="/path/that/already/exists")
or just
discard setCurrentDir("/path/that/already/exists")
If you've got suggestions on how to make the error more clear please do let me know.
If there is no instance where calling a function f with f(a:b) is valid syntax, it would be nice to change the error when is found in the context of the parameters list to a function invocation.
If it is too complicated, or not implementable, a weaker version with a help prompt could also help. Something like:
Error: type expected. (Or maybe you are trying to call a function using named parameters in the form 'param:value' instead of 'param=value'?)
thanks for the response. I had started out with
discard os.setCurrentDir("/path/that/already/exists")
as you suggested. but that returns
Error: expression 'setCurrentDir("/path/that/already/exists")' has no type (or is ambiguous)
in my editor and at compile time.
os.setCurrentDir("/path/that/already/exists") does not return anything, so you don't need to discard it.
import os
os.setCurrentDir("/path/that/already/exists")
ha! that's it! Thanks!
the editor kept underlining the string, so, I didn't look at the discard. sometimes I can't see the forest through the trees. anyway, I'll know better how to interpret that error message! Nim error messages, by the way, have otherwise helped me tremendously to get up to speed on Nim so fast. I really appreciate all the effort that goes into Nim, and hope to contribute myself to that effort.
Don't ya just hate it!? when you bang your head on a problem only to find the answer in a post to YOUR OWN FOUR YEAR OLD [solved] QUESTION !!!
Thanks again, forum, for being here.
Write good comments-- the coder you help may be yourself!
I would add: in any software, try to give precise and detailed error message to the user of the cause of the problem
Since a few hours, my tests don't compile any more and the message I have is Error: type expected, but got: bool. I've tried changing the tests set, expanded manually the macros on a reduced set, etc. It's working with other tests but not this one. I know exactly the line where the problem occurs, but I can't relate it to the error message. And because that's a compilation problem, I can't call expandMacros to help the debugging...
With compiler maximum verbosity, it seems there's a bit of context:
Error: type expected, but got: bool
result = quote do:
^
That's raging...
To solve problems, better give more details than less.