Pause/resume the Nim VM

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

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

2020-08-30 Thread Araq
> Fixing that requires the intrusively merged linked list to go from singly- to > doubly- linked and @Araq does not like to charge "non-delete workload" cases > for things only needed by mixed workloads. (In this case the charge is space > for the 2nd link.) That's t

What about simplifying if-else statements ?

2020-09-05 Thread Araq
> Note that nimpretty won't preserve the spacing, so I never use it and > consider it misnamed. Well your spacing is ugly so nimpretty's name fits. ;-)

how to use .ini content in a GC-safe way?

2020-09-05 Thread Araq
Pass a config parameter to `connectToDb` and remove your global variables.

Question on implementing language with Nim

2020-09-03 Thread Araq
Sure it's possible, add to your VM the capability to run callbacks.

What about simplifying if-else statements ?

2020-09-06 Thread Araq
I really do find it ugly. At least write it this way, whitespace before a colon is uncommon in written English. if a(0): # whatever elif a(4): # whatever elif a(8): # whatever else: # whatever Run

openArray vs seq

2020-09-06 Thread Araq
First of all `openArray` is compatible with `array` and `seq` isn't. Secondly, the difference becomes more apparent in this snippet: proc p[T](x: var openArray[T]) ## can mutate x's contents but x cannot grow or shrink. proc p[T](x: var seq[T]) ## can mutate x's

openArray vs seq

2020-09-06 Thread Araq
But then you cannot pass a `seq` to it. `openArray` is not redundant.

What about simplifying if-else statements ?

2020-09-06 Thread Araq
Yes, but that's nimpretty's job! ;-) For sections of code you can disable nimpretty: #!nimpretty off if a(0): # whatever elif a(4): # whatever elif a(8): # whatever else: # whatever #!nimpretty on Run

For ``--gc:arc``, are ``GC_ref`` ``GC_unref`` still necessary?

2020-09-04 Thread Araq
Once you add both `GC_ref` and `GC_unref` calls into your code where they are required both ARC and the old GCs should be fine with it.

Nimble package structure and interop changes

2020-08-31 Thread Araq
> I've updated the wiki with a backwards compatibility section. Please review > changes and let me know if you have any feedback. Seems to be well thought-through, congrats! :-)

What about simplifying if-else statements ?

2020-09-02 Thread Araq
For your own projects please feel free to use a macro for your favorite play on syntax. Once you make your code public or have other people look at it, remove your macro usage and use `if ... elif` like everybody else. :-)

Question for the language theorists: Is NIm's OO class-based or prototype-based?

2020-08-31 Thread Araq
It is class based. Few operations are made part of the "class" but that doesn't make it closer to "prototype-based".

openArray vs seq

2020-09-10 Thread Araq
Er, and how could we make them type-compatible otherwise? The underlying `ptr, len` pair is essential, see also C++'s iterators and spans, C#'s spans etc. On the contrary, `openArray` is a "borrowed" non-owning type, introduced long before Rust was invented.

Attracting more people...

2020-09-07 Thread Araq
We used to have a "this month in Nim" and vlog developer updates. We should do them again. I'm not really sure why efforts like these come and go. I do know that my live streaming sessions stopped with Corona. :-)

how to package C-only project on macOS?

2020-09-10 Thread Araq
You can do that via niminst, see for more information. However, you can also simply ship binary files on macOS X.

Compilation for different macOS version

2020-09-11 Thread Araq
Probably it's necessary to _build_ on the oldest OS you want to support.

Change Nim colour on GitHub

2020-09-11 Thread Araq
It wasn't.

How do I reduce allocation and GC with pool of objects?

2020-09-09 Thread Araq
Just compile with `--gc:arc`. ;-)

Exceptions in Threads

2020-09-08 Thread Araq
It's easy to wrap the `.thread` proc like so: var errorChannel: Channel[string] open errorChannel proc myThreadProc() {.thread.} = try: stuffThatCanFail() except: errorChannel.send getCurrentExceptionMsg() createThread(th,

How do I reduce allocation and GC with pool of objects?

2020-09-09 Thread Araq
Well ok but if you think that a refcount makes your program faster then that's what --gc:arc does. Anyhow, there are plenty of ways to use a custom allocator, most start by turning your `Value = ref object` into `Value = ptr object`.

multiple definitions when wrapping header-only c++ library

2020-09-08 Thread Araq
Ah right, makes sense. :-)

