Objects for "classes" with ref or without?

2021-02-04 Thread kcvinu
That seems a complete reference of language. I like it. All info in one page. Thanks for the effort.

Is using gcsafe with --gc:arc correct here with producer/consumer?

2021-02-04 Thread treeform
I am trying to learn how the new --gc:arc works with threads, is popping off the q seq correct in a consumer thread? It appears to work, because I lock everything, but I don't know if it will cause problems in some way. Am I missing some thing? import locks, os var q

How to set a string parameter of a procedure by default to nil?

2021-02-04 Thread miran
Does it have to be `nil`/`none`, or can it be just an empty string? proc warmItUp(self: TheCoolThing, myStr = ""): string = var myStr = myStr if myStr.len == 0: myStr = self.theStr ... Run

How to set a string parameter of a procedure by default to nil?

2021-02-04 Thread halloleo
Beauty! I often look in the wrong spot: Nim realises many things in its standard library what other languages implement in the language syntax.

How to set a string parameter of a procedure by default to nil?

2021-02-04 Thread halloleo
Firstly, I really appreciate all the help I get from the " _Nimistas_ " here on the forum. Invaluable! Secondly, there is again something I can't figure out: ### Background I want to pass a string parameter to a procedure with a default from the main object the procedure operates on:

How to set a string parameter of a procedure by default to nil?

2021-02-04 Thread ElegantBeef
`string` is a non-nilable type, which means you cannot, but fear not we have the `options` module! import options proc warmItUp(self: TheCoolThing, myStr = none(string)): string = if myStr.isSome: self.theStr = myStr.get # I assume you wrote this backwards initiall

Macro beginner code review

2021-02-04 Thread ElegantBeef
I second this, `quote` is just one tool, not something you need to or have to use.

Traits or macros for inspecting proc/lambda/functor type

2021-02-04 Thread ElegantBeef
Macros are capable of getting the arguement/return type. The following code will echo out the following ast. import macros macro test(a: typed): untyped = echo a.getImpl().treeRepr let a = proc(i: int): float = 1.0 a.test Run IdentDefs

Traits or macros for inspecting proc/lambda/functor type

2021-02-04 Thread filcuc
Are there macros/traits for inspecting a proc function pointer type? Examples: 1) Being able to iterate on each argument type template foo(f: proc(int)) = for typ in f.argsTypes: // do something with the type Run 1. Having the number of arguments

Macro beginner code review

2021-02-04 Thread xigoi
This looks good! I'm pretty sure using `quote` wouldn't really improve it.

Help needed: Deadlock during allocShared0

2021-02-04 Thread leorize
Yea but it's still using `add()`, which may grow the string.

Help needed: Deadlock during allocShared0

2021-02-04 Thread boia01
Thanks for all the replies! This helps a lot. I had a suspicion the signal handler was trying to print a stack trace. Per @leorize' and @shirleyquirk's comments, it seems I stumbled on a stdlib bug. Should I file a bug report? I'll try `c_malloc` to try to work around the issue and better unders

What are the latest developments in the Nim compiler?

2021-02-04 Thread shirleyquirk
concepts are not 'standard', they're still documented under "experimental", and Araq's [proposal](https://github.com/nim-lang/RFCs/issues/168) and [WIP implementation](https://github.com/nim-lang/Nim/pull/15251) is a much more conservative design; only proc-like definitions (proc/func/method/ma

Macro beginner code review

2021-02-04 Thread Psirus
So I'm trying to learn macros, and its not easy if you've never done metaprogramming. Anyway, I'm trying to write a wrapper for a C function that takes a variable number of arguments, with the first being a string that specifies the types of the rest. I want the wrapper to create this string au

Help needed: Deadlock during allocShared0

2021-02-04 Thread shirleyquirk
so signalHandler shouldn't be doing [this](https://github.com/nim-lang/Nim/blob/bb1c962286922487c5243ca7304fd95fdd27ea53/lib/system/excpt.nim#L636) ? + var buf{.global.} = newStringOfCap(2000) - var buf = newStringOfCap(2000) Run

What are the latest developments in the Nim compiler?

2021-02-04 Thread federico3
Following PRs, RFCs or discussions on IRC and the forum requires a significant investment in time and needs to be done routinely. Perhaps a weekly summary of the main ongoing activities and requests for feedback could help attract contributors.

Help needed: Deadlock during allocShared0

2021-02-04 Thread leorize
The bug is the attempt to allocate memory in an asynchronous signal handler... Signal handlers are like threads but spawned at random points while pausing the thread it's running on. Most code are not and cannot handle this stuff, which is totally understandable. POSIX has a strict definition of

Karax and inline svg elements, what's the recommended way?

2021-02-04 Thread b3liever
So I went with 1. and added all svg elements from the spec /

Help needed: Deadlock during allocShared0

2021-02-04 Thread mratsim
When I tried Weave with allocShared I had deadlocks as well and I didn't use signals. For multithreaded application, I suggest you create your own allocator wrapper that allow you to toggle betwen Nim allocator and malloc.

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 mratsim
If you do `yourString.len` You get the length of the string content in byte. There is an extra byte for `\0` at the end of the string but that's technically not part of the content. I don't know if this is what `Content-length` expect but I would be surprise if Unicode length was used in header

Length of a string in bytes

2021-02-04 Thread Steven
Perhaps if I explain what I want to do ... I'm making a cgi that will create a JSONObject, I then want to return that object as a UTF8 encoded string complete with the Content-Length header

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.

Length of a string in bytes

2021-02-04 Thread Hlaaftana
Strings are not `seq[char]`, they are `openarray[char]`. If you cast strings to seqs or vice versa you will get runtime errors

Length of a string in bytes

2021-02-04 Thread Steven
How do I get the length of a string in bytes? Thanks.

Who can provide a IUP example, requires no DOS window to generate executable file to run after

2021-02-04 Thread Stefan_Salewski
> btw. it is strange why iup is not considered as an official gui lib for nim? It is not that strange as we have currently at least 20 GUI libs for Nim, so calling one the "official" is arbitrary.

Help needed: Deadlock during allocShared0

2021-02-04 Thread shirleyquirk
It's [this signal handler](https://github.com/nim-lang/Nim/blob/bb1c962286922487c5243ca7304fd95fdd27ea53/lib/system/excpt.nim#L612) that tries to print out a stack trace, but can't alloc the new string.