Hi,
I'm running into problems trying to use the machine learning package "decisiontree" (Decision tree and Random forest). I did "nimble install decisiontree", which reported finding it: "https://github.com/Michedev/DecisionTreeNim using git", and now it's in my .nimble/pkgs2 directory as DecisionTree-0.1.1-05f79a0c67b8daead4eec38d615ab89f9b8da07d. But when I try "import DecisionTree", I get these error messages:
Hint: used config file '/home/dave/lang/nim/nim-2.2.4/config/nim.cfg' [Conf]
Hint: used config file '/home/dave/lang/nim/nim-2.2.4/config/config.nims' [Conf]
..............................................................................................................................................
/home/dave/.nimble/pkgs2/DecisionTree-0.1.1-05f79a0c67b8daead4eec38d615ab89f9b8da07d/train/split.nim(87, 22) template/generic instantiation of `:=` from here
/home/dave/.nimble/pkgs2/DecisionTree-0.1.1-05f79a0c67b8daead4eec38d615ab89f9b8da07d/utils.nim(26, 5) Error: undeclared identifier: 'shallowCopy'
candidates (edit distance, scope distance); see '--spellSuggest':
(6, 7): 'alloc'
(6, 7): 'alloc0'
(6, 7): 'allocImpl'
The offending line is in train/split.nim:
split_i1 := i1
This is my first encounter with the so-called "Walrus operator". It looks like the gitbug page for this package hasn't been updated for several years, so perhaps it isn't up to date with recent changes in nim regarding "Walrus". My compute environment is:
Linux hpz2ext 5.15.0-139-generic #149~20.04.1-Ubuntu SMP Wed Apr 16 08:29:56 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
I will try to figure out how to patch my DecisionTree installation to get it working, but meanwhile, any ideas on why it's failing?
Thanks.
The walrus here is a custom operator which expands to shallowCopy, which I believe was removed from the language during the transition to ARC/ORC.
Here's an issue I opened some years ago when encountering the same problem myself in a different library: https://github.com/jangko/nimPNG/issues/73
You can see the solutions the author ended up using in their commit here: https://github.com/jangko/nimPNG/commit/2dccf3e19ceb3fdf3f3f415e717d9d336d473a19
Basically to fix the DecisionTree library you should find all y = shallowCopy(x) (or y := x in this case), and replace with y = x (or y = move(x) - usually you don't have have to write move explicitly because the compiler is smart enough to insert it for you). BUT you must also make sure x is labelled as a sink parameter where relevant, or else you might get a performance hit.
To make sense of all this you need to be familiar with how Nim 2 destructors / move semantics work. Here's the relevant part of the manual: https://nim-lang.org/docs/destructors.html#move-semantics