Generics constrain with two types

2020-09-10 Thread archnim
You're too nice. :-)

Compilation for different macOS version

2020-09-10 Thread enthus1ast
i've cross compiled to macos successfully with osxcross:

how to package C-only project on macOS?

2020-09-10 Thread ElAfalw
Thanks for the suggestion> Regarding shipping binaries, that's exactly what I thought. But look at this one:

Compilation for different macOS version

2020-09-10 Thread Araq
Probably it's necessary to _build_ on the oldest OS you want to support.

how to package C-only project on macOS?

2020-09-10 Thread ElAfalw
Basically, instead of sending out my Nim (and force everyone to install the compiler), I was thinking of just sending out the C code. How to obtain a fully compilable (with everything included) C-version of my project?

Reversed traversal of iterators instead of creating a reversed copy

2020-09-10 Thread enthus1ast
I think this Is not possible for all iterator. For arrays it's easy sure, but imagine eg a network stream. The last data may have not arrived already, or might never end etc..

how to package C-only project on macOS?

2020-09-10 Thread Araq
You can do that via niminst, see for more information. However, you can also simply ship binary files on macOS X.

Compilation for different macOS version

2020-09-10 Thread ElAfalw
I'm running macOS 10.15. I compiled my binary fine here and sent it to sb else with an older macOS version. He keeps getting the following error: dyld: lazy symbol binding failed: Symbol not found: chkstk_darwin Referenced from: /Users/nkszf/Documents/./testapp (which was

how to opt out of automatic import of system.nim?

2020-09-10 Thread alexeypetrushin
+1 it feels wrong that too much stuff being imported by default. Like the `io` module. It pollutes the default environment. And on some platforms (Browser for example) files and stdin/stdout doesn't make sense.

Reversed traversal of iterators instead of creating a reversed copy

2020-09-10 Thread TinBryn
I agree that it should be in the stdlib, but it's fairly easy to implement iterator reversed*[T](arr: openArray[T]): T = for it in countdown(arr.high, arr.low): yield arr[it] Run

keep signed into forum

2020-09-10 Thread slonik_az
Every time I restart browser (Chrome in my case) my nim forum session gets closed and I have to login again typing in the username and password. It would be more user friendly to provide a check-box on the login screen that, when checked, would keep me signed until I explicitly logout or some ma

Reversed traversal of iterators instead of creating a reversed copy

2020-09-10 Thread adokitkat
Hi, I think there should be a 'reverse' macro for reversed traversal of iterators which doesn't change the original content nor creates a duplicate (or something similar) - I tried to search for something like this but I did find only procs `algorithm.reverse()`, `algorithm.reversed()` which re

Norm 2.0.0

2020-09-10 Thread moigagoo
Boy oh boy, did that bug fix turn into a major version bump with an API change: Thanks for reporting the issue! Apparently, the way `JOIN` statements were generated was just broken.

Should a function that's called many times return Table or ref Table?

2020-09-10 Thread shirleyquirk
i came back to suggest {.threadvar.} instead of {.global.} but that's way better +1

Exceptions in Threads

2020-09-10 Thread mratsim
> That's the same as C++ (and some other languages) โ€” an uncaught exception is > a fatal error, so a top-level function must not let any escape. Pretty > standard stuff, not a reason not to use exceptions. But it's not the case in Java, C#, Go because of thread-safe GC and it's not the case of

Generics constrain with two types

2020-09-10 Thread mratsim
@jcosborn code uses concept which are detailed here: This allows to represent arbitrary requirements as an abstract type. The concept definition here type CondStr[T] = concept x (x is string) or (T is stri

Generics constrain with numbers

2020-09-10 Thread mratsim
It was probably made before SomeInteger existed some of the code there is very old

Should a function that's called many times return Table or ref Table?

2020-09-10 Thread euant
There's nothing as far as I'm aware of in the stdlib like `call_once`, but something like the following seems to work: import atomics when compileOption("threads"): import locks when compileOption("threads"): type OnceBase = object of RootObj don

Is there any PWA (Progressive Web Apps) framework or package written in nim?

2020-09-10 Thread federico3
It's useful to have webapps that are fully usable when javascript is disabled and add cosmetic and usability improvements when it's enabled. I have this need for work right now. Some of the existing solutions implement server-side rendering with added benefits on speed and bandwidth but they ar

Should a function that's called many times return Table or ref Table?

2020-09-10 Thread shirleyquirk
oof, good catch

openArray vs seq

2020-09-10 Thread Araq
Er, and how could we make them type-compatible otherwise? The underlying `ptr, len` pair is essential, see also C++'s iterators and spans, C#'s spans etc. On the contrary, `openArray` is a "borrowed" non-owning type, introduced long before Rust was invented.

Calling templates with untyped params

2020-09-10 Thread Hlaaftana
Code block arguments are always the last argument, so `foo(a): x` translates to `foo(a, x)`. template doSomething(someVar: bool = false, code: untyped) = ... the template ... Run

openArray vs seq

2020-09-10 Thread snej
> Hoping for a nice experience in using the language and interacting with the > community. Welcome! :) My advice about `openarray` is to just get used to it. IMHO it's an ugly wart in the language, needed only because `array` and `seq` aren't type-compatible. Every language has its warts...

