unexpected output

2024-08-26 Thread Araq
Also C's `float` is Nim's `float32`.

Possible issue with getting the starting address of a Nim string

2024-08-26 Thread Araq
`result.setLen(ms.size)` doesn't compile with `experimental:strictDefs` anyway (the default for the Nim compiler itself).

cstring as key in tables

2024-08-25 Thread Araq
Well the hash table does not take ownership of the `cstring` keys which could be exactly what you want. There is a specialized version of `hash` for `cstring` so go right ahead, it should just work.

Running procs from a list of procs

2024-08-24 Thread Araq
Easy to do with `std / tasks`. For example: import std / tasks proc hello(a: int) = echo a proc other(s: string) = echo s let myTasks = @[toTask(hello 3), toTask(other "abc)] for t in myTasks: invoke(t) Run

Fusion OS: a hobby kernel written in Nim

2024-08-23 Thread Araq
Nim used to have "regionized" pointers but I removed them before v1.0 as nobody used them...

Fusion OS: a hobby kernel written in Nim

2024-08-22 Thread Araq
> I wish there was an ability to create MemRegions with an associated OS > allocator instance, so that allocating against a specific MemRegion would use > separately managed heap pages. What's the problem? Patch alloc.nim to offer what you need.

Fusion OS: a hobby kernel written in Nim

2024-08-22 Thread Araq
I cannot comment on Koka per se but functional programming languages in general don't understand the heap at all and neither do "scopes". If all you do is writing compilers it's easy to miss what a heap actually is. A heap is all the state that _outlives_ the functions. You cannot tie it to fun

Atlas shrugged...

2024-08-21 Thread Araq
Feedback on this idea appreciated:

Fusion OS: a hobby kernel written in Nim

2024-08-21 Thread Araq
> In a way it's no different than caching a pointer to an arena-allocated chunk > that may outlive the arena context. Maybe I'll think of migrating resources > up the context tree if their owner changes? It is not different indeed. And once you have "migration" you effectively have a system wit

Enabling compression on socket send/receive.

2024-08-21 Thread Araq
The `if` is only everywhere when you fail at using wrapper procs for send/recv consistently.

Request for feedback: `destructor` macro

2024-08-21 Thread Araq
` `=destroy`(x.field.addr[])` is a symptom, not the cause. The cause is you do something you shouldn't do. The compiler composes a perfectly fine destructor on its own. Here is when you need a custom destructor: When your type has a `ptr` or "handle like" integer type and you want to free the c

Fusion OS: a hobby kernel written in Nim

2024-08-21 Thread Araq
> One thing I'd like to experiment with in Fusion is kernel-tracked contexts. Do what you think is worth doing, of course, but I cannot imagine this to work well. It only invites bugs as pure stack based memory management is very limited. Maybe the web request opens a connection to a database, s

Fusion OS: a hobby kernel written in Nim

2024-08-21 Thread Araq
The Nim PL can do that for you with the destructors feature. However, most of the standard library has yet to be ported to Nim v2 to do that. The OS cannot do it for you as the OS does not know the type layouts at runtime, for the OS the running process is mostly pages of random bits.

Request for feedback: `destructor` macro

2024-08-20 Thread Araq
If you use Nim's `ref` you should stick to Nim's ARC/ORC thing. Upcoming version 2.2 got some better support to track down cycle leaks. It is usually a bad idea to interfer with the compiler in ways unforseen by the compiler devs ;-), if you want your own memory management you should use `ptr`.

Forum logo issue

2024-08-20 Thread Araq
In other words, NimForum raised from the dead and got an update. Many thanks to you @PMunch!

Mastering Nim: Table of Contents?

2024-08-20 Thread Araq
I uploaded the TOC here:

How to cite the Nim?

2024-08-18 Thread Araq
I don't know. Back then my PhD thesis about Nim was rejected. ;-)

UncheckedArray and closure issue

2024-08-17 Thread Araq
Start by not capturing `elements` in: (index.with_length length).sort do (a, b: int) -> int: elements[a].cmp elements[b] Run And in general it helps to know the language. For example `cast[ptr UncheckedArray[T]](cast[pointer](alloc(n * sizeof(T` should

How to sort dynamically allocated wordlists -- Sorting UncheckedArray type

2024-08-16 Thread Araq
Use `system.toOpenArray(arr, 0, myLength-1)` which can construct an open array from an unchecked array.

what is the type of exception raised by malebolgia?

2024-08-16 Thread Araq
I couldn't get Nim's runtime to duplicate the precise exception type (it's missing an API for that) but I also didn't try too hard. PRs are welcome, to system.nim or Malebolgia.

why Nim shows different behavior on int overflow?

2024-08-15 Thread Araq
The manual covers the language, not the library. When you open the manual there is link that says "Standard library". There is only so much you do for readers who don't read. ;-) Back to your question: Unsigned integers in Nim have wrap around semantics on overflow because unsigned was introduc

Notifying the dispatcher from a different (foreign) thread

2024-08-15 Thread Araq
I don't really know but my rule of thumb is "polling is the only thing that actually composes".

why Nim shows different behavior on int overflow?

2024-08-15 Thread Araq
I search the index for "max", eventually I get to: which leads me to: "high(int) is Nim's way of writing INT_MAX or MAX_INT." Then I use a fraction of my brain's activity and try out `echo high(

can we use `method` to replace `httpMethod` and `reqMethod`?

2024-08-14 Thread Araq
You can use `method` as a name when you use backticks around it but it's too annoying. Almost as annoying as having to deal with hyperbole.

Malebolgia & VCC, does not always finish

2024-08-14 Thread Araq
I don't know how reliable our atomics are for VCC, please investigate.

Is this a good idea?

2024-08-14 Thread Araq
The manual does not call it "undefined behavior" (UB), that's your term, it says "Whether a panic results in an exception or in a fatal error is implementation specific" and that means it does not depend on the "platform" assuming "platform" implies OS or CPU. Anyway my major point is that we a

Can Nim Macros be used to emulate Fennel's capabilities ?

2024-08-12 Thread Araq
Sure, write a compile-time Lisp parser. Maybe 300 lines of code.

Can Nim Macros be used to emulate Fennel's capabilities ?

2024-08-12 Thread Araq
What is even the question? Emulate what? The features that Nim already has?

Compile times normal or my fault?

2024-08-12 Thread Araq
Well Nim is single threaded but runs the C compiler in parallel, one .c file is produced for every .nim **module**. You can influence it with `--parallelBuild:N`.

Is this a good idea?

2024-08-11 Thread Araq
It is a bad idea because you now have a new failure mode (`FieldTypeError`) everywhere that Nim usually does not have.

Oh threadpool, my threadpool

2024-08-11 Thread Araq
Before that happens, I still like to explore how to combine Malebolgia with async or IO heavy loads.

Setter for Base and Inherited Class (Cont..)

2024-07-27 Thread Araq
`result.setBase = b` should either be `result.setBase b` or `result.base = b`.

Webview style UI with Tauri

2024-07-26 Thread Araq
What is the benefit over `browsers.openDefaultBrowser`?

The lowest possible module(s) of graphics in Nim?

2024-07-25 Thread Araq
I shared my vision here: That was a year ago. Since then development has not stopped but I never found the time to evaluate the existing solutions.

How to Pass Props to Components in a Custom Nim DSL?

2024-07-24 Thread Araq
I don't understand what you try to accomplish I documented how Karax works in my book and you can also study Karax's source code.

How to Pass Props to Components in a Custom Nim DSL?

2024-07-24 Thread Araq
Use Karax's DSL which also works for native code and doesn't require JS code generation.

Compile times normal or my fault?

2024-07-24 Thread Araq
We keep getting reports of the latest GCC producing all sort of issues, so that might be your problem too.

Tooling update

2024-07-24 Thread Araq
> Will the next release of Nim 2.2.0 include Nimble 0.16.0 ? Yes.

Requirements for an imperative language amenable to sql-like optimizations

2024-07-24 Thread Araq
What you say is true but very important lessons are missing here: ;-) 1. An imperative loop nesting structure can be optimized "by hand" and for quite some people the resulting system is more pleasant to work with than looking at strange graphs from a query optimizer trying to deduce where to

first impression, strange `=destroy`

2024-07-24 Thread Araq
We have 6 of these type based hooks why use keywords for all of them. Also, they are used rarely, the compiler generates them just like in C++.

varargs[untyped] in template

2024-07-23 Thread Araq
Use a macro.

Need Help with Nim Compilation Time and File Size Issue

2024-07-23 Thread Araq
`autolayout` generates an unreasonable amount of code.

Need Help with Nim Compilation Time and File Size Issue

2024-07-23 Thread Araq
Why would I know, I'm not an expert on GCCs internals. But it's an unreasonable amount of code either way and the macro should generate data instead of code or maye even code for some adhoc virtual machine.

The lowest possible module(s) of graphics in Nim?

2024-07-23 Thread Araq
One option that is worth considering is also to link SDL statically into your app.

The lowest possible module(s) of graphics in Nim?

2024-07-23 Thread Araq
Well it's OS dependent. On Windows you can use the Windows API or Direct X and on Unix you can write your own device driver.

Using a template as variable-section

2024-07-23 Thread Araq
The major problem is that doesn't make anything "cheap" as it only invites wrong transformations where the state in local variables is not shared between as you split up your procs.

Using a template as variable-section

2024-07-23 Thread Araq
> you may have to move your declarations to the common section again... Nah, that's a terrible idea promoted by Pascal. Declare variables where you use them in the smallest possible scope.

Blog post: How Nim's runtime checks are optimized out

2024-07-23 Thread Araq
Interesting, thank you! So we should focus on producing code that let's GCC know that `len >= 0` and in general promote the usage of int32 over int. What are your conclusions?

How to Efficiently Implement Microservices with Nim?

2024-07-22 Thread Araq
No reply from original poster. It was a bot. Sad.

generic type constraint to size

2024-07-20 Thread Araq
Easy: proc createT[T](x: T): T= static: assert sizeof(T) == 4 result = x Run

Small libraries you'd like to see ported to Nim?

2024-07-20 Thread Araq
Maybe you guys should read more than the headline...

Small libraries you'd like to see ported to Nim?

2024-07-18 Thread Araq
.NET's or JVM's bytecode might be an option. A gazillion of libraries and you don't have to concern yourself with Java's or C#'s obscure grammar corner cases. If you don't like to work on the binary files (and who does) run it through a disassembler first, there are a couple around.

Small libraries you'd like to see ported to Nim?

2024-07-18 Thread Araq
Check out my NIF project. It's similar, but without the JSON (which is illsuited for ASTs and compilers):

LamdaConf 2024

2024-07-18 Thread Araq
Here is my talk: [https://www.youtube.com/watch?v=MIITSTQok-4&ab_channel=LambdaConf](https://www.youtube.com/watch?v=MIITSTQok-4&ab_channel=LambdaConf) Please excuse my - err - thinking pauses, the jet lag was massive that day.

German strings

2024-07-18 Thread Araq
Remove the l-value modifier, it causes trouble for almost every decent string implementation.

Small libraries you'd like to see ported to Nim?

2024-07-18 Thread Araq
> The current focus is on Go (golang) because i think it is relatively similar > to Nim or a subset of Nim Nah, Go is very different with lots of idioms that make no sense in Nim. > I will consider it a success if it is able to translate ~80% of the > constructs to idiomatic Nim code. I hate t

Software design ideas to deal with ownership when writing high level wrapper of C code

2024-07-17 Thread Araq
And then you write the rest of your program passing `ownership: static Ownership` around, pretending that you can write code that doesn't care about ownership? But if so, that means you want the `Borrowed` flavor...

Software design ideas to deal with ownership when writing high level wrapper of C code

2024-07-17 Thread Araq
So wrap it inside a type that keeps an `isOwned: bool` field around. Or better yet: A refcount that supports a special value `unowned`.

Shared heap and foreign thread interaction

2024-07-17 Thread Araq
It's complex. Assuming that it's always called from the same thread, things should be just fine. Otherwise you might get leaks due to excessive thread local storage that isn't freed properly. Best is to compile with `-d:useMalloc` and ask Valgrind about it.

Allocator & garbage collection.

2024-07-17 Thread Araq
Please read: Allocators can be changed too but the used GC must be compatible with it. Read lib/system/osalloc.nim for details. An allocator must implement this interface: proc osTryAllocPages(size: int): pointer proc osAllocPages(size: int):

German strings

2024-07-17 Thread Araq
What's the problem with the prefix for mutable strings? It's like C++'s short string optimization which doesn't cause any problems wrt mutability either.

Nim 2.2.0 RC1 available

2024-07-17 Thread Araq
Ignoring the most recent embarrassing regressions the 2.2 release focusses on performance&stability (and somewhat on internal compiler refactorings).

German strings

2024-07-16 Thread Araq
Thanks for sharing, most interesting read! German strings are close to my new ideal string implementation. Which Nim 2 sadly does not implement...

Fusion OS: a hobby kernel written in Nim

2024-07-16 Thread Araq
A soon as you type your channels you run into composability problems as you cannot easily wait for _either_ Channel[T1] or Channel[T2]. Rather than avoiding signals I would embrace them as a general purpose interrupt mechanism. And an interrupt can be scheduled on a different thread. And then I

How to do something like std::construct_at and std::destroy_at? (with correct alignment)

2024-07-16 Thread Araq
Looks ok, I don't know if it can be simplified. But you just use `uint` instead of `BiggestUInt`. `uint` is guaranteed to be pointer-sized.

Fusion OS: a hobby kernel written in Nim

2024-07-16 Thread Araq
Very nice. What API do you plan to offer? Anything better than Posix? ;-)

how to make macro returning comma separated parameters

2024-07-15 Thread Araq
It's impossible because `v.x, v.y` is not a tree (AST). But you can transform more than that like in `expandVec2(f, a, b)` producing `f(a.x, a.y, b.x, b.y)`. But frankly, just type it out, macros are not for saving typing effort.

Is there any way to hook ref replication or destruction?

2024-07-15 Thread Araq
With `--expandArc` you can see where the hooks are injected but you cannot override ref's hooks. You can edit `lib/system/arc.nim` and add some tracing there.

execution exe error: could not load: sqlite3_64.dll ,ENV:win10 gcc mingw64 nim 2.08

2024-07-14 Thread Araq
Use the DLL from `\bin`. Nothing funny about it.

How to do something like std::construct_at and std::destroy_at? (with correct alignment)

2024-07-14 Thread Araq
Maybe like so: proc inPlace() {.nodestroy.} = var dest = cast[ptr T](addr buffer) dest[] = constructT() Run

execution exe error: could not load: sqlite3_64.dll ,ENV:win10 gcc mingw64 nim 2.08

2024-07-13 Thread Araq
Put the DLL next to your .exe file or update your PATH environment variable.

nim-general@lists.nim-lang.org

2024-07-13 Thread Araq
I think it works just fine for anything but `cstring` or `char` which is underspecified in C and so we generate casts to force unsignedness.

Why cstring destructor is not being called here?

2024-07-13 Thread Araq
File a bug report for that, it looks like Nim's cursor optimizer doesn't understand that `distinct cstring` can be an owning type.

Why cstring destructor is not being called here?

2024-07-13 Thread Araq
DO NOT MIX C's `malloc` with Nim's `dealloc`!

How Can I Ensure Backward Compatibility with Destructors in Nim 2.0?

2024-07-12 Thread Araq
Correct, use that. :-)

