How to wrap JavaScript library

2020-08-29 Thread KerryC
I am struggling with wrapping some parts of a JavaScript library in order to use it with the JavaScript backend in Nim. Examples that I have found don't seem to match my scenario. Is this bit of JavaScript code clear enough that someone could get me started in the right direction? I first set a

Alternative to float

2020-08-29 Thread Lecale
I'm making a little logman utility, which obviously involves csv parsing. I've seen float bug often enough, that I thought to myself that I really want to use an alternative here. But what is the alternative of choice? I've seen that cdouble exists, but double doesn't exist. Should I just use cd

Pause/resume the Nim VM

2020-08-29 Thread Araq
Add a new field to``TCtx`` and store it there.

Pause/resume the Nim VM

2020-08-29 Thread dsrw
How should I be getting ahold of the top of the stack? Do I need to return it from `rawExecute`, or can I get it from PCtx somehow?

Brainstorming ideas to improve Nim's landing page

2020-08-29 Thread leorize
Ideas from @haxscramper on Discord: > I believe that mentioning strong support for functional programming > (closures, higher-order functions, pure functions (with latest .strictFuncs. > addition as well as sum types). Also I think nimscript should be mentioned > too - for things like automatio

is it possible to rename a key in an orderedtable while retaining the order?

2020-08-29 Thread cblake
Oh, and it maybe bears mentioning that if you are doing your own table impl (Nim stdlib does not expose `data`/a way to get the index and it would also change on any resize event) then you could also have a `seq[(V,int)]` where the integer is an index in the "table part" for the key going with t

Observing value changes

2020-08-29 Thread sschwarzer
Combining @Stefan_Salewski 's and @jibal 's posts, here's an implementation with `setValue` renamed to the operator `[]=`. ;-) A downside is that you can't use `MyTable` where a "plain" `tables.Table` can be used as an argument. At first sight, you could us

nimDecRefIsLast and EXC_BAD_ACCESS:

2020-08-29 Thread ElAfalw
I'll give it a try in a minute and I'll let you know!

is it possible to rename a key in an orderedtable while retaining the order?

2020-08-29 Thread cblake
@cricket \- also note that perhaps non-intuitively (but well documented) `proc pop*[A, B](t: OrderedTable, key: A,...)` and its related `del` are `O(n)` operations where `n` here is the size of the `t` in question. Fixing that requires the intrusively merged linked list to go from singly- to dou

nimDecRefIsLast and EXC_BAD_ACCESS:

2020-08-29 Thread ElAfalw
I'm getting an EXC_BAD_ACCESS error, related to nimDecRefIsLast: 136 proc nimDecRefIsLast(p: pointer): bool {.compilerRtl, inl.} = 137if p != nil: 138 var cell = head(p) -> 139 if (cell.rc and not rcMask) == 0: 140

nimDecRefIsLast and EXC_BAD_ACCESS:

2020-08-29 Thread Yardanico
It would be great if you first try to run it with the latest devel Nim compiler, and then if it still doesn't work - try to reduce it to a small test case :)

Trouble using parallel

2020-08-29 Thread ElAfalw
I'm experimenting a bit with `parallel` (my main goal is to implement a simple parallel loop - that's all). I've imported `threadpool` with `--threads:on` and `{.experimental: "parallel".}`. Here's the code in question: parallel: for item in collection:

Blog post about strict funcs

2020-08-29 Thread lscrd
Thanks. That makes sense.

is it possible to rename a key in an orderedtable while retaining the order?

2020-08-29 Thread jibal
Note that there are insertion-order data structures other than seq and OrderedTable that might perform better, depending on the details of your usage. One possibility is a Table[string, int] where the values are the indices into a seq ... when you add an entry, you add the value to the seq and a

is it possible to rename a key in an orderedtable while retaining the order?

2020-08-29 Thread cricket
thank you jibal; im aware that my code doesn't do what i meant it to do, it was more of.. (an example?) because i dont think im so good at wording what i was trying to do haha re: "This seems like an odd thing to want to do, though, if you're going to do it a lot--it will be slow and defeats t

Observing value changes

2020-08-29 Thread jibal
> And that proc is automatically executed when a value changes? It's not. I don't understand @mratsim's idea. > Maybe he has to define his own "setValue" function for the table which calls > the proc whenever a value changes by use of setValue proc. Yup ... see my earlier comment.

Observing value changes

2020-08-29 Thread mratsim
Use a `(int, proc(key: string)` value for callbacks. So have a `Table[string,(int, proc(key: string)]`.

Observing value changes

2020-08-29 Thread Stefan_Salewski
> Use a (int, proc(key: string)) And that proc is automatically executed when a value changes? I can not really believe that, but sure maybe the tables module has that feature, but I never discovered it before. Maybe he has to define his own "setValue" function for the table which calls the pr

Blog post about strict funcs

2020-08-29 Thread Araq
> I just want to understand the behavior. Well `add(s: var seq[T]; x: T)` is builtin and so its body isn't checked. `add(s: var seq[T]; x: openArray[T])` is not builtin and its body is checked. That explains the difference that you have seen.

Observing value changes

2020-08-29 Thread jibal
It's your table, so just enforce that all insertions go through some function of yours. You could do `type MyTable = distinct Table[string, int]` or type MyTable = object t: Table[string, int] Run and provide wrappers for the table operations. With `distinct`, y

Observing value changes

2020-08-29 Thread ElAfalw
Let's say I have a `Table[string,int]` with different values. Is there any way I can "observe" changes to a particular key? I mean, when some key's value is changed to have a specific function executed.