Growth of popularity and Nim community

2020-09-10 Thread snej
My 2ยข: The biggest thing needed in Nim right now is stabilization of the GC and async/threading features. Right now those are in flux and it causes a lot of confusion for developers [e.g. me] who've moved past tire-kicking and are learning how to write serious programs. The tutorials and referen

Exceptions in Threads

2020-09-10 Thread snej
> If you use multithreading, I strongly recommend you not to use exceptions in > your code. I think that's overly extreme... > ensure that no exceptions can happen or are all handled in the proc that will > be distributed That's the same as C++ (and some other languages) โ€” an uncaught exceptio

Should a function that's called many times return Table or ref Table?

2020-09-10 Thread snej
FYI, that code isn't thread-safe โ€” it's possible that two threads enter the body of the `if` statement, which would cause concurrent modifications to `cached_companies`. To remedy that you'd need something equivalent to C++'s `call_once`, which lets only the first caller enter the lambda, all o

Instantiation of uint32 type variables only with a maximum value of 2147483647

2020-09-10 Thread BugFix
Wow, very fast answers. Many thanks.

Instantiation of uint32 type variables only with a maximum value of 2147483647

2020-09-10 Thread doofenstein
you need to use `4294967295'u32` to make an unsigned literal

Instantiation of uint32 type variables only with a maximum value of 2147483647

2020-09-10 Thread Stefan_Salewski
Default literals are of int type. Use var i: uint32 = 4294967295.uint32 var j: uint32 = 4294967295'u32 echo i echo j Run

Instantiation of uint32 type variables only with a maximum value of 2147483647

2020-09-10 Thread BugFix
I'm a little bit confused. The range of `uint32` is `0..4294967295`. But it is impossible to assign a variable (uint32) a value larger than 2147483647 in the editor. The Nim project check says instantly: `type mismatch: got but expected 'uint32'`. (I'm using VSCodium as editor.) By the other si

Extending a generic varags proc

2020-09-10 Thread shirleyquirk
you need to provide a proc (like `$`) that converts all the types you're interested in to a single type import sequtils proc toSeqofString(args:varargs[string,`$`]):seq[string] = args.toSeq echo toSeqofString(3,7.5,'a',"steven",(3,4,5)) Run

Should a function that's called many times return Table or ref Table?

2020-09-10 Thread Araq
Use `TableRef` for this case but your design itself is not good. For example, it's immediately not thread-safe.

Should a function that's called many times return Table or ref Table?

2020-09-10 Thread shirleyquirk
If cached_companies never needs to be written to this is the perfect situation for `lent` and {.global.} is how to keep global variables safe within the scope of the proc that deals with them proc companies()*: lent Table[string,Company] = var loaded {.global.}= false;

Should a function that's called many times return Table or ref Table?

2020-09-10 Thread alexeypetrushin
> of course the compiler is free to optimize it, so maybe there is no copy of > large data blocks involved? That would be a very useful optimisation :)

Should a function that's called many times return Table or ref Table?

2020-09-10 Thread alexeypetrushin
> A very simple method is to call the proc once, and store its result in a var Yes, but it will be loaded eagerly, I try to load it lazy, as I have many different data tables and not all of them always used.

Should a function that's called many times return Table or ref Table?

2020-09-10 Thread alexeypetrushin
> would it not be good enough when to companies() the query string like "MSFT" > is passed and it returns just that entry. Procs that returns whole tables, > where the table itself is a global var are not that often used. Yes, i was thinking about it, but I also need to iterate over all companie