is there any progress in NIF? And what is this?

2024-07-11 Thread Araq
Well the sem AST is works better for generation (arbitrary nesting makes things easier) than it works for analysis (arbitrary nesting sucks). Things might improve if macros gain a capability like "return expression X but as a side-effect add this T to some toplevel hidden type section" but this

Going from 2.0.6 to 2.0.8 & errors

2024-07-10 Thread Araq
Dunno, I would start with "make pop use a `move` and use a coding style that the compiler doesn't have such a hard time to understand".

is there any progress in NIF? And what is this?

2024-07-09 Thread Araq
This is close to what Nim pre version 1.0 tried, tracking all the original ASTs before template/macro expansions. It caused exponential memory consumption and was abandoned. Clever schemes don't help with exponentials. Also, what problem does this solve? > So when designing transformations, we

static inline

2024-07-09 Thread Araq
Import it from the header file via `.header`

Cross-Compile Native Gui Apps with uing

2024-07-08 Thread Araq
Nice article, thanks for sharing! I never saw the value in cross-compilations for non-embedded targets, but that's probably just me. (You need to test the result on every supported platform anyway, why does the compilation step matter?)

Atlas shrugged...

2024-07-07 Thread Araq
No, that is not supported (in the sense that I never gave it much thought and don't know if it works). But it's a good idea. :-)

