Feel free to ask on IRC then.
The only way to progress fast in Nim is by trying and then asking otherwise you
will lose time. I remember learning like throwing eggs on a wall a see what
sticks (and then raising bug reports for static and generic types).
Now from all your posts, I think the
I did not meant that you attacked me. May be you are right. I am asking
questions in the wrong way. I think i was little Impatient at that time. I
should need to try the trial and error method instead of asking in the forum.
> It's not the first time on this forum that somebody has posted a
Thanks. May it was my problem because, i was little frustrated when i cant find
what i was looking for. I know, i have asked too many queries in different
threads. But actually, the suggestions from others were not satisfied me, but
it was my fault, not their fault. I think its better for me to
> Sorry for disturbing you with my questions. Next time, when i face any
> obstacles in nim coding, i will insist myself to not to ask in this forum.
Please read the wiki article I linked. Not only that you shouldn't react like I
was personally attacking you, but you you should see that the
Asking in the forum is not an issue, but what miran said is that he feels like
you might be trying to solve your issue at a low level while we could solve the
actual bigger problem. (correct me if I'm wrong @miran).
1\. Auto and Any type for input params are usually not needed, using a generic
I don't want to use python because these reasons.
1. I need to use a third party app to make exe from python code. (I think
python is not for windows)
2. Compiled exe is very large. A normal hello world gui app will size around
4-5 MBs.
3. Execution speed.
I will sure consider the
Sorry for disturbing you with my questions. Next time, when i face any
obstacles in nim coding, i will insist myself to not to ask in this forum.
> [XY problem](https://en.wikipedia.org/wiki/XY_problem)
> I just tested it and it worked. Is there any problems using this method ?
Of course you can cast refs or ptrs to int and store it in a seq of ints. But
how do you do the bookkeeping? When you retrieve a value from your list, then
its looks like an int. So how do you decide if it may be a ref
> Three separate seqs with different data types and same name? Obviously makes
> not much sense. Ha ha.. In my sense, it was like ; "Hey compiler, this is
> 'one' seq but the data type is one among three. If the input value is int,
> then treat this seq as a seq[int]. And when the input value
miran I think your explanation is still too short for beginners...
One should know that
proc foo(a: seq[int|float|char])
Run
is basically a short form for definition of three separate procs:
proc foo(a: seq[int)
proc foo(a: seq[float)
proc foo(a:
> This gave me error.
>
> `var mySeq : seq[ int | float | string]`
This cannot be used for declaring a variable, but you can use it for arguments
in a function:
proc foo(a: seq[int|float|char]): string =
return $a[0]
echo foo(@[3, 5, 7])
echo foo(@[3.5, 5.7,
Yes, int | float | string is not a concrete type, it's just to match a
signature at compile time. You can use an object variant
([https://nim-lang.org/docs/tut2.html#object-oriented-programming-object-variants](https://nim-lang.org/docs/tut2.html#object-oriented-programming-object-variants)
)
proc myProc2(a : int | float | string) = discard
Run
Thats a great work around. Thanks for it. One question. This gave me error.
var mySeq : seq[ int | float | string]
Run
Any work around for this ?
This is my requirement. I am writing a combobox class. This class has an item
property. It contains a seq. One wants to insert int or string or float, or
even a window handle too. After a lot of experiments, i decided to make that
seq[string] type and if i convert the input data to string with
Thanks for the reply, but i want to check in runtime, not compile time.
Maybe the following is sufficient:
proc myProc(a : auto) =
when a is int: echo "got an int"
elif a is string: echo "got a string"
elif a is float: echo "got a float"
proc myProc2(a : int | float | string) = discard
myProc(1)
myProc("abc")
It's [typeinfo](https://nim-lang.org/docs/typeinfo.html) not typetraits and
instead of `auto` you'd need to use the `Any` type. I recommend you don't use
this module and simplify your code to not use types at runtime. Do note that if
you want to check at compile time all you need to do is use
If type of `a` is really `int`, `float` or `string` you can write code like
this:
proc myProc1(a: int) =
echo "int: ", a
proc myProc1(a: float) =
echo "float: ", a
proc myProc1(a: string) =
echo "string: ", a
proc myProc(a: auto) =
the module typetraits might be able to help you
Yes.
Do you need to know the type at runtime?
Assume that i have a proc like this
proc myProc( a : auto) =
#need to check what the type of a, I am expecting an int, float, string.
# do some operations
Run
How can i check the type of a ?
23 matches
Mail list logo