Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread guzba
@PMunch I have updated Zippy to work at compile time. Example here: I don't love the trouble I had to go through to convert between string to seq[uint8] to make it work (can't cast), but it works and that's great. Can always

Capturing a context variable in public procs

2020-11-09 Thread slonik_az
Nim's stdlib has `with` macro that seems to be what you need

Capturing a context variable in public procs

2020-11-09 Thread spip
I'm working with an external library that requires passing a context variable to all library calls. As I'm writing a DSL to ease using this library, I'd rather hide this context variable to the user of the DSL. Is there a way to achieve like a closure capture variable for public procs? For inst

Issue with compile time evaluation

2020-11-09 Thread dataPulverizer
Many thanks!

Issue with compile time evaluation

2020-11-09 Thread jrfondren
If you're only ever directly naming the function names in `passFun`, this works: import std/macros proc square[T](data: T): T = return data*data proc cube[T](data: T): T = return data*data*data proc halve[T](data: T): T = return data / 2

JS target: second param of proc `[]` is taken as JsObject instead of cstring

2020-11-09 Thread r3c
Works :)))

Issue with compile time evaluation

2020-11-09 Thread dataPulverizer
I am trying to get the following code to compile proc square[T](data: T): T = return data*data; proc cube[T](data: T): T = return data*data*data template isValid[T](fun: proc (data: T): T {.closure.}): bool = (fun == cube[T]) or (fun == square[T])

JS target: second param of proc `[]` is taken as JsObject instead of cstring

2020-11-09 Thread geotre
Try this: var p = jsdata.print.to(cstring) Run

std/tables [] vs. add()

2020-11-09 Thread disruptek
I agree a new `Table` type would make sense. Unfortunately, * You want to break the old code that works in preference for bugs that may or may not exist both now and in the future. * `MultiTable` does not exist. * A new table type won't help these people read the manual.

std/tables [] vs. add()

2020-11-09 Thread cblake
That RFC design is just tuned/optimized for another point in the design space somewhere between `seq` values and the current deprecated approach. It's not exactly worse, but it is also not exactly "better" or "preferable" either (except perhaps super-duper contingently upon circumstance). In pa

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread dom96
> Well but gzip support for our HTTP server/client stuff should work "out of > the box". The problem is that we added HTTP support to the stdlib, now we > might as well make it work well... That's a good point. This is a fair reason to add it to the stdlib. I didn't realise this was the motivat

Raspberry Pi 1B - nmqtt - exit code 137

2020-11-09 Thread Yardanico
You need to have a script-wrapper over zig cc which doesn't have spaces in the name, like "zigcc"

std/tables [] vs. add()

2020-11-09 Thread xigoi
I actually think that indexing syntax should be the same as function call syntax. You can consider tables/arrays as a special case of functions where the return value for each input is listed explicitly.

Raspberry Pi 1B - nmqtt - exit code 137

2020-11-09 Thread dom96
The workaround is to create swap an enable it on your RPi.

Raspberry Pi 1B - nmqtt - exit code 137

2020-11-09 Thread mantielero
Just for the record, I am trying: nim --cpu:arm --cc:clang --clang.exe="zig cc" --zig.options.linker: "-target arm-linux-musleabihf" --zig.options.always: "-target arm-linux-musleabihf" c alarma.nim Run but it looks I am hitting the same problem: CC: s

std/tables [] vs. add()

2020-11-09 Thread timothee
dedicated `MultiTable` is indeed preferable. See for an implementation of `MultiTable` as a thin wrapper around `Table`

Nim threads on different processor core

2020-11-09 Thread cblake
This is another Linux alternative, if you know the PID and are "not the process/thread of interest": awk '{print $39}' < /proc/PID/stat Run Or you could always read the file directly from Nim, too, with roughly `parseInt(readFile(path).split()[38])` where `path` is t

Any workarounds for view-object bugs?

2020-11-09 Thread Araq
I only know `owner: ptr Outer`, sorry for the conveniences, fixes are in the works.

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread xigoi
When we're at it, what is the difference between the different regex libraries?

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread Yardanico
Have you tried LTO and/or PGO? Of course the programs using your library will need to use them, but you can test in your benchmarks at least. E.g. see

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread guzba
Hm, no I have not tried that. I'll take a look, thanks for the tip.

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread guzba
The function being discussed isn't on the hot path for uncompressing so I while I can maybe make it a template or move it up and inline it, it won't end up mattering. For those curious, here are the hot paths: Uncompress:

