Is there a traced equivalent to Nim's `pointer` (or C's `void*`), or do ref
variables have to be concretely typed?
I can't figure out why the following overloaded procs work:
import
sequtils
proc newSeq2d*[int](x, y: int): seq[int] =
result = newSeq[int]((x * y) + 1)
result[0] = x
proc newSeq2d*[uint8](x, y: int): seq[uint8] =
result = newSeq[uint8]((x *
Yes, the arguments must be immutable even after the for in that case.
Seems like the syntax is this:
iterator foo[T](s: seq[T]{call,`let`}): T =
var i = 0
while i < s.len:
yield s[i]
inc i
That's an interesting approach, and it would be sufficient in some cases.
Thanks.
lol wtf. Why have this synonym, I thought one of them was deprecated and was
about to say "This is why all deprecated procs need to be removed before v1.0
is released"...
@mratsim: Could you elaborate on the third option, please? The following
doesn't compile:
iterator foo[T](s: seq{call,`let`}[T]): T =
var i = 0
while i < s.len:
yield s[i]
inc i
Whatever the correct syntax is, wouldn't this restrict potential
Some ideas from the future Nim
1\. Writetracking:
[https://nim-lang.org/araq/writetracking.html](https://nim-lang.org/araq/writetracking.html)
2\. Iterator returns a lent type so that mutation is a compile-time error:
Cool. Thanks for putting some thought into this
I suppose that unrestricted referencing is one of Nim's design decisions in the
language as a whole as well. It is perfectly valid to hold multiple mutable
references to one object. Data can change under your feet at any time with this
setup, so
I thought that all code into async function will be async too my bad. A lot of
thanks for all for your clarifications and hints!
Thanks! I hadn't thought of the effect system hmmm
> Should I/can I ever count on an iterator in Nim to handle the structure being
> changed during iteration?
Not unless the implementation promises to handle it, I suppose. There's nothing
implicit in an iterator that stops it from being affected by changes in the
structure. e.g.
Hello,
I have a conceptual/style question here.
In C++ (and presumably some other languages), there is a concept called
"iterator invalidation". The basic idea is that while iterating a structure,
changes to the structure could break iteration, leading to a loss of memory
safety. It is also
In regards to some other things written here:
> I'm "pretty sure" that I observed in Windows that asyncdispatch would use
> multiple different threads to run the code.
It doesn't, and it cannot do that unless you pass `--threads:on`. This is
assuming that Windows doesn't do something weird
Indeed, I was going to mention the ChatApp example from Nim in Action. Pretty
sure it implements precisely what you're trying to implement.
See both server and client here:
If you want to use a library, [NESM](https://github.com/xomachine/NESM) could
be of use. NESM creates the serialization and deserialization procs for you
automatically based on your (a bit augmented) types.
You could use it like this:
import nesm
import streams
r3d9u11
a few unsorted things:
* no need for c.getFd.getPeerAddr(Domain.AF_INET) use acceptAddr
[https://nim-lang.org/docs/asyncnet.html#acceptAddr,AsyncSocket](https://nim-lang.org/docs/asyncnet.html#acceptAddr,AsyncSocket)
* waitFor starts its own poll loop (nothing else will run
In addition, recv is executed during sleepAsync, but it is blocked immediately
by readLine (). It will not be a solution because we can not receive messages
during blocking.
Probably because stdin.readLine() is a blocking call, the event loop is blocked
and other tasks can not be executed.
wait well in a separate thread, or such a library will be useful
[asynctools/asyncpty](https://github.com/cheatfate/asynctools/blob/master/asynctools/asyncpty.nim)
ok, problem solved. just need to wait before sending data. I don't know why:
proc sendClientMsg (c: AsyncSocket) {.async.} =
while true:
waitFor sleepAsync(1000)
let msg = stdin.readLine()
echo "<- " & msg
await c.send(msg & "\c\L")
something wrong when I tried to read data from stdin! this code works fine:
client.nim
proc readServer(c: AsyncSocket) {.async.} =
while true:
let msg = await c.recvLine()
echo "-> " & msg
proc sendClientMsg (c: AsyncSocket) {.async.} =
while
> why code with loop doesn't work?
While I don't know the exact reason too, I think you need separate thread which
handle the readline like this
[https://github.com/mashingan/nim-etc/blob/master/cond_loop.nim#L58-L67](https://github.com/mashingan/nim-etc/blob/master/cond_loop.nim#L58-L67)
I tried a few things, like "newAsyncSocket(buffered = false)", but it was no
use. All I can say is, it doesn't work for me either.
Using nimsuggest, the first snippet already error when calling `conToInter(5)`
this code works fine:
proc sendClientMsg (c: AsyncSocket) {.async.} =
#while true:
let msg = stdin.readLine()
echo "<- " & msg
await c.send(msg & "\c\L")
why code with loop doesn't work? how to organize parallel/async read/write?
This seems to work, but it's kinda dirty, and the error messages aren't great:
{.experimental.}
type
Vec2 = tuple[x, y: float]
Kinetic = concept g, type T
T.pos is Vec2
T.vel is Vec2
IKinetic = object
Box = object
well, I changed code. server.nim:
import asyncnet, asyncdispatch, nativesockets
var clients {.threadvar.}: seq[AsyncSocket]
proc processClient(client: AsyncSocket) {.async.} =
while true:
let msg = await client.recvLine()
for c in clients:
I haven't tried your code, but one thing I would check, is that the problem is
not caused by the threadvars. I'm "pretty sure" that I observed in Windows that
asyncdispatch would use multiple different threads to run the code. So you
might set the threadvar in one thread, but the code that
Also you might want to take into account the endianness of BMP.
I'm overloading it for a sort of proxy object which contains a pointer to a
vtable with field offsets and type information, to give seamless access to the
fields of the target through the proxy. The entire thing is generated by a
macro, so I could simply generate getters and setters as you
Hi. I'm trying to write simple async network client and server via AsyncSocket
(by [sample from
manual](https://nim-lang.org/0.13.0/asyncnet.html#examples-chat-server)). But
client and server don't read any data. What I'm doing wrong? server.nim:
import asyncnet, asyncdispatch
Probably because the overloaded PresentModeA is not generic so you can't use
this syntax `PresentModeA[Foo]`, try with that:
proc PresentModeA*[T: bool](d: T) = ...
Yes you can, feel free to check Arraymancer `nim.cfg`:
[https://github.com/mratsim/Arraymancer/blob/master/nim.cfg](https://github.com/mratsim/Arraymancer/blob/master/nim.cfg)
@libman: Unfortunately shell scripts would not work on all Windows for example.
Do you really need to overload `.`? That would make any further development of
your codebase really tricky.
If you want custom getters and setters, you can follow this:
[https://nim-lang.org/docs/manual.html#procedures-properties](https://nim-lang.org/docs/manual.html#procedures-properties)
Very cool, ordered.
Thank you for your feedback
I will buy the book and started to enter the universe of NIM ^^
A long long time ago we had this crazy thing called shell scripts. We used them
to set environmental variables, build complicated command lines, etc...
36 matches
Mail list logo