Problem with a highly recursive function

2024-07-07 Thread Araq
It's not `refc` as you don't allocate memory anyway, it's the implied `--exceptions` switch. Use a `.quirky` annotation or compile with `--exceptions:setjmp` or compile as C++ (`nim cpp`)...

is there any progress in NIF? And what is this?

2024-07-07 Thread Araq
It's not entirely clear to me why `HiddenType` in your example would benefit from a `%change, derivedTypeof%` annotation.

is there any progress in NIF? And what is this?

2024-07-07 Thread Araq
What is an "info prefix"? What does it do?

Nimble incorrect package structure warning: What is going to be?

2024-07-06 Thread Araq
> If not, do you accept PRs to remove it? Oh god yes! Bring it on!

Why is the implicit `result` so widely used?

2024-07-06 Thread Araq
You can use procs and templates to avoid excessive nesting and then you can still see the join points in the control flow graph, whereas you lose them with `return`. But hey, what do I know about formal reasoning...

Problem with a highly recursive function

2024-07-06 Thread Araq
Surely there is a way. Use the Y combinator. :P

Why is the implicit `result` so widely used?

2024-07-06 Thread Araq
The decision tree is there whether you use indentation to outline it or not. If you don't like indentation, fine, but then assembler becomes very attractive.

is there any progress in NIF? And what is this?

