Re: Why is Seq.reverse() not part of the standard lib?

2019-11-04 Thread GordonBGood
@kayle, possibly reversing `seq`'s is not implemented in any of the current standard libraries because it is so easy to do writing it yourself. > You have, map, filter, reduce, etc. but not reverse? These are a little trickier to implement that a simple reversal: I recently needed to reverse a

Re: Borrow Checker In Nim?

2019-11-04 Thread GordonBGood
@MrZoraman, Although there was some discussion on this forum in the past about making Nim a little safer as to controlling mutation, I don't think that it was @Araq who instigated the suggestions but rather others such as myself who thought it might be a good option to have so as to compete

Borrow Checker In Nim?

2019-11-04 Thread MrZoraman
Several months back I remember reading a thread on here about Araq planning on adding a borrow checker. Is that still the plan? I don't really want Nim to have a borrow checker so I'm asking about this before I decide to invest more time into learning/using Nim. Thanks!

Re: Why is Seq.reverse() not part of the standard lib?

2019-11-04 Thread keyle
Yes, I've read them and I changed my code to use reverse() as two separate lines... I was commenting, albeit not clearly, on the fact that it's a loss from the method that allows function chaining (in terms of style), which I think it neat. I was also mentioning that someone should look at

Re: Why is Seq.reverse() not part of the standard lib?