Should a function that's called many times return Table or ref Table?

2020-09-10 Thread Stefan_Salewski
From > For consistency with every other data type in Nim these have value semantics, > this means that = performs a copy of the hash table. > > For ref semantics use their Ref variants: I would assume that your assumption is true. But I wonder if you ha

How do I reduce allocation and GC with pool of objects?

2020-09-10 Thread gcao
Thanks a lot! I'll look and see if I can borrow the ideas.

Should a function that's called many times return Table or ref Table?

2020-09-10 Thread archnim
A very simple method is to call the proc once, and store its result in a var. Then you'll be able to wrtite: `companies["anId"].name`

Should a function that's called many times return Table or ref Table?

2020-09-10 Thread alexeypetrushin
I have a function returning table of companies that's **called many times** to get information about different companies: echo companies()["MSFT"].name echo companies()["INTC"].name ... Run How the result of `companies` function should be defined, as Value or R

Can std lib work with gc:arc or gc:orc ?

2020-09-10 Thread Araq
The following remain unsupported for ARC/ORC for the time being: `system.deepcopy` `marshal.nim` Everything else works.

Extending a generic varags proc

2020-09-10 Thread archnim
How can I write a varags that accepts params of different types ?

Generics constrain with two types

2020-09-10 Thread archnim
Please, how does @jcosborn's code work in detail ?

Generics constrain with numbers

2020-09-10 Thread archnim
This is something I don't understand : The implementation of SomeOrdinal in /lib/system/basic_types.nim, on line 32 is the following: SomeOrdinal* = int|int8|int16|int32|int64|bool|enum|uint|uint8|uint16|uint32|uint64 Run Isn't it better (shorter) to write : `SomeOrdi

Generics constrain with numbers

2020-09-10 Thread archnim
I did few tests to understand better generics syntax. This is a cool observation I made (Just for beginners like me who don't know it): If I write : func myfunc[T1, T2: uint8| int8](number1: T1, number2: T2): bool = Run T1 is concerned by the constrain (uint8 | int8).

Generics constrain with two types

2020-09-10 Thread mratsim
> Maybe in a near future, a more precise generics syntax will be provided. I think this is an acceptable limitation, there is no other language that supports what you propose either and it seems like it would make the proc declaration complex. @jcosborn solution is actually quite elegant, other

Generics constrain with numbers

2020-09-10 Thread archnim
Gracias very much ;-).

Calling templates with untyped params

2020-09-10 Thread mratsim
Unfortunately at the moment, `untyped` parameters need to be at the exact same position when overloading or on template calls At the moment you need to use the `do` notation if you keep this order which lead to a strange doSomething:

Generics constrain with numbers

2020-09-10 Thread mratsim
Use `SomeInteger`, `SomeFloat` or `SomeNumber`

Generics constrain with numbers

2020-09-10 Thread lscrd
This way: func myfunc(number: SomeInteger) = Run

How do I reduce allocation and GC with pool of objects?

2020-09-10 Thread mratsim
This is the general idea but: * Value can't be a ref object, it has to be an object or ptr object for manual memory management and you can do ref counting by leveraging Nim destructors as I do here:

Generics constrain with numbers

2020-09-10 Thread SolitudeSF
https://nim-lang.github.io/Nim/system.html#SomeInteger

Generics constrain with numbers

2020-09-10 Thread ElegantBeef
There is the `SomeNumber` which is `SomeFloat | SomeInt` which.. goes all the way up. From docs [here](https://nim-lang.org/docs/system.html#SomeNumber)

Generics constrain with numbers

2020-09-10 Thread archnim
Hello world. Here's the first line of my function: func myfunc[T: int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uin64 ](number: T) = Run It could be longer, for example if I add floating types. Is there any way to shorten that code ?

Calling templates with untyped params

2020-09-10 Thread ElAfalw
I have a template like: template doSomething(code: untyped) = ... the template ... Run which I can call like: doSomething: ... my code ... Run What if I want to add an optional param to this template? Like: te

Generics constrain with two types

2020-09-10 Thread archnim
Thanks a lot, @doofenstein. Maybe in a near future, a more precise generics syntax will be provided.

Extending a generic varags proc

2020-09-10 Thread archnim
Thank you very much, you all.

Generics constrain with two types

2020-09-10 Thread archnim
Thanks a lot.