let num = 10
const x = 9
echo(num + x)
let num = 10.int
const x = 9
echo(num + x)
let num = 10.uint
const x = 9
echo(num + x)
That seems to be the case because you have to explicitly cast `let` s (or the
compiler assumes a default cast).
> Apparent for numerical constants, when you do this: const modpg = 2310 the
> compiler will convert it to whatever is required to make math operations work
> (at least it did so in my code).
>
> But doing: const modpg = parameter[0] causes it to retain the int casting
> from the proc, which th
What I was trying to get at is how to make the generated constant values behave
like coding specific numerical numbers.
Apparent for numerical constants, when you do this: `const modpg = 2310` the
compiler will convert it to whatever is required to make math operations work
(at least it did so
> Coming from Ruby/Elixir,
Maybe some C exercises would help
Note that modpg.unit and rescnt.uint are not plain casts (reinterpretation of
bit pattern) but type conversions. Type conversions may ensure that the values
are not negative before conversion and raise exceptions otherwise. I don't k
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 modp
Hi woggioni,
the static code block is executed at compiletime inside the vm. you cannot
access the parameters outside the block. It´s out of scope. This is why you get
undecleared identifier. But indeed there should be a meaningful error message
instead of the compiler complain.
this works:
If you want to unpack the tuple you have to declare the resulting variables
first, like this:
proc foo(): (int, int, int) = (1,2,3)
static:
var a,b,c : int
(a,b,c) = foo()
echo a,b,c
what is quite strange is that this does not pass gcc compilat
Hi jzakiya,
you simply can not use brackets within your constant-name. Here is the BNF
which literals are allowed:
[https://nim-lang.org/docs/manual.html#lexical-analysis-numerical-constants](https://nim-lang.org/docs/manual.html#lexical-analysis-numerical-constants)
As long as your tuple have
This should work
import math
proc genPGparameters(prime: int): (int, int, seq[int], int) =
echo("generating parameters for P", prime)
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23]
var modpg = 1
var excluded_primes = 0
for prm in primes:
I do `import math` to get `gcd` in my program, that's why you got that error.
I still can't get the output from `getPGparameters` assigned to constants of
the same names, to be used later in the program. I thought you could do
assignments like:
const (a, b, c) = tuple(x, y, z)
Hi jzakiya, for me I will get: Error: undeclared identifier: 'gcd' (also when
you type the run-button below your code snippet).
>From the tutorial:
>[https://nim-lang.org/docs/tut1.html#constants](https://nim-lang.org/docs/tut1.html#constants)
[https://nim-lang.org/docs/tut1.html#advanced-types
I want to execute the code below at compile time to initialize the global
variables shown - modpg, rescnt, residues, ep.
proc genPGparameters(prime: int): tuple =
echo("generating parameters for P", prime)
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23]
var modpg = 1
13 matches
Mail list logo