multiple definitions when wrapping header-only c++ library

2020-09-07 Thread Araq
Please report this bug on github. (Strange thing...)

Change output option for linker on windows

2020-09-07 Thread Araq
Did you try the `--out:filename` command line option?

Any easy way to compare `==` object variants?

2020-09-07 Thread Araq
You can write a macro to generate the `==`. In fact, that's what Nim should do but doesn't (yet).

High proc confusion

2020-09-07 Thread Araq
I think we can change `high` for the better. :-) `high` for integral _types_ is fine but then `high(3)` should not compile as `3` is not a type, it's value. Likewise `high` for seq/arrays is ok and a different operation. In fact, it's a good example for how not to overload procs, 2 completely

Strange and misleading error message when converting to JSON

2020-09-12 Thread Araq
Looks like you hit :-)

ARC/ORC cpu intensive loop bug?

2020-09-15 Thread Araq
Please report bugs on github. Also, for CPU performance consider using Weave, much more effort went into Weave than into Nim's spawn implementation.

``deepCopy`` replacement in "returning a modified copy"

2020-09-15 Thread Araq
I don't have a good solution either but once again I'm working on making `deepCopy` and `marshal.nim` work with arc and orc, had a new idea of how to tackle this problem.

Globals hunt

2020-09-16 Thread Araq
There is the `.global` pragma that does pretty much what C's `static` does. But it's a very bad idea in both languages as your code then is not threadsafe! Instead pass the state the procs need around via parameters.

What's the point of marking methods with {.base.} pragma?

2020-09-16 Thread Araq
`.base` was requried back then when we had multi methods. Now it's still useful, C# uses an explicit "override" keyword to override methods, override in Nim is the default but the downside is that "base" methods have to be annotated.

How do I reduce allocation and GC with pool of objects?

2020-09-12 Thread Araq
To change an object variant's kind, produce a new object variant. Like so: obj = Obj(k: newKind, v: obj.v, x: obj.x) Run

About sink and copy: is this expected behavior?

2020-09-13 Thread Araq
The generic thing is probably a bug, please report it on github. The other problems are not problems, Nim is allowed to optimize away moves as well as copies. See the section "Cursor inference / copy elision" of the spec. This goes way beyond what C++ does.

