Hey thanks for the help!

Here's what I had to do to get it to compile/work fully (using Nim 0.17.2).
    
    
    proc genPGparameters(prime: int): (int, int, int, seq[int]) =
        echo("generating parameters for P", prime)
        let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23]
        var modpg = 1;  var excluded_primescnt = 0
        for prm in primes:
          excluded_primescnt += 1; modpg *= prm; if prm == prime: break
        
        var pc = 3; var residues = @[1]
        while pc < modpg:
          if gcd(modpg, pc) == 1: residues.add(pc)
          pc += 2
        residues.add(modpg + 1)
        let rescnt = residues.len-1
        result = (modpg, rescnt, excluded_primescnt, residues)
    
    const parameters = genPGparameters(11)
    
    const
      modpg    = parameters[0]
      rescnt   = parameters[1]
      ep       = parameters[2]
      residues = parameters[3]
    

The only quirks I had to deal with after the parameters were generated/assigned 
was I had to recast in the code some places where I used `modpg` and `rescnt` 
to do math. The compiler told me where the casting incompatibilities were, and 
I just had to use `modpg.unit` and `rescnt.uint` in a few places.

The full compiled code is about 5KB larger than the one with explicitly coded 
values, buts runs with the same speed. This now will allow me to use any 
Strictly Prime (SP) Prime Generator (PG) without having to create a specific 
version for them separately. Now I can just change the prime value for 
`genPGparameters` and, voila, its done.

The only other question I have is why does the compiler treat differently in 
the code when `modpg/rescnt` are assigned specific numerical values versus from 
the compiletime generated ones?

I would highly recommend putting this kind of example in the `Docs/Nim 
Cookbook`. Coming from Ruby/Elixir, this kind of thing is done all the time.

Reply via email to