Re: Custom default for type
Thanks for the clarification! I always thought the RFC was about the fancy syntax for default values, not the fundamental ability to set them; that I assumed had been possible somehow. Oh well, I'll use an explicit init proc then.
Re: Vapoursynth - optimization
> At this stage I can only recommend NOT to use VapourSynth.nim. It is too slow Please note that your first task would be to make it work with default refc GC and with arc GC. \--gc:none was only suggested for tests, as you reported that it crash with refc GC.| ---|--- For performance you would never use a seq[seq] for your filter matrix, but a continues block of memory which lives in the cache permanently. And you would like to use SIMD instructions. For SIMD you may try to code it manually, I think we have a simd module provided by mratsim, or you would write Nim code that can be converted by the Nim compiler in something for which the C compiler can apply SIMD instructions.
Re: Custom default for type
* RFC #49: [Enforce initialization in more contexts / everywhere / up to debate](https://github.com/nim-lang/RFCs/issues/49) * RFC #172: [dependent types, restricted types or generalization of the range types](https://github.com/nim-lang/RFCs/issues/172) There's a similar problem when you define a range type whose default value is not in the range.
Re: Nested list comprehension
I don't see "collect" used in that comprehension module at all. Also, **comprehension** is slightly broken with nim-1.0.0. I haven't tried nim-devel yet. (I can only use official releases at work.)
Looking for a new home for Nimz3
Some time ago I made a little Nim binding and DSL around the Z3 theorem prover, which can be found at [https://github.com/zevv/nimz3](https://github.com/zevv/nimz3). I made this mostly for fun and learning purposes, but never got to properly maintain or document it. Nimz3 has recently be picked up by Araq for the new "DrNim" project, and I start getting some issues and pull requests on the repo as well. Unfortunately I currently lack both time and motivation to give this package the love it deserves, so I'm looking for someone who wants to adopt to prevent it from gathering dust and unanswered github issues.
Re: Custom default for type
I understand the question. You can't override how a type is initialized in Nim
Re: Custom default for type
[https://nim-lang.github.io/Nim/manual.html#implementation-specific-pragmas-codegendecl-pragma](https://nim-lang.github.io/Nim/manual.html#implementation-specific-pragmas-codegendecl-pragma) ? Not sure if I understand the question tho.
Re: Nim Bugs
New version of nimbug with improvements from user feedback, feel free to give it a try. :)
Custom default for type
Hi! How do I set a default value for a type that doesn't have any? For example, an object or DateTime? I know there's `default` proc that gets the default value for a given type but I couldn't figure out how to use it.
Re: Vapoursynth - optimization
At this stage I can only recommend NOT to use VapourSynth.nim. It is too slow (not because of nim, but I cannot find out why). Testing the convolution filter in Python: import vapoursynth as vs core = vs.get_core() core.std.SetMaxCPU('none') clip = core.std.BlankClip(format=vs.GRAYS, length=10, fpsnum=24000, fpsden=1001, keep=True) clip = core.std.Convolution(clip, matrix=[1,2,1,2,4,2,1,2,1]) clip.set_output() Run So I get: $ vspipe test.vpy /dev/null Output 10 frames in 26.73 seconds (3740.91 fps) My version: import ../vapoursynth import options BlankClip( format=pfGrayS.int.some, width=640.some, height=480.some, length=10.some, fpsnum=24000.some, fpsden=1001.some, keep=1.some).Convolution(@[1.0,2.0,1.0,2.0,4.0,2.0,1.0,2.0,1.0]).Null Run so: $ nim c -f --gc:none -d:release -d:danger modifyframe $ time ./modifyframe real0m37,872s user0m38,989s sys 0m1,997s which is: 2640.47fps On the other hand you can create your own filters. In that regard, I have managed to apply a simple Gauss filter to 10frames in: $ time ./modifyframe real8m25,425s user8m24,112s sys 0m5,422s which is 198fps. Way too slow when compared with the C++ version.
Re: Problems with var return type
> Is it just not possible to wrap a var in an Option? Yep, it's not possible to put `var T` fields in objects (though it might be possible in the future). The compiler does allow putting them in tuples though it doesn't behave very well (what if you don't initialize the var T?).
Problems with var return type
I am not sure that I am understanding how the var return type work, I have this code: proc findComponent*(e: var Entity, T: typedesc): Option[var T] = for c in e.components.mitems: if c of T: result = some(T(c)) result = none(var T) Run I am trying to find a component in e, then return an var of that component, I get this error: Error: type mismatch: got but expected 'Option[var None]' Run What does the `var None` in the return type mean? Is it just not possible to wrap a var in an Option?
Re: Announcement: The Nim compiler is rewritten in Python with some modules optimized in C
You had me there for a few minutes @Araq, fair play :)
Re: Announcement: The Nim compiler is rewritten in Python with some modules optimized in C
today I don't eat fish (lol) on April 1st rewrite all that in Python ... and why not in gwbasic with the one opening on the assembler
NRE documentation inconsistency?
Hi all I have a big PCRE regex, that have conditional named groups. I want to reference all of the groups, even if match didn't occur and handle it on my side with simple if or something like this. As nre [documentation](https://nim-lang.org/docs/nre.html) states: captures[]: string the string value of whatever was captured at that id. If the value is invalid, then behavior is undefined. If the id is -1, then the whole match is returned. If the given capture was not matched, nil is returned. "abc".match(re"(\w)").get.captures[0] == "a" "abc".match(re"(?\w)").get.captures["letter"] == "a" "abc".match(re"(\w)\w").get.captures[-1] == "ab" Run I can do that and get nil, if pattern was not matched. But actual nre code contains this: func checkNamedCaptured(pattern: RegexMatch, name: string): void = if not (name in pattern.captureBounds): raise newException(KeyError, "Group '" & name & "' was not captured") ... func `[]`*(pattern: Captures, name: string): string = let pattern = RegexMatch(pattern) checkNamedCaptured(pattern, name) return pattern.captures[pattern.pattern.captureNameToId[name]] Run Which throws error if named group was not matched.
Re: Natural language processing
You can also find examples in: [https://github.com/Nim-NLP](https://github.com/Nim-NLP)
Re: Template - how to prefix a function's name
Oh yes, I could have made that more clear. Indeed, the default type is untyped. Both for the arguments as well as the return type. And yes, untyped is required to make this work. Essentially untyped is just considered as a raw Nim identifier (nnkIdent in macro terms). If you used string as an argument, the compiler would understand that as a string at runtime. Since the name of the generated proc / etc. has to be known at compile time of course, this wouldn't work. You _can_ (although I don't think with a template) hand a static string, which is a string known at compile time and extract an identifier from the string. But unless you do more complicated macro things where you might want to calculate names of procs you want to generate, this won't be much different than just handing a raw identifier. An example: import macros macro genproc(prefix: static string): untyped = let procName = ident(prefix & "World") result = quote do: proc `procName`() = echo "Hello world" genProc("hello") # works, string literal is static helloWorld() const foo = "alsoHello" genProc(foo) # a const string is known at CT alsoHelloWorld() # and also proc getName(): string = result = "finalHello" var bar {.compileTime.}: string static: bar = getName() # some CT computation genProc(bar) finalHelloWorld() Run