Re: Version 0.17.0 released!
> If you do, you may consider put some words into documentation what to do to > achieve similar behaviour because there is quite a lot of people that are > comfortable with that approach. Agreed on documentation. The VTable section of the manual is short, and there's no tutorial. IMO it would make more sense to rework the tutorial part 2 when the feature is ready. It would be interesting to have some numbers on the use of **method**. Can you point to some Nim where the multiple dispatch feature is being used in an essential way? I wrote some 'expression problem' type code to test it but I rarely use dynamic dispatch at all in Nim. Are multimethods widely used, like they are in Julia? You can already simulate single dispatch already without using **method**.
Re: Slow strings
Levenshtein distance, based on my old Pascal source. In some cases, faster than a implementation in strutils module by 10%. (Enj|Destr)oy! import strutils, os import nimbench proc editDistance2*(a, b: string): int = #{.noSideEffect.} = ## Returns the edit distance between `a` and `b`. ## ## This uses the `Levenshtein`:idx: distance algorithm with only a linear ## memory overhead. This implementation is highly optimized! var len1 = a.len var len2 = b.len if len1 > len2: # make `b` the longer string return editDistance(b, a) # strip common prefix: var s = 0 while a[s] == b[s] and a[s] != '\0': inc(s) dec(len1) dec(len2) # strip common suffix: while len1 > 0 and len2 > 0 and a[s+len1-1] == b[s+len2-1]: dec(len1) dec(len2) # trivial cases: if len1 == 0: return len2 if len2 == 0: return len1 # another special case: if len1 == 1: for j in s..s+len2-1: if a[s] == b[j]: return len2 - 1 return len2 inc(len1) inc(len2) var row: seq[int] newSeq(row, len2) for i in 0..len2 - 1: row[i] = i for i in 1 .. len1- 1: var char1 = a[s + i - 1] var prevCost = i - 1; var newCost = i; for j in 1 .. len2 - 1: var char2 = b[s + j - 1] if char1 == char2: newCost = prevCost else: newCost = min(newCost, min(prevCost, row[j])) + 1 prevCost = row[j] row[j] = newCost result = row[len2 - 1] var s1: string = "0123456789" var s2: string = "0123455779" if paramCount() > 1: if fileExists(paramStr(1)): s1 = readFile(paramStr(1)) else: s1 = paramStr(1) if fileExists(paramStr(2)): s2 = readFile(paramStr(2)) else: s2 = paramStr(2) echo "editDistance: ", editDistance(s1, s2) echo "editDistance2: ", editDistance2(s1, s2) bench(editDistance, m): var d = 0 for i in 1..m: d = editDistance(s1, s2) doNotOptimizeAway(d) benchRelative(editDistance2, m): var d = 0 for i in 1..m: d = editDistance2(s1, s2) doNotOptimizeAway(d) runBenchmarks()
Re: Nim Robot the Second
Awesome! I'd love to see an article on how you put all of this together. I can even let you publish it on nim-lang.org if you'd like.
Re: Please , can we stop spams?
**@dataman** there is no "attitude" we just miss new people sometimes (that's a forum issue that needs to be fixed), apologies.
Re: Nim Robot the Second
Thanks, No the white box is just a mini wireless router running openwrt that can act either as a WIFI hotspot or as a wifi client. The computer is a BeagleBone Black on the left side of the robot, and it was developed using this library: [https://github.com/xyz32/boneGPIO](https://github.com/xyz32/boneGPIO)
Re: Nim Robot the Second
Nice! Is the white box the computer? Which one did you use?
Re: Please , can we stop spams?
Almost two days passed, and my first message is still moderated. I have never seen such an attitude to users at any forum.
Re: Version 0.17.0 released!
First of all. Congratulations. > But you're spot on, I hope this feature means we can remove method from the > language. If you do, you may consider put some words into documentation what to do to achieve similar behaviour because there is quite a lot of people that are comfortable with that approach.
Re: Version 0.17.0 released!
> Ahhh damn, I thought you'd go for the first option and add the feature soon me too - normally documentation takes longer than implementation...
Re: Python3 extension help needed
Thanks jlp765! Tried **GC_disableMarkAndSweep()** at the beginning and **GC_enableMarkAndSweep()** at the end of the procedure, still it throws the segmentation fault. Then I tried **GC_disable()** and **GC_enable()** \+ **GC_fullCollect()** and it works!
Re: Python3 extension help needed
Try disabling [MarkAndSweep](https://nim-lang.org/docs/system.html#GC_disableMarkAndSweep) temporarily.