> Nim's small community there are not enough publicly available libraries to 
> use as a reference.

This seems wrong to me. Some reasons below:

##### Available libraries

First, there are many algorithms and snippets in [Rosetta 
Code](https://rosettacode.org/wiki/Category:Nim). We do have many libraries on 
[Github](https://github.com/search?q=language%3ANim+stars%3A%3E100&type=repositories&ref=advsearch&s=stars&o=desc)
 and on other hosting services (see e.g. 
[icedquinn/icedgmath](https://git.sr.ht/~icedquinn/icedgmath/tree/trunk) ).

##### Experiments with ChatGPT

Not enough to train? Just a few posts down, there has been some experiments 
with [ChatGPT](https://forum.nim-lang.org/t/10013). It has trained on quite a 
lot of old obsolete code like those on Rosetta Code that should be updated.

##### AI in personal use

I personally use [Github Copilot](https://github.com/features/copilot) which is 
great for:

  * writing basic tests fast
  * runnableExamples
  * basic comments
  * pedagogical source code / learning material for university



@Yardanico wrote me a trie implementation for a syntax checker in ~3 minutes 
thanks to GHC. He corrected many of the GHC proposals but here it is:
    
    
    import std/[strutils, options]
    
    const
      Letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    
    type
      TrieNode = ref object
        isWord: bool
        s: array[52, TrieNode]
    
    proc add(t: var TrieNode, w: string, i = 0): TrieNode =
      if t == nil:
        t = TrieNode()
      if i == len(w):
        t.isWord = true
      else:
        t.s[Letters.find(w[i])] = add(t.s[Letters.find(w[i])], w, i + 1)
      result = t
    
    proc buildTrie(s: seq[string]): TrieNode =
      for word in s:
        result = result.add(word)
    
    proc search(t: TrieNode, dist: int, w: string, i = 0): Option[string] =
      if i == w.len:
        if t != nil and t.isWord and dist == 0:
          return some("")
        else:
          return
      if t == nil:
        return
      var f = t.s[Letters.find(w[i])].search(dist, w, i + 1)
      if f.isSome:
        return some(w[i] & f.get())
      if dist == 0:
        return
      for j in 0 ..< 52:
        f = t.s[j].search(dist - 1, w, i)
        if f.isSome:
          return some(Letters[j] & f.get())
        f = t.s[j].search(dist - 1, w, i + 1)
        if f.isSome:
          return some(Letters[j] & f.get())
      t.search(dist - 1, w, i + 1)
    
    proc spellCheck(t: TrieNode, word: string): string =
      assert t != nil
      var dist = 0
      while true:
        let res = t.search(dist, word)
        if res.isSome:
          return res.get()
        inc dist
    
    when isMainModule:
      let t = buildTrie(@["hello", "world", "hell", "word", "definitive", 
"definition"])
      
      # echo t.spellCheck("hel")
      echo t.spellCheck("def")
    
    
    Run

If we update old Rosetta Code (~ 1000 pages) to Nim 2.0 and develop 
[<https://github.com/TheAlgorithms/Nim>] this will improve A.I. tooling even 
more.

Reply via email to