Please help, learning NIM to speed up Python programs, but strange results

2024-06-06 Thread nrk
As @joppez says zippy beating Python above is not very surprising, since it just decompresses the file in a single pass after having read the entire file into memory. Streaming implementations tend to be slower (but of course use less memory, which is kind of the point). As for why gzipfiles is

Monoucha: a high level QuickJS wrapper

2024-06-03 Thread nrk
A preview version of Monoucha, a high-level QuickJS wrapper, has been released: Monoucha is aimed at projects that wish to embed the QuickJS engine with relatively little effort and/or changes to their existing code. It is not a goal of the project to abstra

Issue: regression on 2.x.x: push warning[HoleEnumConv]:off does not work.

2024-05-12 Thread nrk
Maybe you already know, but a workaround is: type e = enum a = 0 b = 2 var i: int {.warning[HoleEnumConv]:off.}: echo i.e Run which seems to work on both versions.

Unicode operators / Arrays, which size is know at run time

2024-05-01 Thread nrk
To expand upon the unicode operator thing: It's a "do-it-yourself" kind of deal. You get to define the meaning of these operators, and they syntactically work like the pre-defined `+`, `-`, etc. e.g. func `∪`[T](a, b: set[T]): set[T] = return a + b func `∪=`[T](a: va

recusion use a lot of memory, any idea why?

2024-02-27 Thread nrk
Nim is not a functional language. You should avoid unbounded recursion, even if it's tail recursion; it's not idiomatic and you are at the mercy of your C compiler to optimize it out. So in this case you should prefer the iterative version. That said, if you really want to tail recurse, here's

Chame 0.14.0 released

2024-02-07 Thread nrk
[Chame](https://git.sr.ht/~bptato/chame) 0.14.0 has been released. Quick ([re](https://forum.nim-lang.org/t/10367#69029)-)introduction: Chame is an HTML5 parser (implementing the WHATWG standard used by modern web browsers) that exposes low-level hooks for operating on user-provided DOM impleme

proc/func/method: syntax

2023-11-16 Thread nrk
I'm so sorry. #[ """ # ]# import macros type None = void str = string macro def(d, b: untyped) = let n = d[1][0] var params: seq[NimNode] var defb: seq[NimNode] params.add(d[^1]) for x in d[1][1..^1]: if x

Strange string prefix

2023-11-13 Thread nrk
For debugging low-level details, it's always useful to check the generated C code. e.g. echo 'echo "hello, world"' > x.nim mkdir tmp nim c --nimcache:tmp x.nim Run Now you can find the source in `tmp/@mx.nim.c`. Let's search for our string: stati

system.string

2023-10-02 Thread nrk
Your type signature looks a bit strange. `Table[string, [seq[int]]]` should probably be `Table[string, seq[int]]` (without the brackets around `seq[int]`); the former appears to be interpreted as a single-element array of `typedesc[seq[int]]`'s, which you can't even pass to Table in the first pl

Simple template and macro question

2023-09-26 Thread nrk
> Is there a way to actually see the expanded Nim code. Maybe try [expandMacros](https://nim-lang.org/docs/macros.html#expandMacros.m%2Ctyped).

Simple template and macro question

2023-09-24 Thread nrk
You have encountered symbol injection & gensym. By default, symbols of variable names in templates (and `quote`) are gensym'ed. This means that they receive a unique identifier only used inside the context of said template. You can in fact inspect this behavior using `repr`: impor

Chame - an HTML5 parser library in Nim

2023-08-01 Thread nrk
A preview version of Chame, the HTML5 parser used by Chawan, has been released. (Previously discussed [here](https://forum.nim-lang.org/t/10328).) Repository: Unlike the stdlib or fusion HTML parsers, Chame aims for 1:1 compatibility with how modern web browser

W3C Compliant HTML Parser to replace current std/htmlparser

2023-07-08 Thread nrk
To some degree; but not extensively. I heavily use it for interpreting HTML content in some private projects (using DOMParser.parseFromString from cha -r), so I have probably caught the most obvious errors by now. But it has no proper testing yet. An integration of [html5lib-tests](https://gith

Why iterator doesn't work?

2023-07-08 Thread nrk
How about a template? import std/tables type Record = object tags: seq[string] Db = object records: seq[Record] template stats*(records: iterable[Record]): CountTable[string] = var res: CountTable[string] for record in r

W3C Compliant HTML Parser to replace current std/htmlparser

2023-07-08 Thread nrk
I am indeed planning to isolate Chawan's html5 parser into a separate library. Right now I'm evaluating the best way to write an API that doesn't involve bringing in half of Chawan as a dependency; preferably it would work similarly to [html5ever](https://github.com/servo/html5ever), so you coul

Ferus -- a tiny web engine written in Nim

2023-07-03 Thread nrk
Always great to see more browser engines in development. I've been working on a similar project for a while, and only recently released it; maybe you will find it interesting. Though our end goals are different (I target terminals), and my approach is in large part "NIH for fun", so it's more o