Re: env needs to be copied for closure

2019-11-19 Thread Araq
> The generated func-s in l all referring to the env by ref, so they are all > referencing to the same env, which is modified in each iteration of for. That's actually what the spec says needs to be done (but I'm not sure it's written down somewhere in the manual. _sigh_ ). Reason: Performance,

env needs to be copied for closure

2019-11-19 Thread foldl
Hi all, I have submitted issue [#12625](https://github.com/nim-lang/Nim/issues/12625) on generating func-s (closures) with mapIt, where the code crashes nimvm or behaviors wrongly in runtime. Further checking indicates that the root cause is, for the code snippet below, env is owned by foo, so

Re: Karax Components

2019-11-19 Thread dawkot
I didn't get to use VComponents, so I don't really know how it works. All I could infer was from [https://github.com/pragmagic/karax/blob/master/examples/carousel/carousel.nim](https://github.com/pragmagic/karax/blob/master/examples/carousel/carousel.nim)

asyncftpclient troubles

2019-11-19 Thread schad
I am trying to get asyncftpclient to work (from windows) and I think I ran into a bug. Connecting works but commands do not (I guess the connection is not kept alive?). Does the following code work for you? import asyncdispatch, asyncftpclient proc main() {.async.} = ec

Re: Help needed: Nested lists in Nim

2019-11-19 Thread ggibson
Yes, this. Related questions pop up every year in our algorithms courses, and the wonders of the modern CPU cache always amaze students!

Re: Help needed: Nested lists in Nim

2019-11-19 Thread Araq
Just use a `seq` and write Nim code instead of emulating another language. Lists went out of fashion in the 90ies when CPUs grew caches.

Re: Silly mistake in for loop but can't figure it out

2019-11-19 Thread miran
> It works for me Because, as pointed out by @Stefan_Salewski, you didn't use **while** isMainModule. @adnan if it wasn't obvious from the answers, you should use **when** isMainModule.

Re: Karax Components

2019-11-19 Thread moigagoo
Could you please elaborate? How to I store state of a VComponent and access it from other components?

Re: Silly mistake in for loop but can't figure it out

2019-11-19 Thread cdome
It works for me import os, strutils for param in commandLineParams(): for path in getEnv("PATH").split PathSep: let probe = path / param if existsFile probe: echo probe # keeps printing forever break Run

Re: Silly mistake in for loop but can't figure it out

2019-11-19 Thread Stefan_Salewski
Really funny :-) I guess you know that we generally write "when is mainModule:" With while it makes no sense, but the compiler can not catch all nonsense.

Help needed: Nested lists in Nim

2019-11-19 Thread edu500ac
I decided to write a simple tokenizer as the starting point for recursive descent parsers. Therefore, I needed nested linked lists of the sort that I can find in Lisp, Prolog and other languages. After searching the web, I came across a discussion from 2015 between _andrea_ , _def_ and _Jehan_ ,

Silly mistake in for loop but can't figure it out

2019-11-19 Thread adnan
I'm implementing which(1) in nim but I keep looping forever, what's causing this? import os, strutils while isMainModule: for param in commandLineParams(): for path in getEnv("PATH").split PathSep: let probe = path & DirSep & param

Get nimble file directory from within nimble file hook

2019-11-19 Thread drkameleon
I've written a after install hook. However, I noticed that the current directory has changed (to the packages directory) - and is not the directory where the .nimble file is. How do I get the original directory path?

Re: Karax Components

2019-11-19 Thread dawkot
If you want to use VComponents, you'll need to use a commit before this bug was introduced (until it gets fixed): [https://github.com/pragmagic/karax/issues/112](https://github.com/pragmagic/karax/issues/112) If you're not going to use VComponents, I'm pretty sure the only alternative is global

Re: Reversing string Hash value

2019-11-19 Thread Araq
No, that's not how hashing works in every mainstream programming language ever.

Re: Reversing string Hash value

2019-11-19 Thread Stefan_Salewski
Note that hash() function is not a one to one operation, but generally many objects have the same hash value. In a HashTable the hash values is generally used to guess a set of candidates, and the candidates are then compared each to the key to see if there is a real match. hash() is generally

Re: Is there any way to look something up in a Table using a pre-computed Hash value?

2019-11-19 Thread drkameleon
Thanks a lot! This sounds like a great workaround!

Reversing string Hash value

2019-11-19 Thread drkameleon
I know that if I have a string, I can get its hash value by: str.hash Is there any way to get the string value from a hash? (like: strHash.str)

Re: Is there any way to look something up in a Table using a pre-computed Hash value?

2019-11-19 Thread mratsim
Create a custom hash for your keys. import hashes type Foo = object id: Hash proc hash*(x: Foo): hash {.inline.} = x.id Run And now `Table[Foo, Bar]` will not hash anything.

Re: Force mutable Seq returns

2019-11-19 Thread mashingan
Perhaps you're looking for [var return type](https://nim-lang.github.io/Nim/manual.html#procedures-var-return-type) ?

Re: NaN tagging in Nim?

2019-11-19 Thread cumulonimbus
(edited previous reply)