> 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,
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
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)
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
Yes, this. Related questions pop up every year in our algorithms courses, and
the wonders of the modern CPU cache always amaze students!
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.
> 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.
Could you please elaborate? How to I store state of a VComponent and access it
from other components?
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
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.
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_ ,
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
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?
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
No, that's not how hashing works in every mainstream programming language ever.
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
Thanks a lot! This sounds like a great workaround!
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)
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.
Perhaps you're looking for [var return
type](https://nim-lang.github.io/Nim/manual.html#procedures-var-return-type) ?
(edited previous reply)
21 matches
Mail list logo