<< 15-07-2017 >>

00:19:19*Guest24175 quit (Quit: My MacBook has gone to sleep. ZZZzzz…)
00:22:52*skrylar_ quit (Ping timeout: 260 seconds)
00:28:53SentreenIs it intended behaviour that a proc with the following signature: `proc foo(a: int, b: int = procWithSideEffect())` will call `procWithSideEffect` for every call with foo where b is not provided?
00:29:59*yglukhov quit (Remote host closed the connection)
00:30:02SentreenI know that in python the value of the optional will be cached for later use. So I was just wondering about the rationale behind the choice :)
00:32:13*Vi- quit (Ping timeout: 260 seconds)
00:36:02*xet7 quit (Quit: Leaving)
00:38:00*yglukhov joined #nim
00:39:42*yglukhov quit (Remote host closed the connection)
00:39:46*nsf quit (Quit: WeeChat 1.7.1)
00:40:15*yglukhov joined #nim
00:44:27*yglukhov quit (Ping timeout: 240 seconds)
00:49:35*ludocode_ quit (Ping timeout: 240 seconds)
00:49:58*Vi- joined #nim
00:50:24*Vi- quit (Read error: Connection reset by peer)
00:52:20*ludocode_ joined #nim
01:02:43*smt__ quit (Ping timeout: 276 seconds)
01:11:40*Snircle joined #nim
01:15:46*v17d quit (Remote host closed the connection)
01:20:07FromGitter<ephja> has anyone had asyncnet.connect not result in an error when it can't connect?
01:24:30*chemist69 quit (Ping timeout: 240 seconds)
01:35:26FromGitter<ephja> ```code paste, see link``` [https://gitter.im/nim-lang/Nim?at=5969715ebf7e6af22cdcbe68]
01:38:39*chemist69 joined #nim
01:51:25FromGitter<watzon> Does num have union types or something similar? For instance, if I wanted to make a multi dimensional table in a language like Typescript I'd do: ⏎ ⏎ ```type MultiDimTable = TableRef[string, string | int | float | MultiDimTable]``` [https://gitter.im/nim-lang/Nim?at=5969751dc101bc4e3a87812e]
01:51:39FromGitter<watzon> But that doesn't seem to work in Nim
01:54:26FromGitter<ephja> @watzon https://nim-lang.org/docs/manual.html#types-object-variants
02:04:25*skrylar joined #nim
02:11:20FromGitter<watzon> @ephja So that's the only way to have a parameter with multiple possible types?
02:13:30FromGitter<ephja> @watzon you mean at compile time?
02:15:39FromGitter<watzon> @ephja yeah, something like c++'s `union` http://www.cplusplus.com/doc/tutorial/other_data_types/#unions
02:18:28FromGitter<ephja> a variant is the equivalent of that except that it's strongly typed
02:19:29FromGitter<ephja> https://github.com/andreaferretti/patty this lib simplies it, but I dunno if it will work with your particular compiler version
02:41:41*yglukhov joined #nim
02:43:15*Snircle quit (Quit: Textual IRC Client: www.textualapp.com)
02:43:59skrylarah nim unions. those are 'case types' iirc
02:45:16skrylari think nim lacks those on account of garbage collector safety. there is a way to force them with the {.union.} tag iirc, but those have restrictions against GC types being in them
02:46:05*yglukhov quit (Ping timeout: 240 seconds)
03:14:57*skrylar quit (Ping timeout: 240 seconds)
04:43:37*yglukhov joined #nim
04:47:57*yglukhov quit (Ping timeout: 240 seconds)
05:10:05FromGitter<Varriount> Nim has tagged unions (otherwise known as type variants).
06:12:01*skrylar joined #nim
06:15:36*andrzejku joined #nim
06:22:12*ShalokShalom joined #nim
06:33:05*skrylar quit (Ping timeout: 240 seconds)
06:45:43*yglukhov joined #nim
06:46:56*v17d joined #nim
06:51:13*yglukhov quit (Ping timeout: 248 seconds)
07:16:26*yglukhov joined #nim
07:22:21*skrylar joined #nim
07:44:36*Trustable joined #nim
07:59:23FromGitter<Varriount> I wonder how feasible it would be to have a "carray" type for sequences, on par with the cstring type
08:24:08*yglukhov quit (Remote host closed the connection)
08:25:55*Vladar joined #nim
08:43:59*yglukhov joined #nim
08:45:05*v17d quit (Ping timeout: 240 seconds)
09:09:05*gokr joined #nim
09:20:05gokrskrylar: The Red/System duality is similar to what I envision with Spry/Nim.
09:20:40gokrEventually I am also contemplating partial compilation - for deployment. Have a small article exploring that a bit.
09:21:21gokrSpry is also meant to be very DSL friendly, since it borrows a similar flexibility in "syntaxlessness" that Rebol (and also Smalltalk) has.
09:21:26gokrOk, off to the pool.
09:33:45FromGitter<watzon> Anyone know why I'd be getting an error while trying to create a sequence with more than 10 items? I'm trying to do this : ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ but the linter is giving me an error: `Identifier expected, but found '".ttf"'` [https://gitter.im/nim-lang/Nim?at=5969e179f5b3458e304b9632]
09:34:18FromGitter<watzon> Never mind
09:34:32FromGitter<watzon> I'm stupid
09:46:48ZevvIs there a way to make the nim compiler less verbose. I'd prefer no output at all when everything is OK
09:46:57Zevvall these 'hints' are a bit cluttering
09:47:45Zevv--verbosity:0 does not seem to help
09:49:00ZevvOh, --hints:off does the job. Sorry for asking first and reading later :/
09:51:44*couven92 joined #nim
10:03:46*Matthias247 joined #nim
10:15:42*tankfeeder_ joined #nim
10:16:00*tankfeeder_ quit (Client Quit)
10:17:26*Ven joined #nim
10:17:33*Ven quit (Client Quit)
10:20:02Zevvg/c
10:20:43*v17d joined #nim
10:24:17*v17d quit (Remote host closed the connection)
10:32:40*skrylar quit (Ping timeout: 246 seconds)
10:39:53FromGitter<zacharycarter> o/ morning all
10:53:37*dddddd joined #nim
10:56:40*sz0 quit (Quit: Connection closed for inactivity)
10:56:47*skrylar joined #nim
11:15:52FromGitter<watzon> Is there an easy way to turn an object into a string for logging purposes?
11:16:01skrylarrepr
11:24:29FromGitter<watzon> Thanks skrylar
11:27:52*Sentreen quit (Ping timeout: 260 seconds)
11:38:34*nsf joined #nim
11:40:18*Ven joined #nim
11:40:41*Ven is now known as Guest52311
11:41:45*Sentreen joined #nim
11:43:32FromGitter<TiberiumN> Hmmm, currently I have "modules" in my app, and all modules are compiled with main application in one .exe. ⏎ I want to split my modules to different .dlls, but here's the problem: My application and my modules are async, and my modules can call main application (for api call). ⏎ Is it possible to split my modules to dlls in such use case?
11:44:00skrylari don't know that nim likes DLLs
11:44:19FromGitter<TiberiumN> I mean I know that I'll need to use something for wrapping
11:44:31FromGitter<TiberiumN> but main problem is that I need my app and my modules be fully async
11:46:51FromGitter<TiberiumN> and I need to call some procedures which are defined in my main app from my modules (and asynchronously)
11:48:18*Sentreen quit (Ping timeout: 260 seconds)
11:56:36*Trustable quit (Remote host closed the connection)
11:58:23*nsf quit (Quit: WeeChat 1.7.1)
12:00:40*Sentreen joined #nim
12:12:57*Sentreen quit (Ping timeout: 240 seconds)
12:19:36ZevvI want to get a key from a table or fallback to 'nil' if it does not exist, what is the idiom for this?
12:19:59yglukhovZevv: getOrDefault?
12:20:10ZevvThanks
12:22:01ZevvI guess that what I would *really* need is a JSON 'to' which allows for optional fields
12:24:43*Tiberium joined #nim
12:24:49skrylarah the wonders of needing nillable types :\
12:25:00ZevvYeah I just found my first SIGSEGV on nim
12:25:34skrylarNitpick about json serialization: you would need to have something like haskells Maybe type. as the lack of a value in a table sometimes has separate semantics to that value being assigned to nil.
12:25:51ZevvTrue, true
12:25:54ZevvI'm not nitpicking
12:26:02skrylardoing up Maybe is not hard. hacking the json serializer to support it? dunno
12:26:17skrylaryou'd have to either vendor it or get araq onboard. though i think he's already for nillable types at some point?
12:26:26*Sentreen joined #nim
12:26:37ZevvThere is no single right answer
12:26:55ZevvI'm very nil-aware because of my C/Lua background, so I'm basically fine
12:27:18skrylaryou can define your own tags on fields of objects and then {.mystuff.} it on there
12:27:28Zevvalthough having the magical-mystical type system solve all my problems would be sweet, of course
12:27:44skrylarso iirc its already possible to have your own {.optional: somedefault.} type tag, and a macro to generate a serializer to support it
12:29:09skrylargo also supports this but you have to do runtime reflection to extract the attributes. nim has you do compile-time reflection to do it
12:29:27skrylarso AFAIK what you want is possible so long as someone did the macro :3
12:30:12ZevvHmjeah, I get about 60% of what you're talking about here at this point. For now I'm adding my own method to JsonObject to extract a value only if it is there, that does the job for me
12:33:32dom96Zevv: That's planned (optional fields in 'to')
12:33:56dom96we have an Option[T] type in the stdlib for this
12:34:02Zevv\o/
12:34:57ZevvAnd another one: is there a way to define default values for object members without having to explicitely assign those in the constructor?
12:36:00ZevvOh the Option[T] is basically a Maybe
12:37:00dom96nope
12:38:05Zevvok
12:45:17*skrylar quit (Quit: My iMac has gone to sleep. ZZZzzz…)
12:48:08ZevvIs there a pretty-printer for 'arbritary' data in the standard library?
12:48:23Zevvlike repr(), but multi-line with indenting, etc?
12:53:15*skrylar joined #nim
12:53:30FromGitter<lateefj> Hello. I think I found a bug in the Freebsd thread code and patch it in my fork (https://github.com/lateefj/Nim/tree/fix_freebsd_threadid_call). Should I submit this as a PR to the devel branch?
12:57:19Araqyup
12:59:35FromGitter<lateefj> Thanks
13:00:53*Snircle joined #nim
13:02:35*Sentreen quit (Ping timeout: 246 seconds)
13:06:22*gokr quit (Quit: Leaving.)
13:08:05*ShalokShalom quit (Ping timeout: 240 seconds)
13:08:58*ShalokShalom joined #nim
13:15:13*skrylar quit (Ping timeout: 260 seconds)
13:15:49*Sentreen joined #nim
13:16:48*ShalokShalom quit (Ping timeout: 258 seconds)
13:24:36*nsf joined #nim
13:27:50*Sentreen quit (Ping timeout: 240 seconds)
13:37:07dom96Araq: This no longer compiles: https://gist.github.com/dom96/7e97d02f974b391e9e60d157f461b225
13:37:25dom96It's in my book and I'm fairly sure it did compile at some point in time.
13:37:36dom96Perhaps pre 0.16.0 even
13:37:52Araqit never was supposed to work, afaict
13:37:52dom96Any chance this is a regression?
13:38:15Araqyeah, but once T is inferred to 'int', there is no back tracking to make it 'float'
13:38:30dom96hrm, okay
13:38:35dom96I'll just remove this example from the book then
13:38:37Araqhowever, maybe we can infer it to 'int literal' and then mutate it to 'float' like it once was
13:39:11Araqbut these implicit conversions just suck
13:39:26Araqthey always bite back, sooner rather than later
13:41:08Araqdom96: no need to remove the example, all you need to do is to replace 5 by 5.0
13:41:13*Sentreen joined #nim
13:41:29dom96The example is to show that Nim infers types well
13:41:35dom965.0 doesn't make sense
13:52:41yglukhovAraq: how does gc work in threadpool? say, i've allocated lots of crap in a threadpool, and went back to main thread, and never going to use threadpool again. is that memory reclaimed?
13:53:22Araqthe threads linger on keeping their heaps
13:53:57yglukhovand i suspect GC_fullCollect on the main thread will not help here, right?
13:54:08Araqyou need to call GC_fullcollect() in the respective thread
13:54:17dom96another thing that doesn't work anymore: https://gist.github.com/dom96/745b42a06ee46c14d34f260e4bd9c343
13:54:27dom96That surely is a regression
13:54:53dom96bbl
13:54:58yglukhovAraq ok, thanks
13:55:00Araqdom96: no doubt it's a regression
13:55:17yglukhovAraq: but something should be done about it, imo
13:56:15Araqseems hard, not even the threadpool has access to the heaps
13:58:30yglukhovAraq: maybe at least i could spawn a proc on all available threads?
13:59:12yglukhovi mean, guaranteed way =)
13:59:21Araqhe, that's awesome
13:59:45yglukhovand then the threadpool.sync could do that e.g.
13:59:50yglukhovimplicitly
13:59:59yglukhovor explicitly, whatever
14:00:13Araqpass a "cleanup = false" flag to sync
14:00:23yglukhovok
14:00:31yglukhovbut how do i do that? )
14:00:47yglukhovi don't see a way currently
14:15:00*Guest52311 quit (Quit: My MacBook has gone to sleep. ZZZzzz…)
14:15:17Araqyglukhov: not sure, but you'll figure out
14:15:59*Ven joined #nim
14:15:59*Ven quit (Client Quit)
14:17:02*gmpreussner quit (Quit: kthxbye)
14:21:36*gmpreussner joined #nim
14:21:39*Matthias247 quit (Read error: Connection reset by peer)
14:21:46*jsgrant_ joined #nim
14:21:49*nhywyll joined #nim
14:52:41*smt joined #nim
15:04:15*Arrrr joined #nim
15:04:32*Arrrr quit (Changing host)
15:04:32*Arrrr joined #nim
15:17:49*byte512 joined #nim
15:18:04*gangstacat quit (Ping timeout: 240 seconds)
15:20:16*Ven joined #nim
15:20:40*Ven is now known as Guest99595
15:22:04*Arrrr quit (Ping timeout: 240 seconds)
15:22:58*gangstacat joined #nim
15:40:48*Sentreen quit (Ping timeout: 260 seconds)
15:43:57*ShalokShalom joined #nim
15:47:20*gokr joined #nim
15:54:36*Sentreen joined #nim
15:58:32*gokr quit (Ping timeout: 260 seconds)
15:59:50*Sentreen quit (Ping timeout: 240 seconds)
16:03:00*v17d joined #nim
16:11:32*v17d quit (Remote host closed the connection)
16:13:01*Sentreen joined #nim
16:13:54*Guest99595 quit (Quit: My MacBook has gone to sleep. ZZZzzz…)
16:13:56*v17d joined #nim
16:14:38*Ven joined #nim
16:15:01*Ven is now known as Guest27471
16:16:20*v17d quit (Remote host closed the connection)
16:16:21*Guest27471 quit (Client Quit)
16:17:06*v17d joined #nim
16:19:36*v17d quit (Remote host closed the connection)
16:21:06*v17d joined #nim
16:43:40*v17d quit (Remote host closed the connection)
16:44:53*v17d joined #nim
16:47:55*Jesin quit (Quit: Leaving)
16:51:49*Jesin joined #nim
17:07:16*Ven_ joined #nim
17:11:25*nsf quit (Quit: WeeChat 1.7.1)
17:11:44*def-pri-pub joined #nim
17:17:29*Ven_ quit (Quit: My MacBook has gone to sleep. ZZZzzz…)
17:19:07*xet7 joined #nim
17:29:37*couven92 quit (Ping timeout: 248 seconds)
17:35:08*ShalokShalom quit (Ping timeout: 260 seconds)
17:38:05Araqugh, I am beginning to hate stdlib deps
17:38:17Araqthe compiler uses json, unicode, etc etc
17:38:45Araqthat's a pain for the experiments I want to do... now I have to port all this to my immutable strings branch
17:54:05*Sentreen quit (Ping timeout: 240 seconds)
17:56:07*xet7_ joined #nim
17:56:19*smt quit (Read error: Connection reset by peer)
17:56:27*smt joined #nim
17:56:48*xet7 quit (Read error: Connection reset by peer)
18:04:05*def-pri-pub quit (Quit: leaving)
18:07:09*Sentreen joined #nim
18:13:10*spkpp joined #nim
18:15:18wishidoes anyone know how to make a sequence of Tables? like var records = newSeq[Table]()
18:15:36FromGitter<TiberiumN> yes we know
18:15:56wishigreat
18:16:03FromGitter<TiberiumN> var recors = newSeqTable[string, string ()
18:16:16FromGitter<TiberiumN> and you need to import "tables"
18:16:39FromGitter<TiberiumN> or another approach: ⏎ var records: seq[Table[string, string]] = @[]
18:18:02wishilet me try this. I am trying to put individual json records into something like a dict, to extend nimdataframe
18:19:02FromGitter<TiberiumN> oh
18:19:15FromGitter<TiberiumN> also, if you want string to string table
18:19:24FromGitter<TiberiumN> you might want to use "strtabs"
18:19:48wishioh yes, thanks TiberiumN
18:24:23*Matthias247 joined #nim
18:34:53wishihttps://pastebin.com/pmMr80x5 I am running into some syntax errors. somehow key values pairs in Nim do not seem to be a [key, value] expression
18:37:19Araqadd doesn't take a pair at all, use mytab.add(key, val)
18:37:36Araqor mytab[key] = val
18:37:59Araqand newStringTable(string) also doesn't compile
18:39:11wishihmh that did compile, but not work. I am just getting started
18:50:46FromGitter<ephja> what was the solution for using await in a template?
18:53:06FromGitter<ephja> could you query the AST as if it had already been expanded?
18:54:09*nsf joined #nim
18:57:00*couven92 joined #nim
19:03:45*spkpp quit (Quit: http://www.kiwiirc.com/ - A hand crafted IRC client)
19:08:48wishiI seem to be too dumb to do that. https://pastebin.com/Kh6tMRam - I don't understand this add method. or I may just misunderstand some docs ;)
19:10:11*nhywyll quit (Quit: nhywyll)
19:14:59*Tiberium quit (Remote host closed the connection)
19:15:51*Ven joined #nim
19:16:14*Ven is now known as Guest59775
19:16:28FromGitter<ephja> wishi: there's no 'add' in that module, but maybe you want to use this https://nim-lang.org/docs/strtabs.html#[]=,StringTableRef,string,string
19:17:29wishiI thought I was already using that.
19:18:14wishioh there is no .add wow
19:18:24wishinever trust an IDE
19:20:09FromGitter<ephja> the 'tables' module has 'add'
19:21:52*Vladar quit (Quit: Leaving)
19:26:03*Guest59775 quit (Quit: My MacBook has gone to sleep. ZZZzzz…)
19:26:19*spkpp joined #nim
19:27:01*salewski joined #nim
19:28:53salewskiAraq, I just did a nimble install c2nim. It seems that c2nim adds for all C structs the bycopy pragma.
19:29:21Araqyes, that was a bugfix/improvement
19:29:23salewskiThere is no way to avoid that? And nimble can not install an older c2nim?
19:29:35FromGitter<ephja> wishi: btw, "for k, v in x" should also invoke 'pairs'
19:29:35Araqwhat's wrong with this feature?
19:31:08salewskiMaybe useful for https://forum.nim-lang.org/t/2978#18780
19:31:55Araqsalewski: yes. I can add a switch in order to not emit it, but why does it hurt?
19:32:10salewskiBut for most C sources that was not necessary. And the Nim output of c2nim looks differently now.
19:33:08salewskiAs you know, for the old legacy GTK files I did postprocessing with scripts, and that needs changes now.
19:33:20FromGitter<ephja> wishi: you can return nothing ("void") from main if you want
19:34:05salewskiAt least for the cairo files I have to fix it, for the old GTK 3.20 it does not hurt, no one really cores for that.
19:34:47salewskiFor cairo i still need c2nim, as it it nort well supported by gobject-introspection.
19:35:19FromGitter<ephja> I sometimes return an exit code (int) and do "quit main()"
19:35:26salewskiWell, I will see how difficult it is to change my scripts, or I will see where I can get an older c2nim-
19:35:59salewskiIn each case the bycopy pragma adds a lot of noise!
19:36:13Araqdon't spend too much time on it, I can make bycopy generation optional
19:36:39salewskiYes. I would be grateful. Thanks.
19:36:51Araqyeah, noise ... shrug, I don't read generated source code anyway ;-)
19:37:03FromGitter<ephja> I'd rather have object meta data at compile time like with Eo for EFL. then you just have to parse the metadata and generate code
19:37:18salewskiBye.
19:37:22*salewski quit (Quit: WeeChat 1.4)
19:37:38spkppstarted with Nim and macros. I have this snippet: https://pastebin.com/5MrgbABx. I created a macro that generates a simple 'echo' proc that takes one arg, but when I try and use the macro, I get undeclared identifier. Do I need to explicitly add genSym nodes?
19:37:50spkppSorry for the lengthy question
19:39:06Araqspkpp: use 'body: untyped' in the macro header
19:39:36spkppLovely, thank you!
19:40:40ZevvWhat do I do with a message like: Error: internal error: (filename: semobjconstr.nim, line: 47)
19:40:57Zevvis this caused by me doing something wrong, or is there really an internal error?
19:42:26FromGitter<ephja> a compiler bug
19:43:03FromGitter<ephja> https://github.com/nim-lang/Nim/search?q=semobjconstr&state=open&type=Issues&utf8=%E2%9C%93
19:43:58Zevvok, clear
19:49:45*gokr joined #nim
19:51:26FromGitter<ephja> is the lack of suggestions for partial unqualified names an editor limitation or a nimsuggest limitation?
19:52:42FromGitter<TiberiumN> what do you mean?
19:53:13FromGitter<ephja> foo.bar usually yields suggestions, but 'bar' doesn't
19:53:33FromGitter<TiberiumN> VSCode does it for me
19:53:44FromGitter<TiberiumN> you mean like this?
19:53:45FromGitter<TiberiumN> (https://files.gitter.im/nim-lang/Nim/CQTJ/image.png)
19:55:19wishiephja... ah ok
19:55:23wishilearning by doing ;)
19:55:34wishithanks
19:57:37FromGitter<TiberiumN> @epja here's my VSCode settings: https://paste.ee/p/pVI4I
19:57:40wishibtw. for that tutorial https://nim-lang.org/docs/tut1.html - do I have to be concerned about a stack buffer overflow like in C? when I get the input and it's too long
19:58:03FromGitter<TiberiumN> I use 1ms delay because nimsuggest checks the file only after it's saved to disk
19:58:16FromGitter<TiberiumN> I mean checks it for errors
19:58:40dom96wishi: Rule of thumb is: only worry about such things when using Nim's unsafe features (ptr, addr, cast).
19:59:40FromGitter<ephja> @TiberiumN isn't that a 1-ms delay? ;)
19:59:47FromGitter<TiberiumN> yes it is :)
20:00:29FromGitter<TiberiumN> nimsuggest doesn't check for errors if I don't save the file
20:00:32FromGitter<TiberiumN> you can set it to 1sec
20:00:43FromGitter<TiberiumN> (maybe this is Nim plugin bug, not nimsuggest limitation)
20:01:25FromGitter<TiberiumN> and about my terminal .bat script - it just automatically loads Visual Studio vcvarsall.bat
20:01:27*yglukhov quit (Remote host closed the connection)
20:01:33FromGitter<TiberiumN> because I mainly use VCC
20:02:41*yglukhov joined #nim
20:03:44FromGitter<ephja> I just get a bunch of local symbols
20:05:07FromGitter<TiberiumN> strange
20:05:17FromGitter<TiberiumN> did you check that nimsuggest is in PATH?
20:06:00FromGitter<ephja> it works when I qualify with the module name
20:06:10FromGitter<TiberiumN> ehmm, I don't know
20:06:15FromGitter<TiberiumN> also, maybe you're not using latest Nim?
20:06:21FromGitter<TiberiumN> because I always use devel
20:06:29FromGitter<ephja> me too
20:20:32*Ven joined #nim
20:20:56*Ven is now known as Guest16543
20:21:10FromGitter<ephja> @TiberiumN how old is your nimsuggest build?
20:23:56FromGitter<TiberiumN> I can't check now sadly :(
20:24:00FromGitter<TiberiumN> Only tomorrow
20:24:41FromGitter<TiberiumN> But I update with choosenim, and it rebuilds all tools including nimsuggest
20:25:33FromGitter<ephja> not that old then I assume
20:29:35*jsgrant_ quit (Ping timeout: 258 seconds)
20:29:50Zevv[noob question] What's the idiomatic way to work with objects and passing them to functions? Use 'foo: var Foo' or 'foo: ref Foo'?
20:31:37yglukhovZevv: 'foo: Foo'. less words - more idiomatic ;)
20:31:51ZevvBut then I'm not allowed to modify the object, am I?
20:32:28yglukhovZevv: if your object is ref type (ala C#, Java, D), then you are.
20:32:39yglukhovif it is value type, then you're not
20:34:01Zevvhm ok let me check that out
20:34:33FromGitter<ephja> if you dereference the reference then it will work with 'var' too
20:34:44ZevvThat makes sense
20:35:17FromGitter<ephja> 'var' will be sufficient in most cases where you need mutability, it's just that you have to dereference manually unless you enable experimental features
20:36:09ZevvThe 'ref type' object just made sense to me
20:36:39ZevvI really look forward to receiving my Nim book, the manual is still terse
20:37:07ZevvReading the nim compiler source is quite helpful, but that's all the way on the other side of the complexity spectrum
20:37:24ZevvI would benefit from some simple idiomatic snippets to get the hang of the lingo
20:37:55FromGitter<ephja> I suppose you could infer everything by looking at the compiler code ;)
20:38:05ZevvI bet :)
20:38:23*jsgrant joined #nim
20:38:27Zevvgiven enough time and a large enough head
20:38:34yglukhovyes, from those coming from either scripting languahes or C#/Java/D/... ref type is more familiar
20:38:45yglukhov* for those
20:39:16ZevvI come from C and Lua; in C there's pointers, in Lua everything is a ref. I never really understood the buzz of references in C++ I guess :)
20:39:44ZevvAnyway, my object is now a ref, I dropped all the 'ref' and 'var' stuff and all is clear and simple and nice and sweet
20:40:11yglukhovZevv: then ref type is a pointer in terms of C (but traced by nim's GC), while non-ref type is a struct.
20:40:28yglukhovtuple is a struct as well
20:40:44ZevvYeah, that makes sense
20:41:20Zevvs/ref/*/g
20:41:36Zevvalso in the type definitions
20:41:44yglukhovyeah, kinda.
20:41:58ZevvI was having troubles passing my objects to {.async.} functions, but that's ok now
20:42:38yglukhovyou cant pass by var to closures, because closures can't capture them if you think of it
20:42:59yglukhovand {.async.} functions use closure iterators under the hood
20:43:11Zevvyeah, I figured that
20:43:13FromGitter<ephja> Araq: The compiler is apparently aware of the fact that cint is int32, so couldn't it be aliased to it? that would solve the (int32, int32) -> (cint, cint) issue
20:44:01Zevvyglukhov: ok, now I'm the noob again. 'pass by var', how is that different from 'passing by reference'
20:44:15ZevvYou either get the object, or a reference to the object
20:44:18Zevvwhat's the third option?
20:44:23yglukhovpass by var is somewhat equivalent to
20:44:32yglukhovpass by C++ &
20:44:32FromGitter<ephja> I can't remember where it determined that those types are compatible
20:45:00ZevvCan you explain the difference in Nim in one sentence between the two?
20:46:46yglukhovwhat do you mean?
20:46:49FromGitter<ephja> fixed int types makes a lot more sense
20:47:16ZevvYeah that was definately a crooked sentence. I mean the difference between passing by var or passing by ref
20:47:25ZevvIt sounds like the same thing
20:47:42FromGitter<ephja> for one you don't have to query the underlying compiler, which probably involves some kind of hack
20:48:17yglukhovZevv: if you have a non-ref type, you can't pass it "by ref". it's either by var, or by itself =)
20:48:51FromGitter<ephja> yeah non-refs are not allocated on the GC heap and traced
20:49:44yglukhovif you have a ref type, you can pass it "by ref" (actually you're just passing the value of reference), by var (if you dereference it upon call, normally you don't wanna do that), or by value (if you dereference it upon call, normally you don't wanna do that as well)
20:49:58FromGitter<ephja> pointers also point to some memory location, but "ptr T" instances are not reference counted
20:50:26yglukhovptr T may point to anywhere, including to inside of some other object, or stack
20:50:28FromGitter<ephja> so they will never be implicitly freed
20:50:38yglukhovref T may point only to the root of the heap cell
20:51:13ZevvOk, thanks for clearing that up
20:51:16Zevvthat helps
20:52:01ZevvI was indeed dereferencing my object at call time
20:52:18Zevvwhich resulted in the non-idiomatic mess I got tangled up in
20:52:31yglukhovptr T may hold arbitrary values, it's your responsibility to handle them correctly. just like you would with pointers in c/c++. refs can hold only valid values, otherwise gc will crash on it on the nearest scan
20:52:34FromGitter<ephja> (ref Foo)()[] -> Foo, (ptr Foo)()[] -> Foo
20:52:50FromGitter<ephja> though only the former is actually valid
20:53:25ZevvYeah, normal C pointers have no mysteries to me, I'm not afraid of int ***a;
20:55:17FromGitter<ephja> I was baffled by pointers at first
20:55:37ZevvI started with assembly on the 6502 as a kid
20:55:46Zevvpointers come naturally if you start bottom up
20:55:47FromGitter<ephja> even functions
20:58:20ZevvAnyway, I'm pretty much thrilled by what I've seen of Nim so far. For me this feels like the cross bread of my two favourites, C meets Lua. Strict typing, closures (!), no runtime, cross compilation, garbage collection. All sweet.
20:58:34ZevvThanks for taking the time to educate a noob, nice to find a friendly community
20:59:25FromGitter<ephja> We are friendly to anyone who is not a COBOL apologist
20:59:45ZevvI'm old, but not *that* old
21:01:44spkppI have a nim file with the contents "var test: seq[proc] = @[]". It fails to compile for me. Are there special restrictions to using proc as a type?
21:01:53*Trustable joined #nim
21:02:47Zevvvar test: seq[proc()] = @[] ?
21:03:10spkppDoes that handle generic procs?
21:03:32Zevvhonsetly, I have no clue, I better just keep my mouth shut
21:03:44spkppno not all, that compiled
21:03:46FromGitter<ephja> no, but generics are compile time constructs
21:04:58spkppGotcha, the intent was to call a bunch of procedures with varying type signatures
21:05:14spkppI think proc(anything) restricts to the one type I specify
21:05:19FromGitter<ephja> I assume you don't want to store procs with different signatures, but if you do then there are various approaches that you can take
21:05:20dom96'proc' is a type class
21:05:25dom96You can't have a list of it
21:05:51dom96This is a common thing for people to get confused about, we need a better error for it
21:06:12spkppYeah, I think I've run into it a few times and the compiler mentioned getting a stack trace from koch
21:06:18FromGitter<ephja> spkpp: are the different signatures known in advance?
21:06:19spkppephja that's what I want to do!
21:06:46spkppephja: I'm just messing around but I think ideally no, if possible?
21:07:19FromGitter<ephja> otherwise it'll be kind of difficult to call them. I've never needed this myself, but you can use variants for this https://nim-lang.org/docs/manual.html#types-object-variants
21:08:40FromGitter<ephja> or unions which are not type safe
21:09:00yglukhovspkpp: https://stackoverflow.com/questions/39232364/nim-stored-procedure-reference-in-tuple/39544532#39544532
21:09:21yglukhovthat should answer your question
21:10:33spkppyglukhov: ooh that's perfect, thank you
21:10:57spkppephja: and thanks to you as well!
21:14:12ZevvI had a similar issue trying to pass arbitrary data to be passed back on a callback funcion. I ended up putting this into a closure as well, is there another way for this? Basically, I want to pass a reference to whatever, and get this reference back later.
21:15:20yglukhovspkpp, ephja, Zevv: i've written a variant type allowing to store values of any type within. https://github.com/yglukhov/variant
21:16:04Zevvok, that takes some magic it seems
21:16:06yglukhovbut like i said, in most cases, closures are the simplest and the most convenient solution
21:16:58ZevvIt seems. I tried passing a ptr, but then I'd have to make sure I keep the GC from deleting my stuff before the callback happens
21:17:05Zevvclosures are just fine for this
21:18:34*ShalokShalom joined #nim
21:19:10yglukhovtrue. nim keywords "ptr", "addr", "cast", "unsafeCast" are the last resort tools. normally you would need them for something really low-level, or some magic, or some heavy optimization tricks
21:19:26FromGitter<ephja> yglukhov: when do you use that rather than an algebraic type?
21:20:15yglukhovephja: whan do i use what exactly?
21:21:23FromGitter<ephja> yglukhov: variants that don't accept only certain types
21:21:33FromGitter<ephja> looks neat though
21:24:15yglukhovephja: well, consider a game engine and scene editor. scene editor has an inspector view that allows to edit component fields. the edit views are different for different types of component fields.
21:24:26*xet7__ joined #nim
21:24:43yglukhovif its vector3, you have 3 text fields, if its a texture, you have some image picker widget, and so on
21:25:27yglukhovin order to build the inspector, i enumerate editable fields of the component in runtime
21:25:41yglukhovsetters and getters are packed to variants
21:26:08yglukhovthen a proper editor is looked up based on variant type
21:26:34yglukhovand then it unpacks setters and getters to edit its specific property
21:26:58yglukhovto illustrate that: http://yglukhov.github.io/rod/livedemo/main.html
21:27:19*gokr quit (Ping timeout: 276 seconds)
21:27:23yglukhovif you select a node in the left view, the inspector will apear in the right view
21:27:57yglukhovthats just one use case, i have others, but i'll let you figure yourself ;)
21:28:08*xet7_ quit (Ping timeout: 260 seconds)
21:29:04FromGitter<ephja> is it not possible with tagged unions?
21:29:08*andrzejku quit (Quit: Textual IRC Client: www.textualapp.com)
21:30:00yglukhovephja: if you have a fixed set of types - yes. but a game engine allows to write own components with own field types, and own editors for these types.
21:31:24yglukhovi mean, as a library, it allows other users to extend it. so taggen union will have to be altered. but you can't alter library code.
21:32:28FromGitter<ephja> isn't there a fixed number of property types?
21:32:39yglukhovno, it may be extended
21:33:11yglukhovthat surely depends on you design. with my design, i allow users to create new field types
21:36:55*fredrik92 joined #nim
21:37:09FromGitter<ephja> at compile time?
21:38:27yglukhovvariants are a lot like tagged unions, tagged by type. and they provide minimum overhead (but may allocate when value doesn't fit), so they are perfectly fine to use in any logic, except some dense code that cares about maximum performance. don't use them in 60fps drawing logic, and in btach processing logic, and you should be fine
21:38:57yglukhovephja: yes, the type ids are generated at compile time, and are just 32bit ints.
21:39:17yglukhovjust like a tag in tagged union
21:39:34yglukhovit doesn't pollute your binary with extra string or whatever
21:39:52yglukhovit boils down to just ints at the end of the day
21:40:38*Trustable quit (Remote host closed the connection)
21:41:02yglukhovyou can try it and see the generated c code =)
21:41:31FromGitter<ephja> so no DLL extensions?
21:42:25yglukhovas long as dlls share the same type definition, the type ids will be equal in both dlls.
21:43:22yglukhovthe type id is computed by first mangling a type, and then getting the hash of the mangled name. so the type ids are pretty stable. could even be used for serialization, but carefully =)
21:45:05FromGitter<ephja> you could have like a vendor prefix, but maybe it isn't necessary
21:46:03yglukhovnoone complained yet, including myself ;)
21:50:50*fredrik92 quit (Ping timeout: 240 seconds)
21:52:10*ShalokShalom quit (Ping timeout: 240 seconds)
21:53:26*fredrik92 joined #nim
21:53:41*fredrik92 quit (Client Quit)
21:53:54*xet7_ joined #nim
21:55:27*xet7__ quit (Ping timeout: 240 seconds)
21:59:47FromGitter<ephja> I wonder if a callback approach would ever be faster. maybe when there are a lot of variations (more type ID comparisons)
22:03:03FromGitter<ephja> does the JS backend update more often than necessary?
22:03:58*Guest16543 quit (Quit: My MacBook has gone to sleep. ZZZzzz…)
22:05:40FromGitter<ephja> allocations might be the biggest issue. first time profiling JS code
22:05:44*spkpp quit (Quit: http://www.kiwiirc.com/ - A hand crafted IRC client)
22:06:53*smt quit (Read error: Connection reset by peer)
22:07:07*smt joined #nim
22:10:52yglukhovephja: the editor currently runs at 60fps. that's an issue to be fixed.
22:11:57yglukhovregarding variants, like i said earlier, if you can get away with tagged unions or callbacks, that would most likely be a better idea, because that's just simpler to reason about.
22:13:08yglukhovbtw, js version of the editor is not the best. native one has more functions, such as open/save, for example =)
22:16:44*jsgrant quit (Read error: Connection reset by peer)
22:38:39*sz0 joined #nim
22:42:23*Jesin quit (Quit: Leaving)
22:43:03*Ven joined #nim
22:43:26*Ven is now known as Guest72659
22:45:46*Jesin joined #nim
22:57:25Zevvs
22:57:37FromGitter<zacharycarter> ?
23:03:18*yglukhov quit (Remote host closed the connection)
23:03:53*xet7_ quit (Quit: Leaving)
23:04:15*xet7 joined #nim
23:36:54*Snircle quit (Quit: Textual IRC Client: www.textualapp.com)
23:49:42*Guest72659 quit (Quit: My MacBook has gone to sleep. ZZZzzz…)