Nimforum 2.1.0 is here

2020-08-24 Thread jyapayne
@dom96 Awesome! Glad to see the updates I made finally shine through! As dom said, I'm open to thoughts and feedback! But I don't have much time these days to fix issues or work on the forum. For categories, my personal feedback would be to have a vote on which categories make it onto the forum

Nimforum 2.1.0 is here

2020-08-25 Thread jyapayne
@cblake You are incorrect about multiple categories. Right now, the forum only supports one category per post. I wanted it to be "tags", but it just didn't end up working out that way based on code reviews and dom's feedback. Perhaps it can be in the future though :)

How to know where a proc is defined - or: Newbie tries to get used to unqualified imports

2020-08-26 Thread jyapayne
According to the nim-mode github page: > jump-to-definition (M-., and M-, keys) > > find-references (M-? key) So try one of those bindings?

Problem with template and async

2020-08-28 Thread jyapayne
For some reason, the error is just wrong. Simply putting a discard statement in front of your bottom expression works: import asyncdispatch template test: untyped = return true proc main(): Future[bool] {.async.} = test discard waitFor main()

nim plus webdriver?

2020-09-15 Thread jyapayne
> Webdriver also targets a newer protocol than Halonium too IIRC. @dom96, that is not correct. Halonium supports both the old protocol and the new one that webdriver supports (just like Python's selenium). @Lecale, but dom is right. You can use whichever one :)

Cross-compile to Rpi4 :(

2020-09-15 Thread jyapayne
@kodkuce If you're running Raspberry Pi OS, it's still a 32 bit OS, even if the raspberry pi itself is 64 bit. You need to compile your code in 32-bit mode.

macro binary operator resolution

2020-09-17 Thread jyapayne
@nucleic, not sure if this is what you ultimately want (it's not that efficient), but here it is: import system, macros proc processLeftRight(l, r: NimNode): string = echo l.treeRepr echo r.treeRepr if l.kind == nnkInfix: result = processLeft

it there general gitignore configs for binaries?

2020-09-29 Thread jyapayne
I usually use something like this: * !/**/ !*.* *.exe # anything else you want to ignore Run The top section will ignore everything, then add back directories and anything with an extension. Kind of a hack, but it works.

Handling customisations when upgrading Nim

2020-10-17 Thread jyapayne
I usually use the git folder to upgrade my Nim installation. This allows me to have my own changes (in a patch file or a branch/commits). Then I can just apply the patch or rebase on top of a new release.

Order of execution: where to find understanding

2021-12-02 Thread jyapayne
@freeflow what programming language background do you come from?

Advent of Nim 2021

2021-12-03 Thread jyapayne
My (very tiredly written) aoc repo: <https://github.com/jyapayne/aoc2021>

simple event system

2022-01-09 Thread jyapayne
@enthus1ast, why not something using Nim's generics? Is there a reason you wanted to use pointers? For example, you could do something like this (made a little better with macros): import tables import macros type Callback[T] = proc (arg: T) Signal[T] = ref

simple event system

2022-01-10 Thread jyapayne
Ah, I misunderstood what you were trying to do. @Hlaaftana is correct, in order for type safety to remain, Nim needs to know what types you want to include in the event registry at compile time. I took a very brief stab at a rough version using macros (that can certainly be improved), and here's

simple event system

2022-01-10 Thread jyapayne
@sky_khan, your solution seems to work too, although I don't completely trust Nim's inheritance due to past issues. Maybe those are ironed out now though

NImScript task and using a shebang line

2022-02-09 Thread jyapayne
@hyl I use this in my gitignore for binary files: # Ignore all * # Unignore all with extensions !*.* # Unignore all dirs !*/ # all of your other rules Run

Macro fails with `got: but expected `

2022-02-17 Thread jyapayne
It might be a bug because this works: import macros type MyModel[T] = object discard macro network*(): untyped = result = quote do: proc init[WHAT](a: MyModel[WHAT]): MyModel[WHAT] = discard network() echo init(M

NimForum 2.2.0 - Fixes a big CVE!

2022-02-19 Thread jyapayne
I would like to add my thoughts about my experience in contributing to the forum. Overall, I really liked adding features and would have liked to add much more, including much of the basic functionality that is missing mentioned in this thread. However, the review process was very very slow and

SDL in a M1 Mac - can't find dylib

2022-03-09 Thread jyapayne
You should be using `LD_LIBRARY_PATH`. Also, you should not overwrite it but append to it like so: export LD_LIBRARY_PATH=/opt/homebrew/lib:$LD_LIBRARY_PATH Run

Have a nim tool in nimble installation error

2022-06-16 Thread jyapayne
Only thing I can think of is there is something wrong with your `.cache` directory. Can you try removing it and run the install again? rm -rf /home/ane/.cache/nim/nimterop Run

Illegal storage access

2022-07-24 Thread jyapayne
You can try using import segfaults Run In your main nim file. It might be able to give you a traceback.

Illegal storage access

2022-07-24 Thread jyapayne
Actually, I misunderstood the docs. Importing the segfaults module allows you to catch a segfault like you would an exception. So you could do: import segfaults proc main() = try: doSegfault() except: echo "segfault caught!" echo getCurre

Can't Get Length of Returned Table

2022-08-15 Thread jyapayne
That particular error has always been confusing. The primary helpful information is precisely what @sls1005 and @Hlaaftana suggested. You need to know the proc, the type, and ideally, the context you used it in. All the other overloads are useless unless you meant to use a different type, which

Need some direction on macros.

2022-08-19 Thread jyapayne
It sounds like you're in for a world of pain and/or fun :) Writing an interpreter is no joke, and it looks like you may need to account for complex behavior that has already been done by someone else. Might I suggest using an already made Javascript interpreter and see if that works for you? [D

Can't get basic example of creating reference objects to work. Compilation errors.

2022-08-21 Thread jyapayne
@enjoysmath, @Stefan_Salewski outlined your problem, but in case it got lost, it was that **you were trying to create a ref object and assign it to a ref ref object**. Arguably, this should be a compiler error because it doesn't quite make sense, but Nim gives you this flexibility if you someho

Fill array in C style

2022-08-22 Thread jyapayne
Not sure if there is a better/easier way, but this will only fill the array at compile time: template initArray[T](size: static int, value: T): untyped = block: var res: array[size, T] for i in 0 ..< res.len: res[i] = value res const a

Using return in templates returns nil

2022-08-27 Thread jyapayne
@NameUndefined, since the `pages` macro uses an `untyped` body argument, the macro expansion happens first, which transforms your code into an async procedure called `receivepages` that returns a future. Then your template gets expanded in that procedure without the async macro modifying the ret

Creating const in a macro fails in 1.9.1

2022-12-28 Thread jyapayne
In addition to @Hlaaftana's answer, if you don't need the data at compile time, you can do this to get it at runtime: import std/tables import macros import print type Metadata = object name: string id: BiggestInt var ALL_METADATA* = in

Send headers from server to client with httpbeast

2023-02-09 Thread jyapayne
@demetera, Nim is statically typed and has some type inference, so when you don't see a type listed, Nim's type inference is at work. The type of `headers` is a string, because Nim infers the type from the default value. `headers:string=""` could also be used equivalently. As for how to use tha

Trouble compiling libraries with cpp header

2023-02-11 Thread jyapayne
@sls1005 is right. `--cincludes` requires an absolute path. Alternatively, this seems to work: nim cpp -p:./src --passC:"-I./webview" --run examples/minimal/minimal.nim Run For the `-p` problem, you need to put a `config.nims` in your `examples/` folder with the conte

ffi: how to pass a value to c?

2023-02-22 Thread jyapayne
You are likely overthinking things. Your copyMem approach is technically correct but is equivalent to the simplest way, which is: proc altera_jinit*(js: var TapDriver) {.exportc.} = js.drstop_state = Idle ... Run The `var` parameter tells Nim to modify the

ffi: how to pass a value to c?

2023-02-23 Thread jyapayne
@shirleyquirk here is a working minimal example in Nim: type TapState* {.exportc: "altera_jtag_state", size: 4.} = enum ILLEGAL_TAP_STATE = -1, RESET = 0, IDLE = 1, DRSELECT = 2, DRCAPTURE = 3, DRSHIFT = 4, DREXIT1 = 5,

Orc RTTI: Is there a way to get Enum + Tuple type info?

2023-02-26 Thread jyapayne
I'm working on getting [a basic LLDB python extension](https://gist.github.com/jyapayne/396a45f7bd0f95b2e22e6389c79b4948) up and running for use in VSCode. Most things work, like I mentioned in the gist above, but I can't find type information for enums and tuples. Enum fields are

Orc RTTI: Is there a way to get Enum + Tuple type info?

2023-02-27 Thread jyapayne
> Maybe this means patching the generated object files. :-) How does that work? Does Nim currently do this for other things?

Are sequences the nim equivalent of python lists?

2021-03-10 Thread jyapayne
They are similar, as `@Yardanico` mentioned, but one caveat is that sequences in Nim can only be of a single data type. In python, you can do this: arr = ["string", 1, {"foo": "bar"}] Run whereas in Nim, you can only have a sequence of all strings, or all ints, or all

I want to use gecko driver headless.

2021-04-10 Thread jyapayne
As an example for halonium with headless, here's how to do it with chrome: import options, os import halonium proc main() = let session = createSession(Chrome, browserOptions=chromeOptions(args=["--headless"])) session.navigate("https://google.com";)

I want to use gecko driver headless.

2021-04-11 Thread jyapayne
@mnahito You could not before, but I've just added the ability to in version 0.2.5. Please update to the latest version and then you can hide the chrome driver console like this: import halonium proc main() = # hideChromeDriverConsole and headless give a comple

string split by {';'}

2021-04-15 Thread jyapayne
@masiarek2, what @GamzWithJamz is saying is that your string has control characters in it, and indeed no split is occuring, you just have some carriage returns and a newline in your string. You can see that split does nothing by doing this: import strutils var s = "foo\rba

XML parsing performance

2021-04-26 Thread jyapayne
@Araq is there any reason we can't have `--opt:speed` for regular debug builds? Using the code from OP yields this: # DEBUG nim c -r g.nim # Time taken: 14.058434 Run # DEBUG with --opt:speed nim c -r --opt:speed g.nim # Time taken: 3.76424

unzip multipart zip file

2021-04-26 Thread jyapayne
You need to concatenate all of the zip files into one file first, then extract that. See [here](https://unix.stackexchange.com/questions/40480/how-to-unzip-a-multipart-spanned-zip-on-linux)

XML parsing performance

2021-04-26 Thread jyapayne
Hmm, looks like `opt:speed` might interfere with debugging. Maybe we could have a new optimization flag for increasing speed of debug code? There's a gcc flag called `-Og` that increases speed without hindering debugging. From [here](https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html) > -

XML parsing performance

2021-04-27 Thread jyapayne
I assume that stacktraces will be unaffected, but it depends on what you mean by debugging. For me, I consider debugging to be mostly using gdb with the native debugging compiler option. But if you're talking about print debugging and using nim's stacktraces, that should be fine. >From [here](h

Getting varargs parameter from JS

2021-04-29 Thread jyapayne
@drkameleon, I believe this is a bug. Please report it on the Nim issue tracker. If you call the function from Nim, you get the expected result, but when calling from js, there is an error in the browser console and `params` is not defined.

Idiomatic way to run a process in the background and close it when appropriate?

2021-05-03 Thread jyapayne
You can look [here](https://github.com/halonium/halonium/blob/master/src/haloniumpkg/service.nim#L297) for an example in my halonium project. It currently will block until the webdriver process is connectable, but you'd have to find a way to determine that in your own code based on the executab

How to catch DOM exception in Nim code?

2021-05-10 Thread jyapayne
If you want a complete example using your code: import strformat import dom except DOMException import jsbind type # The stdlib's importc is broken for this type. DOMException {.importc: "DOMException".} = object type XMLHTTPRequest* = ref ob

Show Nim: Pixie now supports text layout and rasterizing, including rich text with styled spans!

2021-05-15 Thread jyapayne
@treeform Your library is awesome! I tried using it via your `bumpy` repo. One question, on my high dpi screen, the shapes drawn are very pixellated. Is there any way to enable high dpi support?

Concept containing seq of self

2021-05-18 Thread jyapayne
Looks like you have to use `typedesc T`. Not sure if that's a bug or not: type TreeNode* = concept t, type T t.children is seq[typedesc T] proc isRootNode*(self: TreeNode): bool = true type Numbers = ref object children: seq[Numbers] let

JS FFI - getting started

2021-05-25 Thread jyapayne
`table.setData` returns a `JsonObject`, so you have to capture that in a variable otherwise Karax will think that you want to use it as a `VNode` (even though you have it marked as discardable).

CSV: paring in js

2021-06-04 Thread jyapayne
@mantielero You can't read a local file like that in js (at least in recent browsers) because it is a security concern. Imagine any website being able to search and read through any of your files silently. You would need to do something like suggested [here](https://stackoverflow.com/questions/

Recursive iterator to unpack arbitrarily nested sequence

2021-06-19 Thread jyapayne
Sooo, modifying @shirleyquirk's solution, this seems to work: iterator flatten[T](source: openArray[T]): auto = ## Flattens an arbitrarily nested ## sequence when T isnot seq: for element in source: yield element else: for each in sour

RFC: Recursive iterator macro

2021-06-20 Thread jyapayne
Is anyone interested in a macro that could automatically transform an iterator into the factory proc version recommended in [the manual](https://nim-lang.github.io/Nim/manual.html#iterators-and-the-for-statement-firstminusclass-iterators)? I've been tinkering with one since [this discussion](ht

Recursive iterator to unpack arbitrarily nested sequence

2021-06-20 Thread jyapayne
Related to this discussion, I have created this RFC:

RFC: Recursive iterator macro

2021-06-20 Thread jyapayne
@cblake, just added that in an edit :)

Associating a type with a concept?

2021-06-27 Thread jyapayne
You can do something like this, although I'm not sure it's what you want: type NumTest[T] = concept x, y is_eq(x, y, T) is bool is_ne(x, y, T) is bool proc is_eq(x, y, epsilon: float): bool = x == y proc is_eq(x, y: float, epsilon: int): bool =

Weird import issue

2021-08-09 Thread jyapayne
@alexeypetrushin, is this surprising behavior? I think it should be expected since you are not importing `json_helpers.nim` inside `plot.nim`, and that's where the conversion inside the text proc happens. So there's no way for `plot.nim` to know about your json hook. You can modify the import o

Is there no way to pass a specific overload to a macro?

2021-08-27 Thread jyapayne
@treeform you could also do something like this: import macros import strformat type Stuff = object x: int y: int proc foobar(x: string): string = discard proc foobar(x: int): int = discard proc foobar(x: Stuff,

Concepts, undeclared field.

2021-09-01 Thread jyapayne
Seems unrelated to the macro expansion and instead is probably a bug with concepts. This is a minimal example that reproduces your error. Please file an issue on Github. type Loopable*[T] = concept x x.len() is int x[int] is T x.items is T iter

Beginer problem: Combine and alternate list

2021-09-13 Thread jyapayne
Here's a generic version that can also take uneven arrays/seqs: proc alternateCombine[T1, T2](arr1: openArray[T1], arr2: openArray[T2]): seq[string] = var place = 0 while place < max(arr1.len, arr2.len): if place < arr1.len: result.add($arr1[place

What is the role of the expression "{.importc.}" when transpiling to JavaScript?

2021-09-14 Thread jyapayne
@Serge importc is a bit of a misnomer. Really it should be `importffi` or something. It has the same effect as using the C backend, which is to import a foreign function.

importcpp call class method

2021-09-15 Thread jyapayne
Have a look at wxNim for lots of cpp binding examples:

importcpp call class method

2021-09-15 Thread jyapayne
You need to declare Foo as a parameter on the `sayHello()` proc definition. {.emit:""" #include class Foo { public: int data; Foo() {} void sayHello(void) { std::cout << "Hello from cpp" << std::endl; } }; void sayWorks(void) { std

Can I somehow share a C++ class with Nim, either by reading it from a dll or otherwise?

2021-09-17 Thread jyapayne
See my answer to this thread: You can also see [here](https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-importcpp-pragma) for the section in the manual.

undeclared NtAllocateVirtualMemory SysCalls

2021-09-22 Thread jyapayne
You probably need to give a code example. Try to make it as minimal as possible.

How to get files from onchange event in karax?

2021-09-24 Thread jyapayne
Unfortunately, I think the API was not understood when the code was written for FileReader. FileReader uses an event based API, so immediately running `resultAsString` will return too quickly as the file has not been read yet. It should be rewritten to something like: nclude karax

block-level change default type of int literals?

2021-09-26 Thread jyapayne
I think the problem lies in capturing `asI` in a recursive proc. Not sure if the VM can handle that or if it's supposed to. I generally avoid writing procs that depend on captured variables in macros. You can work around this by rearranging the code like so: import std/macros

Nim 1.6.0 RC2

2021-10-02 Thread jyapayne
Apparently, this company provides free signing for open source projects: Maybe it's worth a contact?

Design choice advice for Python-to-Nim transpiler (Python Devs)

2021-10-02 Thread jyapayne
This can be done in Nim as well, but you'd just have to translate the default for `add_two`: type Foo = object addTwo: proc(x: int): int var foo = Foo() foo.addTwo = proc(x: int): int = x + 2 assert foo.addTwo(2) == 4 var bar = Foo() b

Only one line will load. Need all lines in directory to load.

2023-03-19 Thread jyapayne
@Naterlarsen it's because the client is only receiving one message from the server and then waiting for input from the user. Can you figure out what to do based on that information?

Only one line will load. Need all lines in directory to load.

2023-03-19 Thread jyapayne
@Naterlarsen `recvLine()` is a blocking call. That means that while message != "": echo message message = client.recvLine() Run will keep going as long as the client is sending it messages. As soon as those run out, you're stuck in `message = client.recvLin

Only one line will load. Need all lines in directory to load.

2023-03-19 Thread jyapayne
Try out your idea and see what happens :)

Only one line will load. Need all lines in directory to load.

2023-03-20 Thread jyapayne
@Naterlarsen Here is a solution based on using a protocol where first the number of lines is sent, and then the lines. I made a couple improvements to your code as well. # client.nim import net import strutils import std/[times, os] let ip = "127.0.0.1"

Only one line will load. Need all lines in directory to load.

2023-03-21 Thread jyapayne
@gs, You're right that the server and client were the wrong way around. I used the original code as a base to try and not change it too much to make the change in steps more manageable for a newbie. But really, the code before the while loops in my version should be swapped just as you have don

Only one line will load. Need all lines in directory to load.

2023-03-21 Thread jyapayne
Based on what @gs said, my code above should be modified like so to have the proper client/server structure (there are still many things wrong, just as @gs addressed partially in his code and explanation): # client.nim import strutils import net let ip = "127.

Only one line will load. Need all lines in directory to load.

2023-03-21 Thread jyapayne
@Naterlarsen Yeah, oops, the while loop should be in the try block, like @gs mentioned # server.nim import net import strutils import std/[times, os] let port = 443.Port var server: Socket = newSocket() server.setSockOpt(OptReusePort, true) serve

Only one line will load. Need all lines in directory to load.

2023-03-21 Thread jyapayne
@Naterlarsen glad to have helped. As for how I got good at sockets, I wouldn't say I'm very good at them. I've been developing software professionally for 10 years or so, so there are things you pick up after that amount of time. It helps that sockets are a fairly simple mechanism, from a basic

Only one line will load. Need all lines in directory to load.

2023-03-22 Thread jyapayne
@gs All good! I actually appreciated it. It's all in the service of making things better. I've had myself thousands of code reviews, so no harm done :) I'm not so sure that a web framework would be better for him depending on what he wants to create. Typically the web client doesn't communicate

Screenshot works fine in own code but not over sockets.

2023-03-23 Thread jyapayne
Please share your full client and server code again. It's not clear what is wrong from your snippet

Screenshot works fine in own code but not over sockets.

2023-03-23 Thread jyapayne
This is an important lesson on why you should never catch an exception and simply quit or do nothing. In each `except` block, put the following: echo "Error: " echo getCurrentException().getStackTrace() echo getCurrentExceptionMsg() Run You'll see there's an in

Speeding up compile times

2023-04-12 Thread jyapayne
@Stefan_Salewski, just FYI for your English learning, "dude" is equivalent to "bro" (friendly) or "random man" (neutral). It's generally considered either neutral or positive and typically used in reference to males, but it can be used to reference females if you want to be funny :P As far as I

Mocking overloaded function

2024-01-05 Thread jyapayne
You can also disambiguate the function call you need with a macro like so: import macros proc dummy() = echo "normal dummy" proc dummy(s: string) = echo "string dummy " & s macro getProc(sym: typed, types: varargs[typedesc]): untyped =

single line ref seq[int] assignment

2024-02-25 Thread jyapayne
Seqs are already allocated on the heap and are thus reference-counted and don't need to be created with a redundant "new" call. See [the manual](https://nim-lang.github.io/Nim/tut1.html#advanced-types-sequences).

Help with macro/template extrapolating of parameters

2024-04-11 Thread jyapayne
I think this is exactly what you want, minus the `do:` import macros import std/envvars, std/options type EnvType = object m_user: Option[string] m_icloud_dir: Option[string] var Env*: EnvType macro defineEnv*(fieldName, body: untyp

Help with macro/template extrapolating of parameters

2024-04-11 Thread jyapayne
You can also go crazy and get rid of even more boiler plate (I've added types as well): # env.nim import macros, tables import std/envvars, std/options export envvars, options type EnvVarInfo = tuple[envType: string, envBody: NimNode] # Store all o