Re: Incompatible type runtime error with table assignment
Please report this on github too.
Re: Godot and Blender
hi mike you are not misunderstanding I am just inexperienced and busy learning this. My understanding was that blender uses python but I would have thought that using Nim in its place would make everything much faster. And since Nim and Python are roughly the same it wouldn't be that much of a leap. Especially something like Godot that uses gdscript. I must say it is quite amazing time to have such amazing tools available in opensource. I hope I can learn it to get to a point where I can use all 3 together.
Re: How to get rid of [ProveInit] warning?
> I know that an openArray in proc parameters is read only, but the nim > compiler will copy its values to result if compatible. No it will not copy anything. Nim Arrays work like C arrays. It would be equivalent to the C code: void *arr= const void* openArray Run It creates a mutable reference, which cannot happen. It's similar to a Rust borrow. > You can do that because I've used an array instead of a seq[Val] in my small > example. When using a dynamic array whose size is not known at compile time, > you can't write such code (and that's the reason I used an openArray in my > example). You can write such code! It's easier with a seq[Val] because it computes the size at runtime. Here is your first example using seq: [https://play.nim-lang.org/#ix=23Qp](https://play.nim-lang.org/#ix=23Qp) Here is your second example with seq: [https://play.nim-lang.org/#ix=23Qr](https://play.nim-lang.org/#ix=23Qr) > I should have been able to call the initGa proc with an array[int] and return > an array[Val] as int and Val are compatible. No! That should not be allowed at all. Int and Val are not compatible! They are distinct types! This is an important feature of Nim that prevents mistakes. Specifically, in your example the Int(0) is not a valid Val type. Nim prevents you from making this mistake. Nim types are like a Ada types. Just because two types are binary compatible does not mean they are semanticaly compatible (this is why we have the distinct keyword like type meter = distinct Int You cannot convert an int type to a meter type without explicit casting. Range type works the same way. > As Board items default values '0' are not in Val, the compiler will complain > with the [ProveInit] warning, and because that's a multidimensional array, I > can't tell the compiler that it is initialized if I use multiple > initialization loops. You would not use multiple initialization loops. You would write something like this: result = array[ array[Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A')], array[Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A')], array[Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A')], array[Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A')], array[Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A')], array[Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A')], array[Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A')], array[Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A')], array[Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A')], array[Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A'),Val('A')], ] Run > What I'm missing... a way to specify a default initializer for the Val type, > that would be called by the compiler when creating a new variable of type > Val, particularly for array and collections. What you need is a default initializer for **array**. It has nothing to do with val. I do think Nim should auto initialize the result variable. I'm not sure if this is a bug in the "proveInit" algorithm or a bug in the way nim is initializing result. It may be worth a bug report but I'm not sure. as an alternative, I wrote a macro to "initialize" arrays for you: [https://play.nim-lang.org/#ix=23QD](https://play.nim-lang.org/#ix=23QD)
Incompatible type runtime error with table assignment
Hello, I was trying to compile pakku in Artix Linux with the latest stable packaged version of Nim, pakku is also available in Arch and other Arch related distros. I resolved the compile errors and have so far resolved some of the other deprecation warnings too. But I get a run time error in src/feature/syncinstall.nim after bin pkg updates and when AUR pkg updates are just starting to be processed. An assignment fails due to incompatible types but the types seem to be the same, also it worked before and compiles fine. I've tried various things, and though I specified the exact type of table with toTable, make a test table of the same type, taken from reading the output of some error messages, but it fails at run time. Changing it to a ref table variable won't compile, giving a type mismatch error. > let satisfied = toTable[package.PackageReference, syncinstall.SatisfyResult] > (pkgInfos.map(p => ((p.name, none(string), none(VersionConstraint)), > > > (false, p.name, some(p) > > testtable2 = initTable[package.PackageReference, > syncinstall.SatisfyResult](1024) > > testtable2 = satisfied This does not work!!! It didn't work without the 1024 either, I've been trying various random stuff. I don't know much Nim but it looks like it should work. That's basically what the original code does but it gives satisfied to a proc argument of that type instead. Sorry I don't really know how to explain this more concisely as the types and values are part of a larger app, and you need to have an AUR package in need of updating for 'satisfied' to contain a value, but it still fails when empty. It isn't that big really though and builds quickly. Any ideas for a simple fix? I could possibly make it not be a table and put the info in something like my testing seq [WrapperTuple] but that would mean altering all the other places it gets used too. The pakku author kitsunyan is (wisely? :) ) AWOL at present. This is the most up to date source: [https://github.com/brunomiguel/pakku](https://github.com/brunomiguel/pakku) $ nim -V Nim Compiler Version 1.0.4 [Linux: amd64] Compiled at 2019-11-27 Copyright (c) 2006-2019 by Andreas Rumpf active boot switches: -d:release -d:nativeStackTrace Extract from modified src/feature/syncinstall.nim #[ from src/package.nim: PackageReference* = tuple[ name: string, description: Option[string], constraint: Option[VersionConstraint] ] from this file: SatisfyResult = tuple[ installed: bool, name: string, buildPkgInfo: Option[PackageInfo] ] ]# # let satisfied = pkgInfos.map(p => ((p.name, none(string), none(VersionConstraint)), # (false, p.name, some(p.toTable > let satisfied = toTable[package.PackageReference, syncinstall.SatisfyResult] > (pkgInfos.map(p => ((p.name, none(string), none(VersionConstraint)), > (false, p.name, some(p) > > let unsatisfied = lc[x | (i <\- pkgInfos, x <\- i.allDepends), > PackageReference].deduplicate # echo "pkgInfos =n", pkgInfos # echo "pkgInfos.map =n", pkgInfos.map(p => ((p.name, none(string), none(VersionConstraint)), (false, p.name, some(p # echo satisfied.type.name # echo "satisfied =n", repr (satisfied) var # testtable2 = newTable[PackageReference, SatisfyResult]() #Error: type mismatch: got #but expected 'TableRef[package.PackageReference, syncinstall.SatisfyResult]' testtable2 = initTable[package.PackageReference, syncinstall.SatisfyResult](1024) testtable1: Table[PackageReference, SatisfyResult] testnewseq1 = newSeq[WrapperTuple]() # echo "testtable1 =n", repr (testtable1) # echo name (satisfied) # name (pkgInfos) testnewseq1 = pkgInfos.map(p => ((p.name, none(string), none(VersionConstraint)), (false, p.name, some(p echo "testnewseq1 =n", testnewseq1 echo "satisfied =n", satisfied #Error: type mismatch: got # but expected 'seq[SatisfyResult]' #This worked with wrappertuple. And the table content looks just the same but in a table. echo "testtable2 assignment" testtable2 = satisfied echo "testtable1 assignment" testtable1 = satisfied echo "did that work?" #[ No it didn't. resolving dependencies... testnewseq1 = @[(packref: subtitleripper, satres: (installed: false, name: "subtitleripper", buildPkgInfo: Some((baseIndex: 0, baseCount: 1, archs: @["x86_64"], url: Some("[http://subtitlerippe](http://subtitlerippe) r.sourceforge.net/"), licenses: @["GPL"], groups: @[], pgpKeys: @[], depends: @[netpbm], makeDepends: @[make, gcc], checkDepends: @[], optional: @[], provides: @[], conflicts: @[ ], replaces: @[], repo: "aur", base: "subtitleripper", name: "subtitleripper", version: "0.5.2-2", description: Some("DVD subtitle to text converter"), maintainer: Some("init"), firstSubmitted: Some(1484683508), lastModified: Some(1574810177), outOfDate: None[int64], votes: 3, popularity: 0.382473, gitUrl: "[https://aur.archlinux.org/subtitleripper.git;](https://aur.archlinux.org/subtitleripper.git), gitSubdir: None[TaintedString]]
Re: Nim + Flutter == bright future?
Nim + Flutter, this could be the dream.
Re: Manual query "deviated" ?
It should be "derived from", I think, but then I'm the one who made the mistake to begin with...
Re: fileExists and existsFile. This made my day
how to know when it applies?
Manual query "deviated" ?
In the manual there's this example: proc forward[T](x: var T): var T = result = x # ok, deviated from the first parameter. Run The word _deviated_ is also used in the text above. But these uses all seem wrong to me. I _think_ the above comment ought to be `# ok, determined from ...` or `# ok, determined by ...`, and similarly in the text?
Re: How to get rid of [ProveInit] warning?
In you example, you shut up the compiler warning because you initialize `result` with static default values: proc initGa(a: openArray[int]): Ga = # no warnings! # openArray is not compatible with array! # this is why result = Ga(a) does not work result = [Val(10), Val(10), Val(10)] Here the compiler sees result as initialized for i in low(a) .. high(a): result[i] = Val(a[i]) Run That's the reason why the following lines can initialize the items with dynamic values. You can do that because I've used an `array` instead of a `seq[Val]` in my small example. When using a dynamic array whose size is not known at compile time, you can't write such code (and that's the reason I used an `openArray` in my example). I know that an `openArray` in proc parameters is read only, but the nim compiler will copy its values to result if compatible. From the [documentation](https://nim-lang.org/docs/manual.html#types-open-arrays), _Any array with a compatible base type can be passed to an openarray parameter, the index type does not matter_. I should have been able to call the `initGa` proc with an `array[int]` and return an `array[Val]` as `int` and `Val` are compatible. But that's another subject of discussion... In my code, the proc looks like: type Val = range['A' .. 'Z'] Board = array[1 .. 10, array[1 .. 10, Val]] Position = tuple[int, int] proc initBoard(pieces: seq[Position]): Board = # Now I must initialize result with default value, let say 'A' and # then fill it with the content of pieces. ... Run As `Board` items default values '0' are not in Val, the compiler will complain with the `[ProveInit]` warning, and because that's a multidimensional array, I can't tell the compiler that it is initialized if I use multiple initialization loops. What I'm missing either: * a way to specify a default initializer for the `Val` type, that would be called by the compiler when creating a new variable of type `Val`, particularly for `array` and collections. * a pragma that could convince the compiler that a variable is initialized. The first way is best but I don't know if it already exists. In fact, I think that this problem occurs only with `array` or collections as you can always initialize `object` fields with the default converter.
Re: Godot and Blender
As a long-time Blender user, Nim and Godot fan - I'm unsure what you mean. Blender already has a well documented Python API. Godot has Nim bindings, which others here have already linked to. Yes, Python is slow - but it is a scripting language that can be reloaded dynamically - which makes it ideal as an embedded language inside of an application such as Blender. I'm not sure how Nim would compare in this department, or even how it would get embedded in Blender.
Re: 3rd Party Library Documentation
[https://nimble.directory](https://nimble.directory) already does this I think, it has a button "hosted docs", that if your package has documentation will make HTML out of it.
Re: Is it possible to browse the nimble.directory?
nimble search
TXT DNS lookup
Hi, Newbie here - learning from the Nim book and working on pet project. I would love to use nim for networking tools. I've got stuck on making DNS queries. I am surprised there is nothing built into the standard library. What is the Nim way of looking up e.g. TXT? Should I be calling C code for it? Has anyone done this before? I've tried this, but I cannot believe one has to write a library for DNS lookups (it's also broken): [https://github.com/ba0f3/dnsclient.nim](https://github.com/ba0f3/dnsclient.nim) Thank you!
3rd Party Library Documentation
I have a suggestion which is a nice to have, there is an excellent choice that Nim already makes which is a Source & Edit link under every function documentation which links directly to the line in the Github Repo Would be nice if it someone how found its way to 3rd party libraries, useful for learning, understanding and just ease of use
Re: {.gcsafe.}, What does {.threadvar.} do to make a function gcsafe?
Anyway you stated you got an error accesing the global variable, if you don't compile your program with --threads:on you will get only a warning and it will compile correctly
Re: How to Maintain a Nim Chinese Community
i'm interested in a nim chinese community too, create a wechat group
Re: Nim is the friendliest language to start
willy you mentioned project creation & scaffolding ...currently making this, [https://github.com/adeohluwa/gen](https://github.com/adeohluwa/gen) come help use it for feedbacks
Re: Is it possible to browse the nimble.directory?
Unfortunately packages.json is not categorized and the tags are not based on structured classifiers, see [https://github.com/nim-lang/packages/pull/339](https://github.com/nim-lang/packages/pull/339) I'd be happy to add browsing pages if we had categories or if the Curated-Packages had a machine-parsable format
Re: Is it possible to browse the nimble.directory?
Thanks for your helpful replies: and to the others who've replied to my other questions.
Using setLen after newSeqOfCap is not safe?
* newSeqUninitialized doesn't initialize seq with zero. It's in the specifications. * When I use setLen after newSeqOfCap, expanded part of seq is not initialized with zero. * It's in the specifications, too? setLen after newSeqOfCap is not safe? const max_seq_size = 100 const max_itr_size = 10_000 var s: seq[int] for i in countup(1,max_itr_size): s = newSeq[int](max_seq_size) for j in countup(1, max_seq_size): s[j-1] = j s = newSeqUninitialized[int](max_seq_size) echo s[max_seq_size - 1] # 100 (not initialized with zero, in the specifications) s = newSeqOfCap[int](max_seq_size) s.setLen(max_seq_size) echo s[max_seq_size - 1] # 100 (not initialized with zero) Run
Re: Advent of Nim 2019 megathread
My first time participating in Advent of Code! [https://github.com/kaushalmodi/aoc2019](https://github.com/kaushalmodi/aoc2019) :)
Re: Is it possible to browse the nimble.directory?
See also [https://github.com/nim-lang/Nim/wiki/Curated-Packages](https://github.com/nim-lang/Nim/wiki/Curated-Packages) [https://github.com/VPashkov/awesome-nim](https://github.com/VPashkov/awesome-nim)
Re: Is it possible to browse the nimble.directory?
You can look here, is just a JSON [https://github.com/nim-lang/packages/blob/master/packages.json](https://github.com/nim-lang/packages/blob/master/packages.json)
Is it possible to browse the nimble.directory?
The [https://nimble.directory](https://nimble.directory)/ has a good search function, but in reaquainting myself with nim I'd like to be able to see categories and browse. Is this possible?
Re: What are the compiler defaults? etc...
* you can see defaults in nim.cfg supplied with the compiler. * check styleCheck compiler option. * there is no runtime cost. * koch tools builds nimble.
Re: What are the compiler defaults? etc...
* Not easy to answer, roughly speaking all runtime checks are active by default and you get a debug build. * Use the new `--styleCheck:error` compiler option. * Imports have no runtime cost and Nim optimizes procs out that you don't use. * Here is the section of koch.nim of "tools": buildTools(op.cmdLineRest) buildNimble(latest, op.cmdLineRest) Run as you can see, "koch tools" does bulid Nimble. > What I'm looking for is a language as convenient and fast to develop with as > Python but with static typing, easy deployment (single executable), and > C-speed runtime. Which is why I'm trying nim again. Sounds like a good description of Nim for me.
What are the compiler defaults? etc...
* In [https://nim-lang.org/docs/nimc.html](https://nim-lang.org/docs/nimc.html) it shows all the compiler options, but it doesn't seem to show the defaults. How can I find out what they are? * Is there a pragma that would force names to be fixed? For example, if I do _import mod_ and get **afunc** in my namespace, what I also get in effect is **aFUNC** , **aFunc** , etc., whereas I'd prefer just one. (I realise this is unlikely to be available or even possible.) * Is there any _runtime_ cost in doing _import mod_ compared with _from mod import foo, bar_? Is _import mod_ recommended rather than _from mod import ..._? * On Windows I used the prebuilt .zip but on Linux I built it myself. I think it might be worth adding to the instructions to run _. /koch nimble_ since _. /koch tools_ doesn't seem to build nimble. * Incidentally I tried nim a couple of years ago and gave up mainly because I couldn't get it to reliably install on Windows. Now I've installed on Linux and Windows and _finish.exe_ works fine. It gave an error when it came to fetch mingw but instead of giving up it offered to get it from nim's site and when I said yes it "just worked". What I'm looking for is a language as convenient and fast to develop with as Python but with static typing, easy deployment (single executable), and C-speed runtime. Which is why I'm trying nim again.