2019-11-04 Thread zetashift
I'm assuming you're talking about: [https://rosettacode.org/wiki/Reverse_words_in_a_string#Nim](https://rosettacode.org/wiki/Reverse_words_in_a_string#Nim) Look closely at that code and the 2 links I send. You mentioned you can't do list.reverse().join() Run BUT!

Re: Why is Seq.reverse() not part of the standard lib?

2019-11-04 Thread keyle
Hmm, thank you. And it's not queuable either, I can't do `list.reverse().join()` like I could with the rosetta reverse sample. I'd recommend updating the rosetta code example to use the _algorithm_ lib if that's the better way to do it.

Re: let & const on C backend

2019-11-04 Thread foldl
{.compileTime.} will not do the work. In generated C code, value is copied into a just before a is used.

Why is Seq.reverse() not part of the standard lib?

2019-11-04 Thread keyle
Greetings people, it's been a tick. I've been toying with nim 1.0 and I was baffled to find out that I couldn't simply reverse a seq. It's such a common operation in wildly available in other languages, what gives? You have, map, filter, reduce, etc. but not reverse? I had to ask. cheers,

Re: Why is Seq.reverse() not part of the standard lib?

2019-11-04 Thread zetashift
It's available in algorithm not in sequtils (I think I tripped over it too once): [https://nim-lang.org/docs/algorithm.html#reverse%2CopenArray%5BT%5D%2CNatural%2CNatural](https://nim-lang.org/docs/algorithm.html#reverse%2CopenArray%5BT%5D%2CNatural%2CNatural)

Re: Reduce memory footprint - manually free objects?

2019-11-04 Thread juancarlospaco
I think without an example code snippet that reproduces the problem theres no way to know.

Re: What does the ``.inject.`` pragma do? Where is it defined?

2019-11-04 Thread zevv
Explained in [https://nim-lang.github.io/Nim/manual.html#templates-hygiene-in-templates](https://nim-lang.github.io/Nim/manual.html#templates-hygiene-in-templates) Any variables declared in a template annotated with {.inject.} will be accessible in the scope where the template is called,

Re: What is dead code elimination

2019-11-04 Thread cdome
IMO, the most benefit from DCE (Dead code elimination) that it allows to import modules without worrying too much on other modules overhead. For example if you imported sequtils and used only one proc from this module, you will get only one extra proc extra (and its dependencies if any) in

Output test statistics from `nimble test` (succeeded, failed, skipped, possibly runtime)

2019-11-04 Thread sschwarzer
Currently I use the [unittest module](https://nim-lang.org/docs/unittest.html) from the standard library and `nimble test` to test [my code](https://hg.sr.ht/~sschwarzer/vppdiff/browse/default/tests/test_cleanxmi.nim). I like unittest's DSL. The tests look very clean. What I miss is some

Re: What is dead code elimination

2019-11-04 Thread mratsim
Code that is not used is removed from the final binary. For example proc noOneCalledMe() = echo "Hello?" echo 1+1 Run The noOneCalledMe proc will not exist in the final binary created by Nim because it's not used at all. In C or C++ this is usually

Re: Things to watch in the produced nimcache files - for performance

2019-11-04 Thread mratsim
genericReset and genericResetAux. See issues: * [https://github.com/nim-lang/Nim/issues/8745](https://github.com/nim-lang/Nim/issues/8745) * [https://github.com/nim-lang/Nim/issues/10132](https://github.com/nim-lang/Nim/issues/10132) Note that one of the main source of generic reset,

Re: Regex extracting string between two words not working

2019-11-04 Thread mronetwo
Thank you. That works. Could you explain to me what was wrong with my code? It seems that the important part is the var matches: array[1, string] Run Why is var matches: seq[string] Run wrong? I thought that's a list of strings that can be

What is dead code elimination

2019-11-04 Thread kcvinu
Hi all, What is dead code elimination in Nim ?

Things to watch in the produced nimcache files - for performance

2019-11-04 Thread drkameleon
In the past few days I've been examining a lot the nimcache files trying to figure out what the final code looks like and what optimizations I could do to my original code. For example, I discovered things that I had not known and fixed them, mainly by spotting crucial points were

Re: Question re type classes / implict generic procedures

2019-11-04 Thread pmags
Seems like you could just elaborate as needed: proc double[T: SomeSignedInt](x: T): T = when (T is int) or (T is int64) or (T is int32): 2 * x else: x echo "int double(1): ", double(1) echo "int64 double(1): ", double(1'i64) echo

Re: Integers in Nim

2019-11-04 Thread manfred_h
see for [https://github.com/nim-lang/Nim/issues/12552](https://github.com/nim-lang/Nim/issues/12552) for how proc xyz[T : int](x : T) Run behaves

May this macro work good enough?

2019-11-04 Thread Stefan_Salewski
In the last days I created the requested macro for [https://forum.nim-lang.org/t/5418](https://forum.nim-lang.org/t/5418) [https://github.com/StefanSalewski/gintro/blob/master/gintro/gimpl.nim#L308](https://github.com/StefanSalewski/gintro/blob/master/gintro/gimpl.nim#L308) which printed out

Re: Question re type classes / implict generic procedures

2019-11-04 Thread manfred_h
That works for your example. It does not work if I want to treat int's and uints differently: (nb: SomeSignedInt and SomeUnsignedInt are non-overlapping) proc double[T: SomeUnsignedInt](x : T) : T = x proc double[T: SomeSignedInt](x : T) : T = 2 * x echo double(1) #

Re: Integers in Nim

2019-11-04 Thread lucian
this is interesting,I was expecting that T was lifted to integer. Instead is just validated it can be used as integer but the type stays as passed from parameter. proc xyz[T : int](x : T) = echo "type of param is ", type(x) echo "type of generic is ", T echo

Re: Question re type classes / implict generic procedures

2019-11-04 Thread pmags
You could make some specialized types or exploit some of the combined types that Nim already defines. For example: proc double[T: SomeFloat](x : T) : T = x proc double[T: SomeInteger](x : T) : T = 2 * x echo double(1.0) echo double(1) echo double(1'i64)

Re: Integers in Nim

2019-11-04 Thread manfred_h
proc xyz[T : int](x : T) = echo x xyz(1'i8) xyz(1'i32) Run generates two distinct procedures for int8 and int32 in the c code. How does that happen if int is not a generic type, which would be treated as a type class according to the spec?

Re: Integers in Nim

2019-11-04 Thread Araq
"more specific" refers to `ref T` vs `T`, it doesn't refer to type generic type constraints in the form `[T: int]` (which is super weird anyway, `int` is not a typeclass).

Re: Integers in Nim

2019-11-04 Thread Araq
The program doesn't compile for me: temp2.nim(13, 7) Error: ambiguous call; both temp2.test_1(n: T: int or uint) [declared in C:Usersrumpfprojectsnimtemp2.nim(7, 6)] and temp2.test_1(n: T) [declared in C:Usersrumpfprojectsnimtemp2.nim(5, 6)] match for: (int literal(10))

Re: Integers in Nim

2019-11-04 Thread manfred_h
Given that the template in line 7 is more specific than the template in line 5, is the compile time error the expected result?

Integers in Nim

2019-11-04 Thread manfred_h
I wonder whether integers work in Nim as most people would expect. Is anybody surprised by the output of the program below? const c_1bn = 1_000_000_000 let i_4bn = 4 * c_1bn proc test_1[T](n : T) = echo n, "A" proc test_1[T : int|uint](n : T) = echo n, "B"

Re: Question re type classes / implict generic procedures

2019-11-04 Thread manfred_h
Thanks This still leaves the question: how can I avoid implementing each int procedure for int64 also, i.e. how can I ensure that the integer version of double is called for i without uncommenting the int64 version? converter lenientInt64toInt*(x: int64): int = when

Re: read number from ascii (text) file: scanf-like functionality?

2019-11-04 Thread mratsim
If your string and the extracted results fit in your memory you can use the splitWhiteSpace iterator: [https://nim-lang.org/docs/strutils.html#splitWhitespace.i,string,int](https://nim-lang.org/docs/strutils.html#splitWhitespace.i,string,int) Otherwise write a simple parser using streams and

Re: Macro for creating ‘hooks’?

2019-11-04 Thread mratsim
And second version, with run_hook as pragma import tables, macros var hooks {.compileTime.}: Table[string, NimNode] macro registerHook(name: untyped{ident}, body: untyped): untyped = result = newStmtList() result.add newProc( name = name,

Re: Macro for creating ‘hooks’?

2019-11-04 Thread mratsim
Version 1, exactly what you asked. import tables, macros var hooks {.compileTime.}: Table[string, NimNode] macro registerHook(name: untyped{ident}, body: untyped): untyped = result = newStmtList() result.add newProc( name = name, body =

Re: read number from ascii (text) file: scanf-like functionality?

2019-11-04 Thread Stefan_Salewski
> The system module has readLine but not readWord There are dozen of ways to do it and dozen of examples -- some are optimized for performance, some more for easy usage. For example for lines of text, there is split iterator which can split the line into words. Miram already recommends

Re: read number from ascii (text) file: scanf-like functionality?

2019-11-04 Thread ryofurue
Thank you all for the help. If I understand correctly, you have presented various parsers to convert a character string into numbers. Then, my next task is to read the text file word by word. My example above is a short string of blank-separated numbers. In reality, however, my file contains

Macro for creating ‘hooks’?

2019-11-04 Thread antoinets
Hi there, I want to write macros that takes code written in one place and inserts it elsewhere. In use this would look something like: registerHook post_foo: echo “foo done. x=“, x ... proc foo = let x = 10 runHooks post_foo Run My

Re: Slightly confused with how to use templates

2019-11-04 Thread mratsim
I use dirty templates a lot but only when I need to capture 5~10 variables in the environment. It's very easy to refactor and forget that the dirty template was capturing something, it happen to me with result. In your case the transformation is easy: proc Core_Not*[F,X,V](f: F,

Slightly confused with how to use templates

2019-11-04 Thread drkameleon
I have a proc which I want to directly include in my code, that's why I decided templates is the way to go. For example, in my caller proc I have: case someVar of 0: result = doSth() ... Run (obviously doSth() also returns a value) Now, to make

Re: Nimble RFC for project local dependencies

2019-11-04 Thread shashlick
I didn't want to introduce more flags initially but this approach simplifies the real world use case of allowing local deps mode projects to be used traditionally without having to jump through hoops. It's rare enough that the extra typing is tolerable.

Re: Cross Platform Python Package

2019-11-04 Thread Araq
> For this python packaging scheme to work the c files generated by nim and > nimpy need to compile on all the target platforms, and the list of source > files to compile must to be the same on all the target platforms. Well you need to find some other scheme that works then as the list of