Webview style UI with Tauri

2024-07-28 Thread mildred
What I'd like to do is to have server side UI using a WebView, for apps that needs rich UI. Something like htmx, but for the moment, all webview UIs are focused on JavaScript UI code instead. I'll probably get this rolling when I have time and need for this in a next project.

Requirements for an imperative language amenable to sql-like optimizations

2024-07-28 Thread mildred
By the way, I was thinking lately that I'd like a database engine where I could specifically tell how to fetch the data and what index to use, the compiler yelling at me if I try something impossible, rather than relying on declarative SQL, and depending on guesses from the query optimizer for p

Webview style UI with Tauri

2024-07-27 Thread mildred
Proper system intégration, no browser UI, no leak over localhost

Webview style UI with Tauri

2024-07-26 Thread mildred
When a webview style UI is required, I looked towards [Tauri](https://tauri.app/) as it provides a mean to create full apps using the system webview (the webview is not bundled within the app itself like electron and so many others). However it was not possible to use it with Tauri. Very recent

Atlas shrugged...

2024-07-15 Thread mildred
Well, I have ~/Projects for all my projects, Nim or else. There I clone all my repositories and I'd like to avoid having a nested directory structure if possible, and avoid cluttering ~/Projects with Nim stuff. So I have ~/Projects/app cloned, and if I can optionally tell it to use ~/Projects/l

Atlas shrugged...

2024-07-14 Thread mildred
Can you use Atlas without a workspace? That's a thing I loathen with Go when they mandated a gooath. I just want to have my repository where I wish and not necessarily in a workspace. Dependencies fetched to ~/.nimble are fine.

Claude 3.5 (Sonnet)

2024-06-29 Thread mildred
I don't think we can replace programmers, except for boilerplate code, any time soon. Often when I ask a bit more about the spec I am given, I see that it either contradict itself or something else specified before... then it's back to the drawing board. I don't see how an AI can do that correct

Cheap exceptions, opinionated error handling

2024-06-03 Thread mildred
It boils down to the user of a specific function that either : * wants to ignore the error if there is any, and let the error bubble up the call stack without manual code for it * want to handle the error in case it happens because this is significant to the code Why not something like a

Cheap exceptions, opinionated error handling

2024-05-30 Thread mildred
Why not some solution like Go: use cheap exceptions (with ErrorCode) for things like out of memory that are seldom handled usefully but use return codes for errors that should be handled by the programmer (network error, HTTP error status, ...) The problem lies that it's the standard library th

Cheap exceptions, opinionated error handling

2024-05-29 Thread mildred
Sometimes you need additional context on the error, for example when erroring out because a spawned process fails, the error code or kill signal could be useful. Also, when handling the error, it's often useful to know what the program was doing. For example in an IOError, knowing the file path

Windows command injection CVE - Nim affected too

2024-05-02 Thread mildred
There is no way on Windows to properly escape command-line arguments, such a thing does not exists on the OS level it seems... Only command-line string and each program is free to handle it as it wants with different escaping mechanisms...

Sum types, 2024 variant

2024-01-08 Thread mildred
Would it not be possible to have anonymous union types that convert to a broader union type automatically? This would avoid partially instanciated enum while allowing the same kind of uses, no? template makeError(code: int): enum of Le: string = result.Le = codeToString(code)

proc/func/method: syntax

2023-11-17 Thread mildred
I believe everybody is afraid to have their code being now incompatible. This must be a joke.

NIR

2023-11-17 Thread mildred
Using something like LLVM IR can be good if you want to use the LLVM framework, but it is designed to generate assembly code, not C code, and it'ß designed around the C language, it would probably miss a few features for Nim.

Cosmo3 multi-os fat binaries with threads

2023-11-08 Thread mildred
If one wants to implement coroutines in pure C, setjmp and longjmp is probably not the thing to use as it does not allow to have a separate C stack for each coroutine. One should probably use makecontext and swapcontext on stacks allocated with mmap (with MAP_GROWSDOWN, lighter than malloc). [c

Cosmo3 multi-os fat binaries with threads

2023-11-08 Thread mildred
I found this article very insightful around the async problem: > What language isn’t colored? > > [...] Three more languages that don’t have this problem: Go, Lua, and Ruby. > > Any guess what they have in common? > >

Nim boilerplate

2023-10-13 Thread mildred
> If you feel the need for it, feel free to use some interface macro. And not > again this "it needs to be in the stdlib!". Point (2) applies for "must be in > stdlib" too. Well, I'm the one who suggested than an interface macro should be in the stdlib and I feel somehow bad for it. In fact wh

Nim boilerplate

2023-10-11 Thread mildred
lt;https://github.com/mildred/iface>

Why is building the community and ecosystem such a struggle?

2023-10-09 Thread mildred
Do we really have a problem with the Nim forum? I don't think so. We don't have thousands of posts a day, but perhaps that's just because people using Nim do not necessarily need to post to the forums too often. Growing number of posts on the forum might not be correlated to growing users of Nim

idea : reuse libraries from other languages

2023-10-06 Thread mildred
It's a bit different than Node or CPython, Go is a compiled language, and with a standard library that relies on the libc instead of their specific runtime, it could work like a standard C library. But it seems they are only targetting wasm for the moment, so perhaps that's not a so goo idea.

idea : reuse libraries from other languages

2023-10-06 Thread mildred
Recently, I saw this news: [a new stdlib for Golang](https://news.ycombinator.com/item?id=37744563) which removes the Go runtime, produce small binaries and should be mostly compatible with C. Go is known to have a really good HTTP implementation so that it is used in various production grade r

Nim version 2.0.0 is here

2023-09-28 Thread mildred
Is there a documentation explaining the new memory model with Nim 2.0 ? As I understand the gcsafety is a little different and there is the new isolate, but I'm not sure where this is described in details. The manual does not explain it that much.

How to update a nimble package?

2023-08-23 Thread mildred
The problem I had was not with pkgs/pkgs2... I do not have the package in pkgs, only in pkgs2. Given the answers, I suppose the `rm -rf` way is correct although I find it bizarre. It would be great to have a `nimble update PACKAGE` command.

Convert back cstring to string

2023-08-22 Thread mildred
Hi, I wanted to know if it was possible to convert back a cstring to a string. Specifically, I'm binding to sqlite for user functions and when the user function returns a string, it provides a cstring as result value and a destructor callback called when the string is no longer used by sqlite i

efficient way of running proc at a given time, that can be changed

2023-08-22 Thread mildred
It looks like linux have timerfd :

efficient way of running proc at a given time, that can be changed

2023-08-22 Thread mildred
libev and libevent both seem to have a timeout event it can handle. You can either use them, or look at how they done it and do it yourself:

How to update a nimble package?

2023-08-20 Thread mildred
I just wanted to know how I could reinstall the latest version of a nimble package (the update command of most package managers), especially when the said package does not have version numbers.

How to update a nimble package?

2023-08-19 Thread mildred
What's the best way to update a nimble package? For example, I just updated a package of my own, and pushed it to Git, and I have another project that uses this packages and need the new version. I'm not using `nimble develop` mostly because I no longer need it (this is a small correction/addit

Neo vim config for nim

2023-08-13 Thread mildred
I usually don't have issues but currently nimsuggest is crashing on me on the project I'm working on... My nvim config looks like: Plug 'neovim/nvim-lspconfig' Plug 'alaviss/nim.nvim', { 'for': 'nim' } " for coloring at least ... lua <

IPv6 compatibility (dual-stack AF_UNSPEC)

2023-08-11 Thread mildred
The problem is that it's too easy to create IPv4 only libraries / apps using `newSocket` then `connect` instead of `dial`. Perhaps `connect` using a string address should be deprecated at some point. Only `connect` using an address object should be allowed.

IPv6 compatibility (dual-stack AF_UNSPEC)

2023-08-11 Thread mildred
A solution could be to have `newSocket` not actually create the socket until either `bind`or `connect`/`connectUnix` is called, and then detect the correct socket domain from the address given in each case. Or instead of going through `newSocket` and `connect` one should just use `dial` to crea

IPv6 compatibility (dual-stack AF_UNSPEC)

2023-08-11 Thread mildred
I'm getting dual-stack wrong... The correct way of doing things is to: * run getaddrinfo with AF_UNSPEC * create the socket after that using the domain (AF_INET or AF_INET6) returned by getaddrinfo The problem is that the Nim standard library does things in the wrong order, it first crea

IPv6 compatibility (dual-stack AF_UNSPEC)

2023-08-11 Thread mildred
Well, do I need to have a development version of the Nim compiler around (and perhaps use choosenim to switch to it so I can build my projects with it) or can I just have a development version of the standard library and tell the compiler to use it instead of the standard library bundled with th

IPv6 compatibility (dual-stack AF_UNSPEC)

2023-08-11 Thread mildred
Hi, I'm often deploying server apps on the IPv6 stack, and I find that Nim is quite lacking in this regard. I believe by default, sockets are only bound to AF_INET (which means IPv4 only) while normally on C it defaults to AF_UNSPEC if not manually defined (which means dual stack). I opened a b

Nim Sucession Plan

2023-07-03 Thread mildred
Thank you for standing in the shitstorm that the technological field has become, hopefully not everywhere. I stand with you.

Wishlist: Ideal UI library for Nim

2023-06-28 Thread mildred
My 2c on this, I believe that to be able to pull that off, using a native framework (Gtk, Windows API, ...) is required in order to handle the native behaviour of the platform. It's not that complicated to be able to make an UI framework that can draw basic widgets, but once you want unicode, te

How to cast or pass a {.closure.} as a callback to a C API with userdata pointer?

2023-05-06 Thread mildred
store this tuple alongside the C wrapper object so I have the guarantee that its lifetime will match the C object lifetime. Code is here: <https://github.com/mildred/easy_sqlite3/blob/ae9cde848debf023196ff9a53d82d00533b71c4c/src/easy_sqlite3/bindings.nim#L506> For the future here is the r

How to cast or pass a {.closure.} as a callback to a C API with userdata pointer?

2023-05-06 Thread mildred
Hello, I've been using Nim for a little while but until now I never dig in that space of C API, at least not enough to encounter C callbacks. I want a simple thing, pass a function pointer to C code and get the C code call my proc later on. Luckily enough, the C API provides a userdata pointer

How can I return a tuple of arrays from a proc. Having difficulty with proc signature

2023-05-03 Thread mildred
* tuples with anonymous field names: `(int, int)` * tuples with named fields: `tuple[a: int, y: int]` yes it would be great to be able to write `tuple[int, int]` and have a tuple with anonymous field names.

Nim v2 and gcsafe

2023-04-12 Thread mildred
Isn't gcsafe going to disappear with arc/orc as refcounting removes the need to have a per thread garbage collector that needs safety?

Nim v2 and gcsafe

2023-04-12 Thread mildred
I started compiling some of my projects with Nim v2 and I get a lot of errors about gcsafety that I did not have with 1.6. Some nimbles are not gcunsafe, docopt does not compiles any more and nauthy is no longer gcsafe. I was under the impression that gcsafe would be a lot relaxed with arc/orc,

Nim v2.0.0 RC2 is out

2023-04-11 Thread mildred
What about the idea that came up here at some point that the stdlib could just be a list of curated nimbles, maintained or at least selected by the Nim compiler developers? With stdlib being nimbles, we can imagine that a next version of the compiler will re

Why Svelte is far superior than React (Karax)

2023-03-29 Thread mildred
The problem is not really the inavailability of closure iterators but the fact that you invest some time into creating code and discover that il will never work, abd then you wonder what else can surprise you...

Why Svelte is far superior than React (Karax)

2023-03-27 Thread mildred
sted I expanded them here: <https://github.com/mildred/webmsg-webmail/blob/master/src/utils/store.js>

Why does Nim compiler allways depends on another's language compiler?

2023-03-17 Thread mildred
Having worked on another language that targetted the C language, and having looked at that time for a LLVM backend, the most problematic thing with the C backend was when the C code had errors and failed to compile. You get C errors that are difficult to trace back to the original code. However

Nim in production: 350+ HTTP requests per second on a very modest VM

2023-03-07 Thread mildred
That's great, I might contribute to code that lets the server listen over multiple sockets at the same time, and use socket file descriptor inherited from the environment. I'm struggling with HTTP servers in Nim because of that. Ideally I'd want to do systemd socket activation, and I also have

Nim in production: 350+ HTTP requests per second on a very modest VM

2023-03-07 Thread mildred
For static files, I would have thought of something like X-Sendfile or X-Accel-Redirect:

How to listen to an IPv6 address but also allow IPv4

2023-02-04 Thread mildred
I copy-pasted the dial code from the stdlib, made it work with async sockets, replaced connect with bind and here it is: <https://github.com/mildred/stalwart-gw/blob/master/src/utils/parse_port.nim>

How to listen to an IPv6 address but also allow IPv4

2023-02-04 Thread mildred
I believe I have to use dial:

How to listen to an IPv6 address but also allow IPv4

2023-02-04 Thread mildred
If you want to look at the code it's here although I believe it's not necessary to understand the issue: <https://github.com/mildred/stalwart-gw/blob/master/src/stalwart_gw.nim#L63>

How to listen to an IPv6 address but also allow IPv4

2023-02-04 Thread mildred
I'm writing daemons in Nim, and I fail to get it working with IPv6 My nim code uses a socket created by `newAsyncSocket()` from `asyncnet` and uses `bindAddr` to bind the socket to an address specified on the command-line. The bind address is specified in the form of a hostname and when the host

how can I buy "Mastering Nim" without using amazon services?

2022-10-24 Thread mildred
I made an exception and bought it via Amazon. Recently I have been using to print some PDFs I had for my personal convenience, and it's quite nice. They offer for book authors a service where you can sell your book in paper form too. Just give them the PDF and some details ab

Nim v2: what would you change?

2022-08-19 Thread mildred
there is no way you can load NimScript at runtime without embedding the nimscript interpreter at run-time, and increasing your executable size. The nimscript interpreter being the same as the nim compiler.

let variable is not gc safe

2022-07-30 Thread mildred
Being global variables, their lifetime should be infinite, so I believe the must always be gcsafe. Is that the compiler that does not understand that global variables cannot be garbage collected?

could javascript backend make use of new javascript ES6 module support?

2022-07-26 Thread mildred
Supporting ES6 modules (the compilation generates a single module) can be very useful. I recall trying to include in a web page, two different javascript files, each compiled from Nim, and there were incompatibilities created because each file had global symbols defined that did not work well wi

Error: both asyncdispatch.await and asyncmacro.await match, but asyncmacro is not imported

2022-07-22 Thread mildred
Here is the await declaration line 128: > > template await*[T](f: Future[T]): auto {.used.} = > var internalTmpFuture: FutureBase = f > yield internalTmpFuture > (cast[typeof(f)](internalTmpFuture)).read() > > > Run I suspect that there is an ambiguity with ge

Error: both asyncdispatch.await and asyncmacro.await match, but asyncmacro is not imported

2022-07-22 Thread mildred
I am trying to compile [a project that I did not touched for a bit of time (nimnews)](https://github.com/mildred/nimnews), and now when I compile it I have the following error: $ nimble c -d:ssl src/web/newsweb ... src/nntp/protocol.nim(136, 15) Error: ambiguous call; both

interoperable stream type

2022-05-12 Thread mildred
Well, apparently we are not there yet...

interoperable stream type

2022-05-12 Thread mildred
I was under the impression that asyncsteams was a generic stream of futures, could it work for a byte stream. I need to be able to read/write whole chunks of data of arbitrary length, and signal for end of file. I'll look into it. I also saw which is p

interoperable stream type

2022-05-12 Thread mildred
Hello, I'm coming from the Go language, and there there are nice I/O interface types : `io.Reader`, `io.Writer`, and similar. Those are interfaces types meaning that it can be backed by any implementation and those types can be used anywhere in the language to represent readable or writable str

Nim v2: what would you change?

2022-05-12 Thread mildred
I remember that in a past communication the v2 was supposed to deal with the standard library problem, outline I believe in The idea was to transform the standard library as a collection of approved nimble packages, allowing to replace packages in f

Nim v2: what would you change?

2022-05-11 Thread mildred
Please don't bring too many breaking changes. Each project written with an old Nim version will have to be ported over or die. We already don´t have as much libraries as we would like. If it's required to have a better language (I left where the sole breaking change of 2.0 would have been chang

Nim is just so great, works first try

2021-08-06 Thread mildred
Hello, I just wanted to thank all those involved in the Nim language itself. I just finished coding a replication feature on a small web service that manages accounts, and it worked first try. I got a load of compile errors, but after solving them all, I just tested it, and no exception, no bug

Safe `enum` conversion

2021-07-03 Thread mildred
Just trolling, but that's why in Go, type casts also return a boolean for you to check, and since it's a tuple result, you have to handle it instead of chaining your value to something else. Couldn't this be implemented in a macro returning an `Option[X]`? type X = enum Z

nim-ws - websockets for Nim

2021-07-03 Thread mildred
Let me reply on the side for > By that definition pretty much all lines are problematic since most of them > can throw. Nim isn't Go and for a good reason, writing error propagation > logic manually is a waste of time. I kind of disagree with that. Sure, in Go you have to write the error logic

Pragma to restrict procedure to main thread?

2021-07-03 Thread mildred
Thank you, I was more expecting a compile time pragma, but that would do. Just a question, I could not find `mainThread` in the library documentation. Where can I find it? Thank you

Cannot make async futures work with the fidget GUI toolkit

2021-07-02 Thread mildred
That simple, it makes sense. I thought fidget did that already since it uses internally futures for its own HTTP get requests. Reading the code more closely it seems you're right:

Cannot make async futures work with the fidget GUI toolkit

2021-07-02 Thread mildred
ST requests instead of GET requests, so I instantiated an `AsyncHttpClient` object. However, when I make the async call, I never get in the future callback, or past the `await` in the async proc. The async proc looks like this ( [jmap/transport.nim](https://github.com/mildr

Pragma to restrict procedure to main thread?

2021-07-02 Thread mildred
Hello, I was wondering if there was a pragma to restrict the use of some procedures to the main thread. The use case I have is that I did some bindings of the glibc DNS resolution procedures in the [resolv](https://github.com/mildred/resolv.nim/) nimble, and I believe that the glibc

Use cstring for C binding

2021-07-01 Thread mildred
`str.len` is the actual length of the string. it's equal to its capacity when allocated with `newString(cap)` but after it has been used, and more specifically after `str.setLen()` has been called, it does no longer contains the capacity. It's just that I'd prefer to rewrite: cons

Use cstring for C binding

2021-07-01 Thread mildred
Thank you very much for the detailed information. I just learnt that strings could have a capacity different from their length (might be useful for mutable strings). Is there a way to access this capacity from the code?

Use cstring for C binding

2021-07-01 Thread mildred
Hello, I'm trying to bind to C code, and I have various questions around C strings (cstring) As I understand, cstring is suitable for both const strings in C (`const char*`) as well as mutable strings (`char *`, as long as the length is respected). Now, I need to pass a string buffer to a C fun

How to unwrap a seq to a varargs[] procedure argument?

2020-11-28 Thread mildred
Thank you, I didn't think I'd need to use macros but I succeeded with: import macros macro log_macro(level: LogLevel, message: string, args: varargs[untyped]): untyped = result = newCall("log", newIdentNode("console"), message) for i in 0 ..< args.len: result.

How to unwrap a seq to a varargs[] procedure argument?

2020-11-28 Thread mildred
I wanted to customize a log procedure, and add log levels which would log the message or not depending on the log level. The proc looks like: proc log(level: LogLevel, args: varargs[JsObject, toJs]) = discard Run I wanted to call `console.log` from the `jsconsole

std/tables [] vs. add()

2020-11-22 Thread mildred
I didn't think mgetOrPut().add() would work, I was under the false impression that it was necessary to assign back the seq in the table after the add operation. I probably programmed too much in Go lately. Thank you, it does the job perfectly.

tables.add() deprecation in favor of []= is wrong

2020-11-21 Thread mildred
Note: the linked benchmark at are wrong. There is overhead to using seq[T] over a table: adding an item must perform a lookup to know if a seq exists (then append to it and store it) or not.

std/tables [] vs. add()

2020-11-21 Thread mildred
When replacing `Table[string,string]` with `Table[string,seq[string]]` how do you efficiently add an item to the table? I came up with: result[key] = concat(result.getOrDefault(key), @[value]) Run But it requires a lookup, a concat and a store. Is there a better way?

tables.add() deprecation in favor of []= is wrong

2020-11-21 Thread mildred
Found some interesting discussion here:

tables.add() deprecation in favor of []= is wrong

2020-11-21 Thread mildred
Most keys are not duplicated, and fast indexing may help there. Only the odd key may need to iterate over the table to discover all its values. In fact, I got the impression that Tables were explicitly able to deal with duplicate keys, and I started using them for this purpose. If this is remove

tables.add() deprecation in favor of []= is wrong

2020-11-21 Thread mildred
With Nim 1.4, there is a deprecation warning **Warning: Deprecated since v1.4; it was more confusing than useful, use `[]=`; add is deprecated** that I believe is wrong. `[]=` and `add` are doing two very different things for tables. * `add` is adding a new pair to the table, which may result

How to make code GC-Safe when a global constant is used in a proc ?

2020-11-18 Thread mildred
I managed to reduce gc insafety in my codebase to few things only: * [scram](https://nimble.directory/pkg/scram), client package (shown above) but it is actually gcsafe becaue when threads are enabled the global variable is replaced by a thread local variable * [scram](https://nimble.directo

How to make code GC-Safe when a global constant is used in a proc ?

2020-11-17 Thread mildred
The problem occurs when you try to use the library in a `{.gcsafe.}` environment when threads are disabled. Threads enabled, I suppose the use of thread local variable is helping. Outside of `{.gcsafe.}` context, there is no problem.

GC Safe Problem

2020-11-17 Thread mildred
The error message is quite understandable... The `ra` procedure is not gcsafe because it calls `rs` which itself is not gcsafe. `renderSQL` is not gcsafe because it calls `ra` which is not gcsafe. To understand why a procedure might ot might not be gcsafe, you should add `{.gcsafe.}` to it and

How to make code GC-Safe when a global constant is used in a proc ?

2020-11-17 Thread mildred
I got it wrong, when I replace `let` by `const` the code does not compiles.

How to make code GC-Safe when a global constant is used in a proc ?

2020-11-17 Thread mildred
The linked code solves GC safety when compiled with threads. The problem is that my procedure requires gcsafe even when not compiled with threads. The code: when compileOption("threads"): var SERVER_FIRST_MESSAGE_VAL: ptr Peg SERVER_FINAL_MESSAGE_VAL: ptr Peg

How to make code GC-Safe when a global constant is used in a proc ?

2020-11-17 Thread mildred
Replying to myself. gcsafe is needed because otherwise a global variable could be collected by multiple threads. Is there a way to mark an object as immutable and impossible to collect so it could be shared between threads ?

How to make code GC-Safe when a global constant is used in a proc ?

2020-11-17 Thread mildred
Hello, Since I upgraded my code to 1.4.0 and updates some dependencies, I have issues with my code. I have a warning that it is not gc-safe. Investigating (by adding the gcsafe annotation), I found out that a library I'm using is not gc-sage. Here is the code:

Which HTTP server library?

2020-11-16 Thread mildred
Looking at there are plenty of packages, but it seems only a limited number are web server libraries: * httpkit: does not even manages the transport layer * microasynchttpserver: does not seems featureful enough (cookies, form-data, ...) * httpb

Which HTTP server library?

2020-11-15 Thread mildred
Hello, For my nimnews package, I wanted to know what were the best HTTP server library options I had. For the moment, I'm using Jester but I'm not making use of the framework part at all as I prefer to split my code in procedure and not having to write all by handlers in the same place. For th