How to access command line parameters under the JS backend

2021-02-16 Thread ElegantBeef
You could checkout [Nodejs Nim](https://github.com/juancarlospaco/nodejs) which may have what you need, have not checked myself though.

How to access command line parameters under the JS backend

2021-02-16 Thread halloleo
I want to target nodejs for a little command line tool (which accompanies other JS stuff). Is there any way to read the command line parameters under the JS backend? I tried the standard `paramCount()` and `paramStr()` from the `os` module, but get a run time exception "paramCount is not implem

Defects and CatchableErrors

2021-02-16 Thread halloleo
> They're catchable, but you're not supposed to catch them without a really > good reason. Interesting! Does this mean - to stay with `DivByZeroDefect` \- that I should always test for the denominator to be not zero _[before](https://forum.nim-lang.org/postActivity.xml#before) I do the division

hotcodereloading and libfswatch

2021-02-16 Thread mikebelanger
update: the plot thickens. Sometimes, after a few saves, I get this: mymain(18971,0x7fff8a098380) malloc: *** error for object 0x7fc000c7bb50: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Run Some googling of the above

Composing templates / macros?

2021-02-16 Thread Hlaaftana
In the original example, `{.inject.}` works. import macros template op1(): untyped = a + b template op2(): untyped = a - b macro run(op: string) = var opNode = if op.strVal == "plus": getAst(op1()) else:

Composing templates / macros?

2021-02-16 Thread geekrelief
ok, duh.. I just need to pass in those parameters. macro setterAssign(classNameIdent, nimPtr, propNameIdent, setterNameIdent, nimVal) = if setterNameIdent.repr != "NIM": quote do: cast[`classNameIdent`](`nimPtr`).`propNameIdent` = `nimVal` else:

Composing templates / macros?

2021-02-16 Thread geekrelief
I thought I could make `setter` a macro like: macro setterAssign(classNameIdent, propNameIdent, setterNameIdent) = if setterNameIdent.repr != "NIM": quote do: cast[`classNameIdent`](nimPtr).`propNameIdent` = nimVal else: quote do: cast[

Composing templates / macros?

2021-02-16 Thread geekrelief
Btw, thanks for taking a stab at this. I've been trying to avoid rewriting the template as a macro if I can.

Composing templates / macros?

2021-02-16 Thread geekrelief
In your example, the templates are instanced in a proc with the identifiers, but what if the proc MyFunc is inside a template or macro? Which is what my example code above is trying to do. To give more context, I'm using godot-nim which has a macro that generates a binding to the godot engine.

Composing templates / macros?

2021-02-16 Thread shirleyquirk
it's unclear to me what you're trying to do here, i appreciate your work in simplifying but maybe you went a bit too simple. here's my initial interpretation of what you're doing: template op1() = a + b template op2() = a - b proc MyFunc[op: static string](a,b:int):int =

Composing templates / macros?

2021-02-16 Thread geekrelief
I have a template that defines a proc, and I'd like to be able to modify the contents of the proc depending on parameters passed. I'm trying to do something like: import macros template op1():untyped = a + b template op2():untyped = a - b macr

AsyncSocket timeout

2021-02-16 Thread benob
Good to know.

.mjs import behaviour in node.js

2021-02-16 Thread jan0sc
I have some nim code with embedded js like this: const myJsCode = """ import fs from 'fs' // ... """ {.emit:myJsCode.} import tables # ... Run The imports work fine in node.js as long as the code is compiled to a file with extension `.mjs`. How

String "interning" attempt

2021-02-16 Thread cblake
One more probably too advanced thing - if your calculation uses inequality comparisons a lot, you can just sort `str[]`, clear the table, and re-insert them all to get the property that `string1 < string2` if and only if `wordNum1 < wordNum2`. This of course invalidates any prior wordNum's. So,

String "interning" attempt

2021-02-16 Thread cblake
You're welcome. Also, instead of `var str: seq[string]` you can say `var str = newSeqOfCap[string](16384)` (or whatever number). That should make the appends no cost up to the initial limit and then amortized over pretty big capacity growths (which I think are 2x at each stage but someone else s

String "interning" attempt

2021-02-16 Thread cblake
Those refs will be 8B pointers not 4B (or even 2B for many vocabularies) word numbers. You could also have the number come from the size of the Table at incorporation time, as in: import tables type Str* = distinct uint32 var tbl: Table[string, Str] proc intern*(s: str

String "interning" attempt

2021-02-16 Thread Serge
Thank you !

AsyncSocket timeout

2021-02-16 Thread GabrielleHunter
Thx for advice! /

String "interning" attempt

2021-02-16 Thread Serge
Thank you, I actually meant : "echo "len(T) = ", len(tbl) ## len(T) yields : 1 (as expected), and not 2 (if my test didn't work...)". I'll try to test your model against mine for speed, but I guess appending to an array is not ideal for performance. PS: You can actually use a linked list if you

Nlftk : FLTK for Nim : how do you associate a callback to a button?

2021-02-16 Thread Serge
The example hereunder works, but I was wondering: how does one associate a callback to a button in this context? import fltk as fl var btn = make_button(64, 64, 100, 64, "Click!") btn.box = fl.Up_box btn.labelfont = fl.Helveti

String "interning" attempt

2021-02-16 Thread cblake
Oh, and FWIW, using mgetOrPut is slightly more efficient, but further from your original coding attempt (and `==` needs earlier declaration/definition): import tables type Str* = distinct uint32 var tbl: Table[string, Str] var str: seq[string] proc `$`*(n: Str): stri

String "interning" attempt

2021-02-16 Thread cblake
@shirleyquirk \- sure. I recommend you read the Knuth. It's right at the beginning of Volume 3 Section 6.4. There is also his Theorem S and exercise 8 & 9\. There are at least 2 optimal multipliers, 1/phi & 1-1/phi. :-) Of course, since the multiplications are all in integer arithmetic anyway, t

Exception hierarchy

2021-02-16 Thread Araq
Start with and keep reading. You should inherit from `IOError` or `ValueError`

String "interning" attempt

2021-02-16 Thread shirleyquirk
golden ratio is "the most irrational number" by one definition (continued fraction) so i could see how it could have useful properties. the romu multiplier seems like it was found more by craft than math.

Status Desktop - private messenger and more using Nim + QT

2021-02-16 Thread mratsim
Ah that's more clear what you meant. I expect optimizations will be scheduled in the future but we need features and proper user experience first. I expected the lack of "snapiness" perceived is because something is blocking the UI thread from time to time. Though here that requires fiddling wi

String "interning" attempt

2021-02-16 Thread Serge
Here is my new candidate for an intern(string) function in Nim: import lists var lst = initSinglyLinkedRing[string]() var tbl = initTable[string, ref SinglyLinkedNodeObj[string]]() proc intern(s: string): ref SinglyLinkedNodeObj[string] = if s in tb

String "interning" attempt

2021-02-16 Thread cblake
Any one hop from a seeded PRNG is more or less equivalent to a hash function (the latter just usually have more care Re: apparent independence with just one hop). RoMuDuoJr (multiply & rotate) is pretty similar to multiply & shift "Fibonacci hashing" (named after Knuth's enchantment with the gol

Defects and CatchableErrors

2021-02-16 Thread Yardanico
They're only catchable if you didn't specify `--panics:on` :) With `--panics:on` those exceptions are NOT catchable.

Defects and CatchableErrors

2021-02-16 Thread xigoi
They're catchable, but you're not supposed to catch them without a really good reason. Relevant issue: