Simulate super in Java at compile time

2021-04-24 Thread Dabod
With template, it can build and run as expected import typetraits type Parent {.inheritable.} = object Child = object of Parent template super(_: typedesc[Parent]): typedesc = typedesc[void] template super(_: typedesc[Child]): typedesc = typedesc[Par

Simulate super in Java at compile time

2021-04-24 Thread Dabod
I am not sure if my code is valid (without last line, it can compile and run) import typetraits type Parent {.inheritable.} = object Child = object of Parent proc super(_: typedesc[Parent]): typedesc = typedesc[void] proc super(_: typedesc[Child]): t

Simulate super in Java at compile time

2021-04-24 Thread ElegantBeef
Well you could use `template` instead of `proc` there, but that's very tedious to maintain and this is just easier. import std/macros type Parent {.inheritable.} = object Child = object of Parent macro parent(typ: typedesc): untyped = let impl = typ.ge

Qualify identifier with exported module?

2021-04-24 Thread ElegantBeef
As far as I know when a module exports another module all the symbols are considered under that module so it's `gdnim.save`. To get `hot.save` to work I think you need to either import `hot` or include a file that imports it.

Qualify identifier with exported module?

2021-04-24 Thread Dabod
use this trick to simulate namespace # hot.nim type hot* = object macro save*(_: type[hot] = hot) = discard Run # mymodule.nim import gdnim hot.save() save() Run

Qualify identifier with exported module?

2021-04-24 Thread geekrelief
I just tried `gdnim.hot.save()` and that works, but it's not ideal if I have exports several modules deep. Anyway, I guess I didn't try fully qualifying the identifier immediately because I was tripped up by an error message about an ambiguous call when another module had the same exported iden

Qualify identifier with exported module?

2021-04-24 Thread geekrelief
This seems like such a simple thing, but I don't know why this isn't working. I have a module `hot.nim` that gets imported and exported by another module `gdnim.nim`. And I want to use my macro `hot.save()` in another module that imports gdnim. But when I do I get `undeclared identifier: hot`.

Deploying an app on Heroku (Jester)

2021-04-24 Thread Hlaaftana
You set your port based on your own config as far as I can tell. For Heroku, you have to set it to the `PORT` environment variable.

Deploying an app on Heroku (Jester)

2021-04-24 Thread GreyBeard
Hello, thanks for the reply I appreciate it, no I didn't set my own port I acknowledge that issue about Heroku, I used the Heroku environment variable for the PORT so it's not an issue, the app starts normally, it's just I can't serve any static files.

Creating Private Package List/Index

2021-04-24 Thread fengkehh
@pietroppeter > With nimble you can also install from a private repo, using the url instead > of the package name (and you would put the url in the nimble file as > dependency). Yep this is basically what I ended up doing. The only thing that slightly annoys me right now is I have to manually

Return procedure in jester route

2021-04-24 Thread ccc3301
How do I return a procedure on a route in jester? import jester import pages routes: get "/": resp pages.index() # Doesn't work Run That way my application would be better organized.

Is there a reliable way to round?

2021-04-24 Thread juancarlospaco
> other languages have suitable rounding

nim-1.4.6_x64.zip/bin/nimble.exe reports as Trojan:Win32/Zpevdo.B

2021-04-24 Thread r3c
> Use a better virus scanner? This whole thread is a meme

Creating Private Package List/Index

2021-04-24 Thread PMunch
You should be able to add an alternative package list to Nimble: . Not 100% sure how Nimble fetches the packages though, so if they are private repos requiring authentication you might run into some trouble.

Creating Private Package List/Index

2021-04-24 Thread pietroppeter
With nimble you can also install from a private repo, using the url instead of the package name (and you would put the url in the nimble file as dependency). No need to publish stuff. Another option is nifty that maybe can be adapted to your use case:

Let's Make Async Great Again!

2021-04-24 Thread dom96
Thanks for writing up this list! I agree with a lot of the items you've listed. In particular I think the following should be prioritised: > 5 Don't print multi-page async error stack traces, if it can't be made short > and clean maybe it's better to trim it somehow. > > 6 No sync IO instead o

XML parsing performance

2021-04-24 Thread doofenstein
what can help as well is putting the code into a function, so that the variables become local instead of global, which gives the compiler more optimisation opportunities, like so (I also changed some stylistic things :D): import streams, parsexml, times proc main() =

Is there a reliable way to round?

2021-04-24 Thread timothee
(ryu) is the proper way to fix this

XML parsing performance

2021-04-24 Thread tcheran
Thank you for your suggestions ynfle. Yeah, I probably should move to 1.4.6 and learn more about compile options.

XML parsing performance

2021-04-24 Thread ynfle
`-d:danger` takes away bound checks and other safety mechanisms see . You could use any of``-d:release -opt:speed -d:lto``. Also try changing the garbage collector to `--gc:arc` (though I'd suggest using the latest version of n

XML parsing performance

2021-04-24 Thread tcheran
WOW! Fantastic !!! With -d:danger option the execution time of the posted code dropped to slightly more than 3 secs. If applied to the version using shallowCopy, even less, around 2 secs and something! Thank you SolitudeSF. P.S. I just hope that applying -d:danger did not modify the space-time c

Is there a reliable way to round?

2021-04-24 Thread dawkot
https://nim-lang.org/docs/math.html#round%2CT%2Cint

Is there a reliable way to round?

2021-04-24 Thread xioren
Thanks, will give those a try.

Is there a reliable way to round?

2021-04-24 Thread Symb0lica
I'd suggest either import strutils echo formatFloat(9.779,format=ffDecimal,precision=2) Run or import strformat echo &"{9.779:0.2f}" Run

Deploying an app on Heroku (Jester)

2021-04-24 Thread GreyBeard
Hello there! hope you're well and safe. I'm very new to Nim and I'm trying to deploy an app on Heroku, Heroku seems to block Jester from serving static files (403s). I'm deploying this: I read on a blog that it might work using "nimassets", but I don

Is there a reliable way to round?

2021-04-24 Thread xioren
I understand the warning about floating point decimals in the docs but other languages have suitable rounding functions. For example: nim: round(9.779, 2) Run give 9.779 python: round(9.779, 2) Run gi

collision-resistant hash for 64bit pointers

2021-04-24 Thread jackhftang
Sample code of the above idea. Not verified =] import heapqueue import strutils import strformat import bitops import algorithm proc findMinCollision*(nVec: int, xs: seq[float]): (float, seq[int]) = var n = xs.len # ps[i] = probability of co

XML parsing performance

2021-04-24 Thread SolitudeSF
-d:danger

collision-resistant hash for 64bit pointers

2021-04-24 Thread jackhftang
Your problem can be viewed as noisy-channel encoding. Though in practice we map a block to larger space, your case is mapping to a smaller space, but the mathematical structure is the same. There is a family of coding call [linear code](https://en.wikipedia.org/wiki/Linear_code) . Given you **do

collision-resistant hash for 64bit pointers

2021-04-24 Thread cblake
As another example, if you had 48-bit addrs with FF's up top and 12-bit-aligned (4096) say virtual mem page-aligned, then you only have 36 bits. So, if you literally mask off the top 4 then instead of 64 Gigispots you'd have 4 GiSpots. If you are doing DLL/shared library load addresses you may n

nim-1.4.6_x64.zip/bin/nimble.exe reports as Trojan:Win32/Zpevdo.B

2021-04-24 Thread m33
Something like [Nullsoft installer](https://nsis.sourceforge.io/Main_Page) would be nice. But it won't solve compilers and tools exe files being wrongfully flagged as malware.

XML parsing performance

2021-04-24 Thread tcheran
Hi to all, I'm new to NIM, but for what I've seen so far, I like it a lot. I really hope NIM's community and NIM adoption will grow up. I was wondering if I could use NIM for some specific tasks I have to deal with, and one of these is (huge) XML files parsing. I've seen a bit the online documen

Creating Private Package List/Index

2021-04-24 Thread fengkehh
Hi all, I am considering using Nim as the language of choice to productionalize certain components of a model at my company. To do that however I have to figure out how to set up a private nimble package list/index so I can publish and maintain proprietary libraries without the public having an

collision-resistant hash for 64bit pointers

2021-04-24 Thread Zoom
> is there anything else about this domain i can use to maximize the collision > resistance of this mapping? say, a way to weight the lower bits more than the > higher I don't think you want any used bits to be weighted higher than other. In any case you'd be better off with testing for your sp

collision-resistant hash for 64bit pointers

2021-04-24 Thread cblake
If instead you took the lower bits of the full product of 42*42 of 86 bits (easy to do - just multiply in a uint64 and then mask to get the lower 32), then you would get less bit mixing, but more resistance in the small..like (I _think_ ) guaranteed non-collision of hashes from all or almost all

collision-resistant hash for 64bit pointers

2021-04-24 Thread cblake
I mean, if you really want you could assume 16-byte (SSE land) alignment from allocators and take the 42 bits you have left into two 32-bit misaligned numbers (say upper 32 and lower 32 of that 42), and then multiply those to spread them over the full 64-bit register and then mask out the upper

collision-resistant hash for 64bit pointers

2021-04-24 Thread cblake
It is important here to distinguish between collision resistance in terms of like a "self avoiding random walk" \- i.e. minimizing collision, and just "being close to random". Assuming you mean the latter, the regular `hash(uint64)` in the stdlib should be quite resistant when given 32-bit inpu

collision-resistant hash for 64bit pointers

2021-04-24 Thread shirleyquirk
this isn't Nim specific, of course, but how do i design a mapping from pointers in a single process's address space to int32 to minimize the likelihood of collision? To start with, i know that only the lower 48bits are used. and if i know the alignment of the pointer type i might be able to eli

nim-1.4.6_x64.zip/bin/nimble.exe reports as Trojan:Win32/Zpevdo.B

2021-04-24 Thread shirleyquirk
finish.exe executes scripts, downloads things and then executes them, modifying files all over the place. we know it's an installer, but if you didn't: pretty sus. maybe if it were an .msi it would be treated kinder?

Forcing comparison overloads for custom ref objects

2021-04-24 Thread b3liever
This should work: `proc `<`(a,b:refo):bool {.error.}`

Forcing comparison overloads for custom ref objects

2021-04-24 Thread shirleyquirk
how about: type refo* = ref object n*: string refb = ref object z*:int proc `<`[T](x,y:ref T){.error.} proc `<`(a,b:refo):bool = return a.n < b.n when isMainModule: let r2 = refo(n: "b") let r1 = refo(n:

Forcing comparison overloads for custom ref objects

2021-04-24 Thread drkameleon
OK, so... let's take this example: type refo* = ref object n*: string when isMainModule: let r2 = refo(n: "two") let r1 = refo(n: "one") echo $(r1 < r2) Run The program compiles fine and yields a result. The result is

nim-1.4.6_x64.zip/bin/nimble.exe reports as Trojan:Win32/Zpevdo.B

2021-04-24 Thread m33
Agree, reading [Opsec Considerations](https://github.com/byt3bl33d3r/OffensiveNim#opsec-considerations) from OffensiveNim I think we should keep an eye on over paranoid/lazy antivirus vendors that might someday flag binaries produced by nim.exe as malware (this is pure speculation, don't take t