2024-07-06 Thread Araq
NIF now has a spec:

Issue with memory managment. SIGBUS: Illegal storage access when using Sokol makeImage

2024-07-04 Thread Araq
The address of a sequence is where the sequence resides in memory. It just so happens that it stores the size and capacity before its elements (how else would it work?). To get the address of its first element, use `addr s[0]`. This expression also works with arrays so you don't need any special

Am I losing something by learning Nim without learning C/C++?

2024-07-02 Thread Araq
Mostly they are covered by these two RFCs: * *

simpleargs - Dead simple CLI parsing.

2024-07-02 Thread Araq
FWIW the reason why I never wrote a DSL for command line parsing is that `parseopt` combined with Nim's `case` construct that works on strings offers the 80% solution that is good enough for me. A nice addition to `parseopt` would be though if it counted the arguments and options automatically.

A way to get a real argument type in a proc call?

2024-07-02 Thread Araq
Use a `typed` macro.

StableSeq

2024-07-02 Thread Araq
`StableChain`. I like it. (After all these proposals I still like "stable" best and it is commonly used for this idea in the C++ world.)

StableSeq

2024-07-01 Thread Araq
`StableList` (or `PinnedList`) makes no sense though as every commonly used list is "stable".

StableSeq

2024-06-30 Thread Araq
4. Well because I have no `=copy` hook yet either, see the question about it. As for your other questions, the stdlib algorithms predate `concept`.

StableSeq

2024-06-30 Thread Araq
Well this discussion got somewhat out of hand. I'm mostly interested in the naming. Say we have a `PinnedSeq` then we can also think about a `PinnedTable` and the stdlib has no name for the new "add and return ptr to the created element" operation.

StableSeq

2024-06-30 Thread Araq
If I wanted a tree/trie/FingerTree/SkipList I would have asked for it... But I'm after something that in C++ is called "colony", see and

Problems debugging an app made with the wxpython library imported through nimpy

2024-06-30 Thread Araq
Compile with ARC/ORC and `-d:useMalloc` and ask Valgrind. GDB usually reports some problem long after the actual corruption occured and is mostly worthless IME.

StableSeq

2024-06-30 Thread Araq
That only makes `append` slower plus about 50% of all data is in the last chunk anyway. Exploiting this knowledge would be much better than a BTree structure.

  1   2   3   4   5   6   7   8   9   10   >