Array Difference

2021-04-06 Thread lqdev
Not as far as I know. I think if we would add such a proc to the standard library, `-` would be a good name candidate as we already use normal operators `+`, `-`, `*` for sets, instead of ∪, ∖, ∩.

Question about using "include"

2021-02-20 Thread lqdev
You'd need to declare v3 before you include file1 and file2, like so: var v3 = 3500 include file1 include file2 Run

Length of a string in bytes

2021-02-04 Thread lqdev
That's not true, while a `string` will indeed convert into an `openArray[char]`, it's still a `string` under the hood. The memory representation for a `string` is internally the same as for a `seq[char]`, so it's "safe" to use `cast[seq[char]](yourString)`. Though I wouldn't rely on that person

Length of a string in bytes

2021-02-04 Thread lqdev
All strings in Nim are just `seq[char]`, so `yourString.len` will work. You need to use `unicode.runeLen` if you want unicode length.

Unmarshal JSON to type

2021-01-22 Thread lqdev
You can try using [jsonutils](https://nim-lang.org/docs/jsonutils.html), which allows you to provide your own hooks for unmarshalling. Alternatively you can just make the field into a string and use `parseFloat` on it later.

Best practice for OOP-style of procedure calling

2021-01-22 Thread lqdev
moigagoo didn't mention that but you need to import `std/with` to use it. Currently it's a bit underdeveloped though, with some simple examples not being parsed correctly (eg. you can't do `[1] = "a"` to use `x[1] = "a"` syntax), but it's certainly nice to

libdill for large scale concurrency

2021-01-20 Thread lqdev
Sounds like something that could be implemented on top of [Weave](https://github.com/mratsim/weave).

Ignore part of tuple without warnings

2021-01-20 Thread lqdev
As far as I can tell from the gensyms, you're trying to do that in a template. Try adding a {.used.} pragma to your variable, like so: let (a {.used.}, b) = getATuple(sth) Run

Any way to access the Documentation Comment of a procedure?

2021-01-14 Thread lqdev
You can do so by creating a macro that inspects the syntax tree of your procedure and extracts doc comments from it: import std/macros import std/strutils # the parameter has to be `typed` because we need to access the proc's # implementation macro doc(procedure:

Own numeric type

2021-01-02 Thread lqdev
That's not a language feature, possibly due to the low number of actual use cases for it.

Seems like a bug? SIGSEGV: Illegal storage access.

2021-01-01 Thread lqdev
The compiler should never SIGSEGV, so this is indeed a compiler bug. Please [report this on GitHub](https://github.com/nim-lang/Nim/issues).

Should`type` or `typedesc` be used?

2020-12-30 Thread lqdev
There's no difference at all, they do the same thing.

One line comprehension equivalence

2020-12-18 Thread lqdev
Seems like for some reason `collect` doesn't really support being used as an argument directly, but you can circumvent that using a `block`: import std/sugar echo(block: collect(newSeq): for i in 1..11: i) Run

lint+ - an improved linter for the lite text editor, incl. Nim support

2020-12-15 Thread lqdev
I'm not sure I understood correctly, but you're mentioning the lack of highlighting in fmt, right? Well unfortunately, due to the limitations of lite's highlighter, that's not really possible without incorporating a custom highlighting engine to the plugin. Personally I don't use fmt that much,

Seq, table. How to efficiently reference the last item

2020-12-15 Thread lqdev
There's no such thing as a "last" index in a table. If your table doesn't have holes, you may as well use a `seq[seq[int]]`, in which case the last index of the last seq in the seq would be written as `mySeq[^1][^1]`.

Create my own language in Nim

2020-12-12 Thread lqdev
Regarding npeg: while it's a good starting point for building a parser, in my own experience I found that building AST with it is quite difficult to do. Mainly because of how its code blocks work.

Create my own language in Nim

2020-12-12 Thread lqdev
This book is a really good introduction to creating interpreted languages: /

lint+ - an improved linter for the lite text editor, incl. Nim support

2020-12-11 Thread lqdev
Yeah, I'll just make it a configurable setting then.

lint+ - an improved linter for the lite text editor, incl. Nim support

2020-12-11 Thread lqdev
Yes, but usually when you're editing code you want to see all errors at once. I wouldn't want to see a million errors in my terminal, though, just the first one that happened.

lint+ - an improved linter for the lite text editor, incl. Nim support

2020-12-11 Thread lqdev
I've noticed that `nim check` sometimes seems to choke on code using generics, no clue why. I'll make `nim check` the default though, if you say so.

lint+ - an improved linter for the lite text editor, incl. Nim support

2020-12-10 Thread lqdev
I'm proud to announce that I've released lint+, a linter for [lite](https://github.com/rxi/lite). It actually started out as a Nim-only linter, but I decided to distill it to something a bit more generic with a separate Nim support plugin. You can grab lint+ from its GitHub repository:

Is there a way to monitor the total memory usage of a Nim app?

2020-12-10 Thread lqdev
There are some procs in system that may be helpful: * *

pop for a set - is there something prettier?

2020-12-07 Thread lqdev
Well, that's because `pop` is kind of against how bitsets work. There is no insertion order preserved in a `set[T]`, so really there's nothing to pop. What would you need a `pop` operation for?

What is the use of reference (ref) types in Nim. What is ref normally used for in Nim?

2020-12-07 Thread lqdev
That's actually not what `ref` does. Marking a type with `ref` makes it heap-allocated, the word `ref` itself loosely stands for 'ref-counted'. What you would call a 'ref' in eg. C#, or a pointer in C, is accomplished by `var` in Nim. For instance: proc modify(x: var int) = x

Simple way to have a dynamic shared list/sequence between threads

2020-11-30 Thread lqdev
Check out channels:

help C to nim conversion just precision

2020-11-27 Thread lqdev
c2nim translates these sort of "incomplete" struct definitions into this: type TermKey* {.incompleteStruct.} = object Run You're probably running into something else in your source header.

Strange error message from collections/sets.nim

2020-11-25 Thread lqdev
I feel like one very important point people miss when saying tabs should be used for indentation is the fact that tabs actually have a different purpose. It's in the name: _Tabulator_. Not indentator.

Win10 terminal game

2020-11-17 Thread lqdev
I could squeeze a bit more performance out of a Linux terminal by only updating characters that changed between frames, but the Linux terminal works much differently than the Windows console. In fact, the Windows console is buffered, and can probably be controlled much faster with the WinAPI fu

variable length tuple unpacking

2020-11-11 Thread lqdev
There isn't a way of doing this in Nim. However, you can (sort of) work around this: let s = x.splitWhitespace() (x, y, rest) = (s[0], s[1], s[2..^1]) Run

Reference Variable (C++ jargon) - is there such a beast?

2020-11-08 Thread lqdev
Thanks for the correction, I'll edit my snippet.

Reference Variable (C++ jargon) - is there such a beast?

2020-11-08 Thread lqdev
Currently the only way of doing that is through the use of pointers. However, dereferencing is done automatically for fields, so this: type Abc = object a, b: int c: array[10, int] var a = Abc() r = addr a a.b = 10 a.c[5] = 3

local types - how to

2020-11-07 Thread lqdev
Pretty much, yes. But in reality this isn't as bad of a limitation as it may seem :)

local types - how to

2020-11-07 Thread lqdev
That's not possible, sorry. You'd have to do something like this: type ApfelbaumBool = enum Undef, True, False Apfelbaum = object Baum : array[5,int] akt_Reihe : int max_level : int Cache : array[2*4*6*8*10,Bool] Run

Idiomatic function call coding style?

2020-11-03 Thread lqdev
I think `str.len` is more common, but there isn't anything wrong with using `len(str)`. Use whichever one you prefer :)

Get all procs in given module

2020-10-30 Thread lqdev
Unfortunately no, that's not doable. At least not with existing modules. The `macros` module contains a proc `getImpl` which you _could_ potentially use on a module name. I say _could_ , because actually using it on a module returns a `nil` node. The closest I was able to get to this was to cre

Compile-time if and/or syntax conflicts

2020-10-27 Thread lqdev
`if` is strictly runtime, you need to use `when` in this case: proc createMyArray*(N: static[int]): array[N, int] = when N == 2: result = [1, 2] elif N == 3: result = [1, 2, 3] Run

What Nim projects are you working on?

2020-10-23 Thread lqdev
Game-related stuff. * aglet: is a high-level OpenGL wrapper that makes low-level graphics programming easy. * rapid: is game engine built for making cool games quickly, still largely a work in progress. I'll a

It's time to make Nim known ! ✊✊✊✊

2020-10-15 Thread lqdev
I had a similar idea, but haven't really found the time or motivation to do anything yet. Maybe when I start making progress on my game I'll start posting devlogs, of course mentioning Nim's more amazing features that make game development a breeze :)

Confusing behaviour with cstringArray

2020-10-03 Thread lqdev
`seq` and `cstringArray` have different memory layouts and so, they're not binary compatible. Casting between them is undefined behavior, probably resulting in a segfault.

Question on implementing language with Nim

2020-09-04 Thread lqdev
Maybe store a `Table[string, proc (args: seq[Value])]` or something like that inside the VM, and create an opcode for Nim calls? I'm not sure about the specifics of your VM. It would be helpful if you could provide some more information.

nim.town is a shared domain for nim projects, developers, organizations, etc

2020-09-04 Thread lqdev
Apologies for the late reply, I don't use the forum very often. Yeah seems like your message tripped Gmail's spam detection, even though I was the one to start the conversation. Odd.

Preserve static value in recursive macro

2020-08-24 Thread lqdev
You probably want to split this macro into a separate proc that operates on a plain seq[string], and then make that recursive.

nim.town is a shared domain for nim projects, developers, organizations, etc

2020-08-24 Thread lqdev
@cricket I don't mean to brag, but I sent you an email 2 days ago and haven't heard back yet. Please check your spam folder!

How to cast a slice of seq[char] to uint?

2020-07-30 Thread lqdev
Sure is. But you have to handle endianness, as x86_64 is a little endian architecture and data returned by nimPNG is stored in big endian order. import strutils let pixels = @[uint8 0, 0, 255, 0, 255, 255, 255, 0, 0] var arrayPixel: array[4, uint8] copyMem(arrayPixel

Beginner - Is there a Nim's similar to a Python dictionary?

2020-07-16 Thread lqdev
You can also create a variant object: type Person = object name: string age: Natural MyValueKind = enum mvkNumber mvkString mvkPerson MyValue = object case kind: MyValueKind of mvkNumber: numberVal: f