Macros Masking Common Errors

2022-10-08 Thread kobi
The problem is true, macros do mask errors, or at least where the errors initiated from. What to do about it is unknown, but to dig the head into the sand is not the solution

how to properly init a Table of seq

2022-10-08 Thread ElegantBeef
Yes you can, you need to add it to the table so the result has an address: import std/tables proc `[]`(table: var Table[string, seq[int]], key: string): var seq[int] = discard table.hasKeyOrPut(key, @[]) tables.`[]`(table, key) var a =

how to properly init a Table of seq

2022-10-08 Thread chancyk
@ElegantBeef Is there a way to overload `[]` to provide a default if the key doesn't exist? Something like: proc `[]`(table: var Table[string, seq[int]], key: string): var seq[int] = if table.hasKey(key): result = table[key] else: result =

how to properly init a Table of seq

2022-10-08 Thread ElegantBeef
Yes you need to put the value in the table before operating on it. `table[key][i] =` is not equal to `table[key] = @[]`. In the first case there is no sequence to index on, since there is no entry for the key. The following is a slightly more elegant method of doing this. if

how to properly init a Table of seq

2022-10-08 Thread tcheran
Hello, I wish to use a Table of seq[int] to store values associated to some keys across different .txt files. I learn how many files I need to scan at runtime, so I was thinking to declare the size of seq of each table entry with: newSeqUninitialized[int](n) Run

Macros Masking Common Errors

2022-10-08 Thread chancyk
@araq Sorry, I guess it's just a template that overloads `/` as defined below: template genOp(op: untyped) = proc op*[T](a: T, b: GVec4[T]): GVec4[T] = gvec4[T]( op(a, b[0]), op(a, b[1]), op(a, b[2]), op(a, b[3]) )

Macros Masking Common Errors

2022-10-08 Thread planetis
I don't see any problem related to macros either. What you can do is import `std/lenientops`, or just `(t2 - t1).inNanoseconds.float / 1_000.0`.

Macros Masking Common Errors

2022-10-08 Thread Araq
Yeah, well I have no experience with `vmath` and nothing you wrote has anything to do with "macros".

Macros Masking Common Errors

2022-10-08 Thread chancyk
There's often macros in packages that affect common things like the division operator or dot operator, and they will completely the had the actual error. I've found this to be a common and tricky problem to deal with as a beginner. I wonder if in the case of base types such as int32, int64,

How to declare a varible in a case statement for use afterwrads

2022-10-08 Thread auxym
You might like this blog post with other similar patterns:

How to declare a varible in a case statement for use afterwrads

2022-10-08 Thread xigoi
Mutability should be restricted as much as possible, to make it easier to reason about code. C++ programmers like to talk about “const-correctness”, but C++ makes it very difficult to restrict mutability.

Fidgetty Widget System: Rewrite

2022-10-08 Thread catswhiskers
Just in case you weren't aware: Using the mouse scroll wheel to scroll as in fake examples in choosenim, moves only miniscule amounts on each turn of the wheel. So much so the scroll "button/bead/bar" has to be the preferred option.

How to declare a varible in a case statement for use afterwrads

2022-10-08 Thread Araq
> The language is a tool. No, tools disappear once the house has been built. A language really is building material. Connecting wood with stone is harder than putting stone on top of stone.

How to declare a varible in a case statement for use afterwrads

2022-10-08 Thread kobi
defecting, hehe. The loyalty value used to bother me too. It is silly, actually. The language is a tool. Just like when a problem needs a screwdriver instead of a hammer, don't feel guilty for being disloyal to the hammer. btw, what is wrong with using a top level `var`? (declaring a var before

How to declare a varible in a case statement for use afterwrads

2022-10-08 Thread cblake
There are a few constructs just like that where analogy making from the constraints of other programming languages fail you. A similar example is try-except expressions. I.e., this works: import tables var t: Table[int, int] let x = try: t[0] except: 1 Run

How to declare a varible in a case statement for use afterwrads

2022-10-08 Thread halloleo
Very cool! So elegant! Now where you said it, it feels so obvious...

It is possible to use object field in proc pragma?

2022-10-08 Thread ASVI
I can write like this template myPragma(name: string, body: untyped): untyped= echo "registered name: ", name type Person = ref object name: string proc test(self: Person) {.myPragma("John").} = echo "hi" Run but something like

Selecting/installing older nim package on FreeBSD

2022-10-08 Thread nealie
In the past I've been able to use ports-mgmt/portdowngrade to downgrade ports to older versions. I haven't used this in a while, so I don't know if it still works since the move to git, but it might be worth a go. Failing that, you could just patch the lang/nim port to use the previous

Selecting/installing older nim package on FreeBSD

2022-10-08 Thread Araq
Actually you have to use the `koch` tool to do it...