Raspberry Pi 1B - nmqtt - exit code 137

2020-11-09 Thread mantielero
I am exploring the [cross-compilation route with zig](https://forum.nim-lang.org/t/6362), but so far I am failing.

Nim threads on different processor core

2020-11-09 Thread cblake
CPU affinity is merely advisory guidance to an OS scheduler, not strict pinning. (This is unlike "memory pinning" via Unix calls like `mlock` which can be very strict at keeping pages resident in DIMMs.) Basically, affinity just "steers" the scheduler to make it more likely a process is schedul

Is this possible? Default iterator fields.

2020-11-09 Thread xigoi
You can simplify this: iterator items*(f: Family): Person = for member in f.members: yield member Run Unfortunately, Nim doesn't have an equivalent of Python's `yield from` and the aliasing PR didn't get accepted, so this is the best you can do.

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread Yardanico
Well, you can probably replace it by a template, but what I meant was that function inside of another function is not closure by default (unless it captures something from the outer scope).

Any workarounds for view-object bugs?

2020-11-09 Thread snej
I'm trying to use view objects in 1.4 and devel. Even my simplest test cases are either crashing, returning bogus values, or triggering C compile errors. For example: type Outer = object value: int type Inner = object owner: var Outer var o = Outer(value: 12

Nim threads on different processor core

2020-11-09 Thread snej
> When I create a new thread how do I know if it is running on different > processor core? I guess my question is "why do you want to know?" Even if you got an answer, it would be stale, since the thread could be pre-empted at any moment and resumed on a different core. `pinToCpu` calls `setTh

Raspberry Pi 1B - nmqtt - exit code 137

2020-11-09 Thread sky_khan
Not sure if it will work but I guess you may try giving it more swap space and much time.

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread slonik_az
> @Yardanico: I don't think that they are closures if the proc captures nothing The [function](https://github.com/guzba/zippy/blob/master/src/zippy.nim#L93) that @b3liever mentioned is defined inside the `func uncompress` and is not annotated as inline. Would it help to hoist it and properly ann

imgui

2020-11-09 Thread sekao
You do not need to load IMGUI from a shared library at all. If you build using the `cpp` backend, nimgl will build IMGUI from source and statically link it. See my example project here:

std/tables [] vs. add()

2020-11-09 Thread Araq
> C'mon, RTFM just once. This is a nice feature you killed out of ignorance and > FUD. Not sure why you address PMunch. It was me who "killed" it, out of feedback, people typed `x.add` instead of `x[] =` and had bugs because of it. I regard it as my mistake not having caught this during the v1.

imgui

2020-11-09 Thread juancarlospaco
Your Linux Distro package manager?. `locate cimgui.so` may help.

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread Araq
@guzba, yeah IMO `when defined(release): {.push checks: off.}` is acceptable for heavily tested code. Also, with "Dr. Nim" we can prove array indexing correct at compile-time.

Is this possible? Default iterator fields.

2020-11-09 Thread bartimus
nvm - i wasn't using the iterator items* iterator items*(f: Family): Person = var i = 0 while i < f.members.len: yield f.members[i] inc i Run

Generating code coverage with Nim 1.4.0

2020-11-09 Thread lbart
I'm also interested and I'm looking forward to it!

Is this possible? Default iterator fields.

2020-11-09 Thread bartimus
So, I used nim back before v1, so it has been awhile. I recently started looking at it again now that it has matured a lot. running through my default language learning program, I ran into this question: Background I have two objects: 1. person object 2. family object type

psutil package creation for ARM on Raspberry Pi OS

2020-11-09 Thread JohnS
Good news, I'm not sure if that's a nimble check our psutil that's making the mistake but what do you mean by `use the pkg created by nimble`?

std/tables [] vs. add()

2020-11-09 Thread cblake
@b3liever \- if we did `MultiTable` then I think we should also (eventually) add `MultiSet` (presently missing in stdlib). My `adix/lptabz` does all of the above, and adds a "sentinel" optimization, Robin Hood hashing, a "performance guarding" resize protocol, and several other expert features a

Raspberry Pi 1B - nmqtt - exit code 137

2020-11-09 Thread mantielero
I was looking to try `nmqtt` with an old RPi, but I didn't managed to build it: $ nimble install nmqtt [...] Installing nmqtt@#head Building nmqtt/nmqtt/nmqtt_password using c backend Executing /usr/bin/nim c --colors:on --noNimblePath -d:release -d:NimblePkgVer

std/tables [] vs. add()

2020-11-09 Thread disruptek
Also consider some code I wrote in the compiler recently: if p.file notin c.filenames: `[]=` c.filenames, p.file: # too bad add() was deprecated, huh? var itIsKnown: bool fileInfoIdx(ir.sh.config, AbsoluteFile ir.sh.strings[p.file], itIsKnown) Run

std/tables [] vs. add()

2020-11-09 Thread cblake
Cool, @Araq. :-) @cumulonimbus. That had occurred to me, too, I may have discussed it before, and you may be right, but Python had OpOverloading in like 1989 before Perl a couple years earlier had even gotten popular enough to have many haters or be a real "entry point" from Python (or anything

std/tables [] vs. add()

2020-11-09 Thread disruptek
Hey, I used `add` all the time and it's super annoying that I have to adopt a third-party table implementation just to keep the semantics. It's documented -- that's how I learned of it -- and I was just reading a thread about HttpHeaders from like 10 years ago where @dom96 was told in like 3 di

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread Yardanico
I don't think that they are closures if the proc captures nothing - I've tested it before and compiler correctly figures out that this is a normal proc.

std/tables [] vs. add()

2020-11-09 Thread b3liever
Would it be a good idea to have a `type MultiTable = distinct Table` that has an `add` function?

imgui

2020-11-09 Thread pihentagy
Hi all! I’m new to nim and saw that there is [imgui](https://github.com/nimgl/imgui) for GUI. But running the example (after fixing the missing ptr in the code) does not work. Where should I get `cimgui.so`if I’m under linux mint 20? ~ ⌚ 18:14:43 $ nimble install https://githu

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread b3liever
@guzba you use an inline [function](https://github.com/guzba/zippy/blob/master/src/zippy.nim#L93) I think these are closures by default. Maybe this is causing a performance drop?

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread guzba
My concern with this suggestion is it seems both -d:danger and --checks:off affect the entire build (all code and all libraries), not just this small and fuzzed section of Zippy where it matters. It doesn't seem like a great idea for all libraries to get hit with that since most are not fuzzed,

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread Stefan_Salewski
> How does Nim balance performance Maybe write in the readme: For optimal performance compile with option -d:danger. If you compile with -d:release you may additional use --checks:off.

std/tables [] vs. add()

2020-11-09 Thread cumulonimbus
> I think "just one indexing syntax" is an unfortunate artifact of 1980s era > C++/Python languages having "rigid syntax/flexible semantics". Alternatively, it is possibly an artifact of Perl having array, hash and scalar context for variables, which -- after a while -- was mostly natural, but w

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread guzba
@b3liever zlib and other C code don't have the various bounds checks etc automatically added by Nim. I already fuzz the library so I can say that it's not like it is crazy to turn the checks off as the key checks are written in code itself. How does Nim balance performance critical, CPU-bound co

std/tables [] vs. add()

2020-11-09 Thread Araq
Don't worry. :-) The `{:}` syntax is here to stay and won't change, hardly read any complaints about it either.

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread guzba
Yeah zlib is just crazy good at uncompressing. I have VTune'd and tweaked the uncompress path in Zippy and there are no obvious ways to drastically speed it up left. I think zlib has some cleverness at the algorithmic level I'll need to learn about. It'll take some work to match it. Compressing

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread b3liever
Great effort, much appreciated! Btw I noticed throughout the code: when defined(release): {.push checks: off.} Run It's a bit cheeky :) Wouldn't it be better if we follow default conversions in nim code?

Quick question about acyclic pragma

2020-11-09 Thread Araq
Seems correct to me, yes. Btw been there, done that, wrote --gc:orc afterwards, never under-estimate how complex these problems can become with `async`. ;-)

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread PMunch
This is really cool! Perfect for decompressing embedded assets as it doesn't have any dependencies. Now if only it worked on compile-time it could be used to compress embedded resources as well.

Quick question about acyclic pragma

2020-11-09 Thread jackhftang
Is the following statement correct? Even there are cyclic references between objects during runtime, but if I can make sure that 1. all ref fields are assigned to nil when the objects no more needed. 2. the objects do not form a closed reference loop that cannot be travelled from the root p

std/tables [] vs. add()

2020-11-09 Thread cblake
Also, the `{}` literal syntax does _not_ restrict to non-dups. `{ 1:1, 1:2, 1:3 }` will probably always be equivalent to `@[ (1,1), (1,2), (1,3) ]`. To my knowledge there are no plans to make `{}` de-dup and I, for one, hope it stays that way. Such `{}` sugar is syntactic while de-dup is semanti

JS target: second param of proc `[]` is taken as JsObject instead of cstring

2020-11-09 Thread r3c
Is this a bug, or am I doing something wrong? import jsffi var jsdata = js{ one: js{"one": "asdasd"}, two: 2, print: "" } var vue = js{ data: jsdata, watch: js{ # template/generic instantiation of `{}` from here

std/tables [] vs. add()

2020-11-09 Thread Hlaaftana
If you don't need indexing and just need to iterate over a collection of keys to values, then you can use a `seq[(string, string)]`.

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread cumulonimbus
> It's just 1% slower then regular zlib, but in pure nim. I didn't try it, but reading guzba's readme table, it's 0-20% slower when compressing, but about 200% slower when decompressing. It's still great to have a native Nim version, but if that's the speed difference, it's still not time to ki

Why does this proc may have side effects?

2020-11-09 Thread PMunch
Unfortunately it doesn't appear like `{.effects.}` lists side effects like you might expect, so it can't be used to do what you're trying to do (to figure out which side-effect triggered the error). Although in your case you're only calling a single procedure,`+`, so the possibilities are pretty

std/tables [] vs. add()

2020-11-09 Thread cblake
I retain the duplicate key/multitable/multiset feature in my `lptabz` in the [adix](https://github.com/c-blake/adix) package as mentioned [at the end of this thread](https://forum.nim-lang.org/t/5917) and also [this one](https://forum.nim-lang.org/t/6944). That's the only compatibility support

Why does this proc may have side effects?

2020-11-09 Thread HarmlessBall
Good one, I had no idea about this trick. Make sense if it works pretty well. Thanks! [.](https://www.walgreenslistens.review/".";)

std/tables [] vs. add()

2020-11-09 Thread PMunch
Well, the problem was that people didn't realise that `add` added another key. There's also the issue that `[]` for a table only returns a single value, and it's not guaranteed which it will be, and there is no way apart from iterating all the keys to get all values for a key. I'm not sure if a

std/tables [] vs. add()

2020-11-09 Thread domogled
Hello, function add from std/tables package is deprecated since nim version 1.4. Add and [] are not identicaly. _Warning: Deprecated since v1.4; it was more confusing than useful, use `[]=`; add is deprecated [Deprecated]_ var dict: Table[string, string] = initTable[string, string

Reference Variable (C++ jargon) - is there such a beast?

2020-11-09 Thread Araq
> The big question: is it probably that experimental features stay or become > even non-experimental? View types are regarded to be so important that we hope to have them non-experimental in 2021 but that doesn't hold for other experimental features.

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread slonik_az
> @dom96: Why push to have so much stuff shipping with Nim? TL;DR: New Nim users tend to favor stdlib, fusion over 3-rd party packages. My perspective is of a new Nim user (started using Nim a month ago). As it was mentioned here by other newcomers I am

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread Araq
Well but gzip support for our HTTP server/client stuff should work "out of the box". The problem is that we added HTTP support to the stdlib, now we might as well make it work well... But there is not much to regret here either, both "web of third party libs" (Rust) and "stdlib is big and audit

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread dom96
> I think fusion is a good place to put this code into. FWIW I disagree. Why push to have so much stuff shipping with Nim? Installing Nim packages is trivial for most use cases, if it is not then we should fix that instead of pushing the Nim core team to maintain more packages themselves.

Zippy: a dependency-free Nim implementation of deflate, gzip, zlib, zip

2020-11-09 Thread dom96
This is awesome! I will be pushing to use it in choosenim :D Thank you for working on this.

Returning objects from func with ARC

2020-11-09 Thread Araq
1.1 seems to be a bug -- please report it on github. As for the other questions... format them differently please, to answer them thoroughly, I need to scroll back and forth way too much.