Cross-compile to Rpi4 :(

2020-09-14 Thread Araq
* Ensure your GCC installation is setup correctly. * See what that mysterious `./serv` program is doing. * Try to understand why you binary file contains ")" and why it's interpreted as ascii.

Add hash[T] to hashes?

2020-09-13 Thread Araq
Object identity cannot be automated.

Add hash[T] to hashes?

2020-09-13 Thread Araq
Well guessing that `object` means `tuple` isn't good enough for me. I keep getting (minor) bugs with `$` that "simply exists" for my objects which are not trivial, so yeah, these defaults cause problems.

Nim documentation in pdf format

2020-09-04 Thread Araq
You can build a PDF version of the documentation via `koch pdf`. (I currently can't because I don't have pdflatex installed anymore.) The reason we don't ship a PDF version is because then we would need to check the layout for every new version we release. Just use "save as" for the web page

Nimble package structure and interop changes

2020-09-04 Thread Araq
Once again, as soon as we require `import x / x` rather than `import x` there is no "pollution" of module names. Nimble introduced the pollution, not Nim.

Pros vs. Cons Of Nim In The Large?

2020-09-04 Thread Araq
> After C# it's looks kinda naive. The biggest issue is that while technically > you can hide some parts of the library from user it's inconvenient. There is > no internal namespace scope where I can easily separate lib functionality > from the users code. Again, Nim is not C#, I understand

Question on implementing language with Nim

2020-09-04 Thread Araq
(Nitpicking: that's a classical interpreter and has nothing to do with "just in time" compilation. It always helps to get the basic vocabulary right.) There are two ways to do what you need, one is to use libFFI, see The other,

For ``--gc:arc``, are ``GC_ref`` ``GC_unref`` still necessary?

2020-09-03 Thread Araq
What you're doing is implementation defined and very dangerous. But your observation seems to be correct, in this case GC_ref is not required for `--gc:arc`. But it's a hard puzzle and I might change my mind about it. :-)

How to achieve better performance with arc GC?

2020-09-01 Thread Araq
In no particular order: * Compile with Nim devel, check its cursor inference optimizer does its job (though it's work-in-progress) * Compile with `--panics:on -d:danger` and with link-time optimization. * Use `lent`, `sink`, `cursor` and `acyclic` annotations. * Run a profiler. * Use

global var not detected by compiles()

2020-08-31 Thread Araq
When `main` is compiled your global variable is not yet declared. This works: template test(k: untyped) = when compiles(k): echo "it compiled" k = "New England" else: echo "not compiled" var k = "New England"

System Programming in 2k20

2020-09-01 Thread Araq
> OOP is just a tool in the programming toolbox and can be used and misused, > like any other tool. That's true but if we had computer _science_ , here is my bet what it would show: OOP produces more error-prone and hard-to-debug systems much more often than the "competing" paradigms do.

System Programming in 2k20

2020-09-01 Thread Araq
> Nevertheless, Nim lacks this semantic at all, and there is no way for a user > to distinguish between "safe" and "unsafe" areas of code. That's simply wrong, the unsafe features are `ptr`, `addr` and `cast`, all keywords. In fact, most other of your points are equally wrong and it feels like

High proc confusion

2020-09-07 Thread Araq
> I suggest deprecating the first one That's what I tried to say, yes, completely agree.

Module imported with "as" still accessible, is it a bug?

2020-09-13 Thread Araq
Name pollution or not, `as` introduces a **module alias** , it doesn't turn the `import` into a `from` statement. Perfectly consistent, round design here that we won't change.

Should a function that's called many times return Table or ref Table?

2020-09-10 Thread Araq
Use `TableRef` for this case but your design itself is not good. For example, it's immediately not thread-safe.

Can std lib work with gc:arc or gc:orc ?

2020-09-10 Thread Araq
The following remain unsupported for ARC/ORC for the time being: `system.deepcopy` `marshal.nim` Everything else works.

Reference to tuple type

2020-10-07 Thread Araq
You cannot store a type that has a `ref` into a `const`, but you can use them inside compile-time procs in intermediate steps.

Nim - plugin for IntelliJ IDEs | JetBrains

2020-10-07 Thread Araq
> Nim is quite in complex as in to know all procedures and types which are > generated via macros you basically have to implement an interpreter and the > majority of the language rules. You can play tricks though and apply heuristics. In fact, I rely quite a bit on "Tabnine" these days and

Dual behavior

2020-10-08 Thread Araq
Even if there is a way to make this work in the way you want it to work, it's completely unidiomatic Nim code and thus bad design. In Nim a dot call doesn't indicate mutation.

A nice read about Nim (blog article)

2020-10-14 Thread Araq
> So, this kostya benchmark seems to me like a textbook case of what not to use > json for (500k*3 floats...Really?). Yeah, this benchmark is terrible bullshit but our JSON parser is slow. My "packedjson" package helps with the memory consumption of the lame "let's read it all into a graph

Small introductory post about ARC/ORC in Nim.

2020-10-15 Thread Araq
`Isolated[T]` has been implemented but now we need a channel implementation that works with it... And yeah, if your worker thread can "steal" subgraphs and return them back afterwards via moves it is a solution to your problem. If not, you need to use atomic refcounts which are coming to

A nice read about Nim (blog article)

2020-10-15 Thread Araq
Not to mention that JSON doesn't support special floating point values like Infinity or NaN. It's a bad format with the only advantage that it's not XML. I'm looking foward to the days where progress in computing is based on computer science and not on unbelievable hacks that survived for way

A nice read about Nim (blog article)

2020-10-15 Thread Araq
Incrementalism is easily done by using the parsejson.nim library and its token stream.

Show and tell: RPC on embedded devices

2020-10-14 Thread Araq
> It's correct that the ORC cycle collector will only run at/on GC ref/decr's? Correct. And only on decrefs that are not decrefs to zero. But you can also disable it via `GC_disableMarkAndSweep` and run `GC_fullcollect` when you know you can afford it. These operations are now poorly named,

Nim Source Magic

2020-10-14 Thread Araq
I don't see how that would help. But then I don't see why compiler builtins are confusing either. It's not turtles all the way down, there is a ground floor.

Regarding the future of --gc:none and --gc:regions

2020-10-15 Thread Araq
Well the most expensive to maintain GC mode is `--gc:refc` but the RFC is about unifying the ecosystem and not so much about cutting maintenance costs for us. That said, neither --gc:none nor --gc:regions are convincing switches for me, I see them as failed experiments and ARC as the winner. We

python dict implementation for Nim's Table

2020-10-15 Thread Araq
Well it's not that I mind PRs that change our tables implementation for the better, but we do have to maintain compatibility and people usually depend on even little details like iteration order (if only in the unit tests) or the fact that tables are `const`-able (something I regret btw). Now

Regarding the future of --gc:none and --gc:regions

2020-10-15 Thread Araq
> How could this be mitigated? Give `typeof(newBigTree(n))` a custom destructor or move `x` to a different thread / container.

Regarding the future of --gc:none and --gc:regions

2020-10-15 Thread Araq
> It is the most performant option, and no matter how fast arc/orc get, they > will still be slower I haven't seen this in benchmarks. Got one to share where it's true?

-d:danger versus -d:release --checks:off

2020-10-06 Thread Araq
> To get a definitive answer... Well people read the source code successfully. Can't get more definite than that. :-) But yeah, `danger` is `release + checks:off`. And the default config should probably be simplified to use `--checks:off`.

Massive Funding Coming To Nim

2020-10-06 Thread Araq
Oh no that harmful.cat-v troll page... I still don't know what's so great about the vi/Unix/C/awk setup, they are so awkward most industries moved away from them...

Looking for collaborators!

2020-10-05 Thread Araq
> Btw I'm so glad this is a language specific thing rather than a broken logic Ref semantics vs value semantics are hardly "language specific", they apply equally to all systems programming languages, in fact, it's the defining term of "systems programming", I would argue.

Looking for collaborators!

2020-10-05 Thread Araq
Changing how this works is not negotiable, Nim does it far better than C#/Crystal/D and the more time I spend on "strict funcs", borrowing, ORC and optimizers, the clearer it becomes. > On the down side, writing Nim programs feels a little like writing Perl in > that I need to pay extra

Double for loops

2020-10-12 Thread Araq
Sometimes a tiny amount of math does the trick: var seq1 = @[ #[First seq's content]# ] seq2 = @[ #[Second seq's content]# ] for index in countdown(min(seq1.len, seq2.len)-1, 0): echo(seq1[index] + seq2[index]) Run

Nim's vision

2020-10-16 Thread Araq
My current vision is "Nim is the most convenient language for embedded devices and (hard and soft) realtime systems". But visions change too and in the meantime we use Nim ... for everything.

Version 1.4.0 released

2020-10-17 Thread Araq
Thank you and a big thank to all contributors! Unfortunately, as you can see, we messed up this release a bit. Reason: We had a couple of solid releases, fully automated, grew confident, did the same steps this time but the "nightly builds" setup was changed. :-)

Regarding the future of --gc:none and --gc:regions

2020-10-20 Thread Araq
Reasons it was phased out: * Benchmarks didn't convince me. * Incredibly easy to write bugs once you're beyond the "I write benchmarks" state. * Memory consumption can easily be worse than classical GCs. * To enable safe cross region pointers you need much of the existing deepCopy

Regarding the future of --gc:none and --gc:regions

2020-10-20 Thread Araq
`--gc:regions` was "phased out". Or better put: "wasn't developed further".

Regarding the future of --gc:none and --gc:regions

2020-10-20 Thread Araq
Oh that one... Nobody used it. And the original motivation of distinguishing between user-space and kernel-space pointers for kernel development was hopelessly naive -- you must not deref a user-space pointer inside the kernel so it's even better to model it as `type UserSpaceAddress = distinct

Views of a non thread local var

2020-10-20 Thread Araq
View types are part of the memory safe Nim subset and so we have to protect ourselves against mutations of global variables performed by other threads. Your workaround is a nice way to show this protection is not nearly good enough. :-) Not sure how to solve it. Maybe view types should be

Nimpretty --maxLineLine seems broken

2020-10-10 Thread Araq
https://github.com/nim-lang/Nim/pull/15541

where are fusion docs?

2020-10-09 Thread Araq
Good questions. Things we should sort out for the 1.4 release.

Reference to tuple type

2020-10-06 Thread Araq
The example screams "use an object type instead" to me.

Any attempts at implementing filestream and std lib friends on NodeJs?

2020-10-08 Thread Araq
Please read for the pros and cons. Unfortunately this is not yet an RFC. And I think we all agree that supporting a new target should be justified in an RFC.

A nice read about Nim (blog article)

2020-10-14 Thread Araq
> Compile-time is not a problem, use when nimvm Ha! Good one. (I'm aware, `when nimvm` doesn't help me as you cannot use it inside an object declaration.)

A nice read about Nim (blog article)

2020-10-14 Thread Araq
Last time I looked into json parsing performance I was blocked by our (silly IMO) requirements that json parsing must be do-able at compile-time... But please @cblake take a look, it's the most obvious candidate for optimizations.

Small introductory post about ARC/ORC in Nim.

2020-10-14 Thread Araq
I love it. Very good job! Maybe I would phrase a couple of things differently, but everything seems to be correct. (And that's rare!)

Regarding the future of --gc:none and --gc:regions

2020-10-19 Thread Araq
Well this is all very interesting but for now it's good enough to keep the `--gc:regions` switch. But in theory with the right collection libraries and maybe a polymorphic allocator and the `=hooks` mechanisms you can create a much better `withRegion` construct. One that works with ORC and

General recommendation for optimum performance?

2020-08-18 Thread Araq
Your options are a pretty good start, for --gc:arc "nim devel" usually has more optimizations implemented. Also, use `--panics:on`.

Nimble package structure and interop changes

2020-08-28 Thread Araq
I still don't understand how backwards compatibility would be handled. By a `nimble --legacy` switch?

Recognizing non-ASCII characters in lexbase-based lexer

2020-08-28 Thread Araq
Like so: const PermittedIdentifiers_In = {'a'..'z', 'A'..'Z', '\128'..'\255'} Run You can check for "valid Unicode" or "only some Unicode classes are allowed" in a postprocessing step , unicode.nim should be helpful for that.

Nimble package structure and interop changes

2020-08-28 Thread Araq
Well `--path` has a strict order so what module you refer to is deterministic. We could warn about ambiguous module imports but there is little need, if the order is wrong, you import the wrong module and you get not found symbols or type mismatches.

Blog post about strict funcs

2020-08-28 Thread Araq
> Before investigating further, I would like to know if I missed something. You didn't, this code must compile.

Blog post about strict funcs

2020-08-28 Thread Araq
> Mutability via var parameter has higher priority than immutability of other > parameters? Correct.

Blog post about strict funcs

2020-08-28 Thread Araq
As I wrote, `add` for seq must be `.noSideEffect` no matter the `T`. The analysis might be "sound" as it it is, but it's too conservative. :-)

For Loop Macro Plans

2020-08-28 Thread Araq
IMHO it's high time to move them from their "experimental" status to stable.

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.

execvp / fork in 1.3.5

2020-08-21 Thread Araq
Tried the `osproc` module too? I see no need for your Posix specific code.

htmlparser bug? Help with my web scraper

2020-08-22 Thread Araq
htmlparser was written before there was a standard that explained how to repair broken HTML and most HTML out there is broken.

htmlparser bug? Help with my web scraper

2020-08-22 Thread Araq
> Is there an alternative or recommendation so that I know a random Google > Search won't break? Please report a bug with an example HTML string inside.

does using `result` guarantee NRVO?

2020-08-22 Thread Araq
Yes, but there is a codegen bug we need to fix. The bug is a decade old though...

Want advice from Nim experts on my chess client app development

2020-08-22 Thread Araq
Regarding, (2) simply compile with --gc:arc. (Not to mention what an utterly bizzare requirement that is...)

Table with different types of values?

2020-08-21 Thread Araq
Use Nim's type system. type Keys = enum key1, key2 Value = object param1: string param2: int const table = array[Keys, Value] = [ key1: Value(param1: "a string", param2: 100), key2: Value(param1: "another

Blog post about strict funcs

2020-08-27 Thread Araq
I wrote a new blog post: <https://nim-lang.org/araq/writetracking_2.html> Please enjoy and feel free to ask questions here.

Blog post about strict funcs

2020-08-27 Thread Araq
These should be provided as external libraries (and iirc we have some Nimble packages offering these) or added to "nim fusion". Our focus is on language development, not on libraries.

Blog post about strict funcs

2020-08-27 Thread Araq
> Can the error message be expanded to show you the alias chain that lead to > the mutation? Currently it does show a single step of the alias chain. You're probably right and it should show all steps. It's not as easy though as the algorithm doesn't even track this (it's called "path

Pause/resume the Nim VM

2020-08-24 Thread Araq
> Should I work to get some version of my patch included in Nim, perhaps > replacing the Pausable stuff with a new NodeKind variant? Something like that but I wonder if it requires a new NodeKind at all. The `PCtx` already contains everything required except for the "program counter".

  1   2   3   4   5   6   7   8   9   10   >