Is this expected behaviour?
var x {.compileTime.} = false static: x = true echo x Run > false
Re: Introducing --gc:arc
Well, changing to inherit from `CatchableError` did not alone fix things (though that is clearly a thing I should have done long ago, and I think separating bugs from unusual control flow is a Good Thing). I did catch these when compiled with `-d:danger/-d:release` for the past 2.5 years, though. I will try to work on a proper minimum reproducing example/bug report tomorrow. Been busy.
exportc pragma and ref object
When I compile the following code: import strutils type Token {.exportc.} = object typ: cint val: cstring proc exportc(a: Token) {.exportc.} = let msg = "Token (type, value): ($1, $2)" % [$a.typ, $a.val] echo msg Run with nim c --header exportc.nim Run I get a header file with the following snippet: typedef struct Token Token; struct Token { int typ; NCSTRING val; }; N_NOCONV(void, signalHandler)(int sign); N_NIMCALL(NI, getRefcount)(void* p); N_NIMCALL(void, exportc)(Token a); N_CDECL(void, NimMain)(void); Run which is what I expect and can then call from a c main function. However, if I change the object to a ref object Token {.exportc.} = ref object typ: cint val: cstring Run I get a header file with the following: typedef struct tyObject_TokencolonObjectType___My6xn9bSiVikjAjVy7Y8xcA tyObject_TokencolonObjectType___My6xn9bSiVikjAjVy7Y8xcA; N_NOCONV(void, signalHandler)(int sign); N_NIMCALL(NI, getRefcount)(void* p); N_NIMCALL(void, exportc)(tyObject_TokencolonObjectType___My6xn9bSiVikjAjVy7Y8xcA* a); N_CDECL(void, NimMain)(void); Run So for a ref object the exportc pragma doesn't stop name mangling which makes calling from c a pain. Is this a bug or is there something about reference objects I'm not comprehending. Thanks, Jason
Re: Introducing --gc:arc
> fully document this change. I'm waiting for a bug report because I bet it is a bug and not the deliberate choice to map IndexError et al to quit. Consider that code that catches these errors already was broken with `-d:danger` too and for years `-d:release` was what is now `-d:danger`.
Re: How do I initialize a set of range?
Like so: type OneTo10 = range[1..10] let somePrimes = {2.OneTo10, 3, 5, 7} Run
How do I initialize a set of range?
This code: let somePrimes: set[1..10] = {2, 3, 5, 7} Run gives: Error: type mismatch: got but expected 'set[range 1..10(int)]' Run How do I initialize a set of range?
Re: new experimental nim plugin for neovim
A [demo](https://asciinema.org/a/276278) on debugging in neovim: \-- I made this a long time ago, but forgot to share it on the forums.
Re: stdlib pegs: Accessing optional subexpressions
Thanks! I had heard of `npegs`, but so far chose `pegs` because it's in the standard library and understands standard PEG syntax. That said, `npeg`'s features are very impressive. :-) > Afaik, stdlib peg is designed for nim compiler itself and somewhat limited. So I guess there's not much motivation to enhance this module? Probably it would be easier to implement a standard PEG parser with `npegs` as part of `npegs` than enhance the `pegs` module? ;-)
Re: new experimental nim plugin for neovim
Ah ok, thanks :)]
Re: Setup Nim with Vim/NeoVim
Nowadays, with vim 8 & neovim's `packages` feature (see `:h packages`) it has never been easier to maintain a full setup that you can just clone from your git and got everything working right after :) > For some reason, I couldn't get vim embedded instructions to do the tabs > properly. I don't what the problem was. I tried using nvim, and it seemed > more cooperative. How did you set it up?
Re: Setup Nim with Vim/NeoVim
One thing I really hate about Nim is its use of whitespace, particularly in regards for disallowing tabs. I've been going pluginless for a couple of years now, and want to keep it that. I like to be able to get my installations from 0 to working in as little time as possible. For some reason, I couldn't get vim embedded instructions to do the tabs properly. I don't what the problem was. I tried using nvim, and it seemed more cooperative.
Re: Introducing --gc:arc
> At present I can get cligen things (like that example bench above) to compile > and run ok, but with gc:arc invoking with --help raises a HelpOnly exception > that then dumps core. Current runtime seems to think the exception is > unhandled. (Haven't looked into it further.) [https://github.com/nim-lang/Nim/issues/10288](https://github.com/nim-lang/Nim/issues/10288) My guess is that `--exception:goto` will abort on `Defect` instead of trying to handle it, and `Exception` inherits `Defect`. Try rebasing your types to `CatchableError` instead.
Re: new experimental nim plugin for neovim
`zf` is for creating fold :) To close one you use `zc`. See `:h fold-commands` for further folding magic.
Re: missing rules in grammars.txt
Sorry, I made it a showstopper bug, will be fixed anytime soon now.
Re: Newbie question: Why am I getting the too many variables error on my loop index variable?
Aha: success for myKey, myValue in readFile(day02PathAndName).split(',').pairs(): result[myKey.int64]=myValue.parseInt Run
Re: Newbie question: Why am I getting the too many variables error on my loop index variable?
It might be more productive if I advise you that I spent several days perusing the nim documentation before I admitted defeat and asked a question here. @Solitude's comments highlighted something that is not adequately referenced when you read the for loop section of the manual.
Re: Newbie question: Why am I getting the too many variables error on my loop index variable?
I'll have to wait until my knowledge of nim improves before I can that. In the meantime I'm using let mySeq:seq[string]=readFile(day02PathAndName).split(',') for myKey, myValue in mySeq: result[myKey.int64]=myValue.parseint.int64 Run
Re: new experimental nim plugin for neovim
Still using this plugin lots - and works great! One thing I'm wondering about is opening and closing sections. It's nice to have top-level things collapsed when a file is first opened, and I can just open the section I'm interested in. Only thing is, I'm not sure how to close a section after it's been opened. I tried out `zf` on a section, but just got a E350: Cannot create fold with current 'foldmethod'. So maybe this isn't an issue with this plugin, but some generic nvim config? Either way I figured someone on this thread would know.
Re: Newbie question: Why am I getting the too many variables error on my loop index variable?
Seems to be a use-case for Nim's csv parser, [https://nim-lang.org/docs/parsecsv.html](https://nim-lang.org/docs/parsecsv.html)
Re: Setup Nim with Vim/NeoVim
As a shameless plug, but I made one of the most featureful Nim plugin for neovim :) Check it out at [https://github.com/alaviss/nim.nvim](https://github.com/alaviss/nim.nvim)
Re: Newbie question: Why am I getting the too many variables error on my loop index variable?
Sorry for being lazy earlier and for my poor English. What I meant was this: import strutils var file = """ Hello,World Key,Value """ for line in file.split("\n"): # iterator returns string var data = line.split(",") # proc returns seq[string] # but there is no version of split you can use as "for myKey, myValue in" if data.len() == 2: echo data[0]," = ", data[1] Run
Re: Newbie question: Why am I getting the too many variables error on my loop index variable?
invoke items/pairs iterator explicitly
GitHub Actions to lint Nim code
I wrote a GitHub Actions to lint Nim code. nimlint-action is inspired by [reviewdog/action-eslint](https://github.com/reviewdog/action-eslint). [https://github.com/jiro4989/nimlint-action](https://github.com/jiro4989/nimlint-action) This action notices compile message to Pull Request. Examples. import strutils echo "hello world" Run Nim prints **Warning:** if you compile this code. /tmp/main.nim(1, 8) Warning: imported and not used: 'strutils' [UnusedImport] Run This action notices these message ( **Hint:** , **Warning:** , **Error:** ) to Pull Request.
Re: Compilation failure 1.0.4 on Pi3
I'm using Raspbian on a Pi3 (and Pi2). The version of nim in the repo is fairly old. I'm now just going with the simplest solution: using the nightly build that I indicated above. It works, so I'm happy. I'm using GCC v 8.3.0 on the Pi 2 and 3. I do most of my work on an x84_64.
Re: Newbie question: Why am I getting the too many variables error on my loop index variable?
On further reading it seems there is a split proc and a split iterator. The former returns a sequence of substrings. The code I have seems to be using the iterator version. How would I indicate to nim to use the proc rather than the iterator version of split?
Re: Newbie question: Why am I getting the too many variables error on my loop index variable?
there is no split iterator that returns two values at a time. you're confusing it with sequence and implicit pairs. you have to keep track of the indexes on your own here.