Re: How does a
@cdome Mixin is not a concept I'm familiar with; I thought that was meant to be something basically like a "partial template". I've looked up mixin in the doc; from that example I still don't know what it does (looks like some kind of "symbol import"?), so I need a bit more direction. I tried adding: mixin hash mixin `==` In the proc that creates the Table: proc initSharedTable*[A, B](initialSize=64): SharedTable[A, B] = assert isPowerOfTwo(initialSize) mixin hash mixin `==` result.counter = 0 result.data = initSharedArray[KeyValuePair[A, B]](initialSize) but it didn't seem to make any difference. Then I tried adding it directly at the top of the module, but the compiler says it's invalid there, then I tried adding it in the template where the error is ("hc = hash(key)"): template genHashImpl(key, hc: typed) = mixin hash mixin `==` hc = hash(key) if hc == 0: # This almost never taken branch should be very predictable. hc = 314159265 # Value doesn't matter; Any non-zero favorite is fine. But the error doesn't go away. Where else should I put it? @boia01 What I mean is, that I have a module that defines the type "SharedTable[A, B]", and in another module I have "SharedText", and in a third module (TypeRegister) I import both modules and define a type that contains a "SharedTable[SharedText, Whatever]", so I'm "passing SharedText as a generic parameter to SharedTable".
Re: How does a
Can you expand on: > module that receives the SharedText as generic parameter can find the > hash(SharedText) proc? What do you mean exactly? Does the module import your SharedText module? If so, it should find your `hash(SharedText)` proc. EDIT: I hadn't seen cdome's reply. That's probably what's happening. You need a `mixin`.
Re: How does a
you need to mixin the hash proc into your table: mixin hash, ==
Re: websockets server example won't compile: type mismatch:
shared.nim has a global variable, reqPing, a map of [file descriptor]->[ping response]. That gets used inside readData(), so it's not gcsafe.
How does a "Table" find the "hash()" proc of a type?
So far, I have coded the following: * A simple "string-in-shared-heap" module (I know there is something like that already in the standard lib, mine caches the hashcode). * A seq-in-shared-heap module. * A Table-in-shared-heap (I know there is something like that already in the standard lib, but mine is on purpose NOT thread-safe). * A thread-safe "register", that maps a key both to a value and a unique ID on the shared heap, using the above "seq" and "Table". * A register for "types", built on the above "register". It uses the "string-in-shared-heap" as "key". * A module that exports a few "atomics" method (load, store, exchange, cas), that it works on pthreads AND Windows. * Concurrent message-queues on the shared heap, using all of the above. All of this seems to work (except the message-queues), at least in the "inline" tests writen with "when isMainModule: ..." My issue is, that when I use the "type register" in the message-queues, suddenly the "shared heap table" cannot find the hash function of the "shared heap string". The code in the message queues calls the same procs as the test code in the "type register", so I see no reason why the hash() proc could not be found. The whole code is rather large now, mostly due to containing a clone of "tables.nim", so I don't want to post it here, but I'll create some github repo(s) for it, once it has been cleaned up. I'm only posting the (simplified) "string-in-heap" module for now, to show how the hash() proc is defined. Do I need to do anything more, so that a module that receives the SharedText as generic parameter can find the hash(SharedText) proc? import hashes type SharedText* = object txt*: cstring txthash*: Hash txtlen*: int proc hash*(st: SharedText): Hash {.inline, noSideEffect.} = result = st.txthash proc len*(st: SharedText): int {.inline, noSideEffect.} = result = st.txtlen proc `$`*(st: SharedText): string {.inline.} = result = $st.txt proc `==`*(a, b: SharedText): bool {.inline, noSideEffect.} = (a.txthash == b.txthash) and (a.len == b.len) and (cmp(a.txt, b.txt) == 0) proc initSharedText*(s: cstring): SharedText {.inline, noSideEffect.} = result.txt = s result.txtlen = len(s) result.txthash = hash(s) And the compiler error message looks something like: # ... mysharedtable.nim(153, 12) Error: type mismatch: got (SharedText) but expected one of: proc hash(sBuf: string; sPos, ePos: int): Hash proc hash(x: uint64): Hash # ...
Re: lzma headers
Cool. Compression is really interesting.
Re: Hiring Nim Devs for Ethereum Implementation
I'd just like to say that **this project is very good news**, for both Nim and Ethereum. * * * I've been critical of [cpp-ethereum](https://github.com/ethereum/cpp-ethereum) being GPLv3, which means not everybody can use it (for either practical or philosophical reasons). As always, I personally urge using [a copyfree license](http://copyfree.org/standard/licenses) for the Nim implementation.