<< 24-12-2018 >>

00:05:59*vlad1777d quit (Ping timeout: 244 seconds)
00:12:55FromGitter<Clyybber> Araq: Regarding your comment on static T ; could we make int Literals be convertible to static int?
00:13:24Araqthey are but it's lipstick on a pig
00:29:14*Cthalupa quit (Ping timeout: 244 seconds)
00:30:11FromGitter<Clyybber> Araq: What are the fundamental problems of static in your opinion?
00:30:36*Cthalupa joined #nim
00:35:39Araq1. is it a type or a value?
00:35:59Araqin generics it says "value allowed/required here".
00:36:21Araqin proc parameters it says "compile-time value required here"
00:36:47Araqbut these are two different things.
00:37:31Araq2. it doesn't compose well in the type system
00:37:41Araqa) what is a 'static' return type?
00:37:56Araqb) what is a tuple[a: static int; b: int] ?
00:38:28Araq3. the type relation between T and static T is unspecified. subtype relation?
00:38:40Araqbut then why does static T match better than T?
00:39:17Araq4. what does that enable that the older 'range' type didn't?
00:40:10Araq5. what is the type of [1, 2] ?
00:40:18Araq - array[2, int]
00:40:27Araq- array[static 2, int]
00:40:39Araq- array[static 2, static int] ?
00:40:48Araq- static array[static 2, static int] ?
00:43:25AraqBy the spec the type is 'array[2, int]' btw, no 'static' in sight because it's a broken concept.
00:44:09Araqit's a type qualifier like 'volatile' or 'const' in C++, broken beyond repair, an endless source of complexity.
00:45:54AraqC/C++: The type system reflects the requirement for memory-mapped IO interfaces (volatile). Total bullshit, have peek/poke builtins for that ffs.
00:53:47FromGitter<Clyybber> 'array[2, int]'
00:54:06FromGitter<Clyybber> Sry, mistyped
00:54:27Araqit's actually array[range[0..1], int] but I was too lazy to type it out
00:54:52Araqand there might also be a confusion between 2 and range[0..1]
00:55:04FromGitter<Clyybber> So does the compiler implicitly convert the 2 Int literal to a range?
00:55:09Araqbut that would add more confusion on top of static.
00:55:38Araqnow apparently you can also calculate with these types/values
00:56:14Araqproc `&`(a: array[N, T]; b: array[M, T]): array[N+M, T]
00:56:50Araqbut that means that we actually have a '+' on *typedescs*
00:57:40Araqturning range[N] + range[M] into range[N+M], lifting the + from values into the type domain
00:58:24Araqthat's awesome, but doesn't require 'static' either
00:59:00FromGitter<Clyybber> Does static allow stuff like static string?
00:59:55Araqyes but it's not clear what kind of calculations are supported with it
01:00:32Araqand proc foo(s: static string) does not count, that's not an arbitrary type computation
01:00:56Araqthat's merely an additional constraint on the 's' parameter
01:03:08Araqproc foo[N: static int]() = echo N # again, the eternal type vs value confusion. does 'echo' work with 'typedesc'? Not really. so why would it be supported?
01:03:34Araqproc foo[N: static int]() = echo valueof(N) # clarity.
01:04:09Araqhaving said all that, I can now write a spec for it and clean it up
01:04:29Araqand with a spec we can fix the compiler bugs...
01:04:30FromGitter<Clyybber> Gitter formatting fucked up your code
01:04:53Araqread our irclogs then
01:05:21FromGitter<Clyybber> Yeah will do, or I might as well join by IRC, gitter annoys me a bit :P
01:08:56FromGitter<Clyybber> Would it make sense to treat identifiers to static int/string like a literal?
01:14:21FromGitter<Clyybber> So we can say static int is not convertable to int, but is convertible to intLit.
01:20:00FromGitter<Clyybber> Nevermind, that would mean static int is convertable to int
01:20:39FromGitter<Clyybber> Which would be fine I guess.
01:23:40FromGitter<Clyybber> But that would mean it would be equivalent to const int...
01:23:57FromGitter<Clyybber> which it isn't.
01:26:06FromGitter<Clyybber> The only difference between a const int and a static int is that a const still exists as a variable at runtime, while a static doesn't.
01:26:33FromGitter<Clyybber> Is that right?
01:27:31Araq'const int' is not a type
01:27:46Araqbut I get what you mean, yes
01:41:04FromGitter<Clyybber> Hmm, yeah static T is pretty complex
01:42:14FromGitter<Clyybber> I guess the best way to go about them is to treat them the same as literals.
01:43:21FromGitter<Clyybber> Good nite
02:12:40*Tyresc quit (Quit: WeeChat 2.4-dev)
02:36:33*Snircle joined #nim
02:41:22*PrimHelios joined #nim
02:42:13PrimHeliosanyone know why this code segfaults? https://hastebin.com/ekinelihar.cs
02:48:55*kapil____ joined #nim
02:54:14*Snircle quit (Quit: Textual IRC Client: www.textualapp.com)
02:55:18FromGitter<gogolxdong> Is there an easy way to split a seq to subseqs sizes 4?
02:56:08FromGitter<zacharycarter> https://nim-lang.org/docs/sequtils.html#distribute%2Cseq%5BT%5D%2CPositive
02:56:53FromGitter<gogolxdong> not into 4 seqs, into seqs of size 4.
02:57:20FromGitter<gogolxdong> tried distribute.
02:57:24FromGitter<zacharycarter> ah - sorry
03:00:05*banc quit (Quit: Bye)
03:00:14*wildlander quit (Quit: have a nice xmas o/)
03:12:30FromGitter<gogolxdong> ```code paste, see link``` [https://gitter.im/nim-lang/Nim?at=5c204e9e5064a51f83691dff]
03:12:49FromGitter<gogolxdong> I can only make this.
03:16:18*banc joined #nim
03:22:27PrimHelioswas that segfault because newDiscord was returning "ref Discord" which is already a ref object?
03:24:28FromGitter<zacharycarter> PrimHelios - I can't say that's the reason for the segfault
03:24:47FromGitter<zacharycarter> but you're correct that newDiscord should be returning Discord not ref Discord
03:25:04FromGitter<zacharycarter> ref Discord would insinuate that you're returning a gc-traced ref to an already gc-traced ref
03:25:14FromGitter<zacharycarter> I assume that is why though
03:25:37FromGitter<zacharycarter> try removing it and replacing it and see if the segfault comes and goes
03:25:56PrimHeliosi did. just changed the "ref" keyword and it compiles and runs just fine now
03:26:18FromGitter<zacharycarter> cool - good catch I didn't see that initially when you asked
03:28:19PrimHeliosso, does that mean declaring an object as "ref object" means that every instance is a traced reference?
03:28:41FromGitter<zacharycarter> yes
03:29:13PrimHeliosah, cool. i've never had this much control over stuff before :P
03:29:18FromGitter<zacharycarter> you can also use unsafe ptr if you want
03:29:36FromGitter<zacharycarter> which would be a unsafe reference not traced by the GC
03:30:16PrimHeliosgosh, a lot more control than python. i kinda love it to be honest
03:30:20FromGitter<zacharycarter> but if you do new refObject you're creating a reference to some object which was allocated on the heap of the current thread
03:31:04FromGitter<zacharycarter> Nim is definitely lower-level than Python
03:31:24FromGitter<zacharycarter> and if you're looking for a more performant python, Nim is a nice option to explore
03:32:09PrimHeliosyeah, that's actually why i've been really interested in it. i like the type system and speed, but it still looks pretty elegant
03:33:02*abm quit (Quit: Leaving)
03:33:49FromGitter<zacharycarter> I'm not using it atm - but I plan on doing so again in the future, but I've used it quite extensively for a couple of years now
03:34:03FromGitter<zacharycarter> for web and game programming
03:34:25FromGitter<zacharycarter> once I have my engine in a more stable state - I'll work on an editor in Nim
03:35:19FromGitter<zacharycarter> it does have some very attractive features
03:48:31shashlick@zacharycarter: what kind of editpr
03:49:09FromGitter<zacharycarter> 3d game editor
03:49:33FromGitter<zacharycarter> which uses the engine I'm working on
04:00:28FromGitter<zacharycarter> shashlick: this one - https://github.com/zacharycarter/zeal
04:13:07shashlickNice
04:16:44FromGitter<zacharycarter> thanks
04:16:57FromGitter<zacharycarter> most of it I didn't write :P but I have gotten it working on macos
04:17:16FromGitter<zacharycarter> and I wrote some macos specific stuff - like a filewatcher using the FSEvents API
04:32:08*vlad1777d joined #nim
04:52:34*endragor joined #nim
05:09:02*endragor quit (Remote host closed the connection)
05:16:11FromGitter<kaushalmodi> @Araq Some progress with nightlies Travis: https://travis-ci.org/nim-lang/nightlies/builds/471757921
05:37:50FromGitter<kaushalmodi> The nightlies releases are now publishing as before: https://github.com/nim-lang/nightlies/releases
05:38:28FromGitter<kaushalmodi> We now need a Windows expert to fix the .travis.yml so that it doesn't fail Windows build due to missing pcre64.dll: https://github.com/nim-lang/nightlies/issues/10
05:40:22*vlad1777d quit (Ping timeout: 268 seconds)
05:41:46kinkinkijkinwhat is the best way to see if a seq contains an item matching a given item ? it's probably in sequtils right
05:44:56leorizekinkinkijkin: `if item in seq`
05:45:16kinkinkijkinoh that's a lot easier than i was going to da
05:45:20kinkinkijkindo *
05:48:34kinkinkijkinwait, I have a situation where the seq I want to compare against is a seq of zipped names and their corresponding command, would that work if I just did seq.name ?
05:49:10shashlick@kaushalmodi: you got windows running on travis?
05:49:53leorizekinkinkijkin: no, it can only look for the entire item
05:50:07leorizeI'd suggest using `tables` module instead if you need such use case
05:59:01*dddddd quit (Remote host closed the connection)
06:00:01FromGitter<xmonader> @shashlick it's working. you can use my clone :) i don't know how to turn off the hints from the compiler
06:01:10shashlickya looks like he figured it out too - https://github.com/nim-lang/nightlies/blob/master/.travis.yml#L21
06:01:41shashlick--hints:on|off|list
06:01:54FromGitter<xmonader> oh! thanks!
06:03:10FromGitter<xmonader> ```code paste, see link``` ⏎ ⏎ much better [https://gitter.im/nim-lang/Nim?at=5c20769ecac5bc2241dc1e5c]
06:04:53shashlickyou could set --verbosity:0 eventually
06:07:44FromGitter<xmonader> @shashlick all good now thanks :)
06:11:24*vlad1777d joined #nim
06:26:56*endragor joined #nim
06:31:18*endragor quit (Ping timeout: 245 seconds)
06:45:04*plushie quit (Quit: plushie)
06:57:06*anamok joined #nim
06:57:08anamokhi
07:00:46anamokWhen using strscans, what is the equivalent of the regexp ".*" (any characters)? For example take this sentence: "The language was officially renamed from Nimrod to Nim with the release of version 0.10.2". I want to concentrate on the part "from Nimrod to Nim", and I want to extract Nimrod and Nim to two variables.
07:03:33shashlickyou could try $+$. but not sure if it will work though
07:06:19*Vladar joined #nim
07:06:53anamokHere is my current code: http://ix.io/1wGH/nim
07:10:37leorizeanamok: try this string: "$*from $w to $w$*."
07:10:54leorizeyou'd need a `tmp` variable to discard the `$*` match
07:13:32anamokThanks, it works. Could you explain what it means? I don't see why they are different, once it's $* , then it's $*.
07:17:40leorize$* requires a token after it for a match
07:22:39anamokAnd what is $*. ? What does the . mean for strscans?
07:23:40*endragor joined #nim
07:24:53leorizeanamok: a literal `.`
07:27:21anamokIf I remove the "0.10.2", then how to say "go until then end and match everything"?
07:27:58leorizefrom what I can see, you'd need a custom matcher
07:28:06leorizehttp://nim-lang.github.io/Nim/strscans.html#user-definable-matchers
07:28:17*endragor quit (Ping timeout: 268 seconds)
07:28:35kinkinkijkinoh my god, ubuntu 18.04 currently distributes nim 0.17.2, was wondering why i was getting errors for using removePrefix and removeSuffix
07:28:42kinkinkijkinabsolutely no reason for this
07:30:27anamokuse choosenim to install Nim
07:31:28kinkinkijkinim building manually right now
07:31:41*nsf joined #nim
07:31:58shashlickI'm thinking of making a Nim snap
07:34:05anamokshaslick: $+$. doesn't work
07:44:33PrimHelioskinkinkijkin: i've noticed quite a few ubuntu packages are ridiculously out of date, unfortunately :\
07:45:05leorizeanamok: proc tilEoL(input: string; start: int): int = input.high - start
07:45:16leorize^ that's a custom matcher that'll skip the rest of the input
07:45:36leorizeuse it like this "$[tilEoL]"
07:46:55anamokleorize: thanks, it works like a charm
08:23:07*kapil____ quit (Quit: Connection closed for inactivity)
08:40:11*PrimHelios quit (Ping timeout: 250 seconds)
08:49:52*Pisuke joined #nim
08:52:09*MyMind quit (Ping timeout: 268 seconds)
08:52:18FromDiscord_<exelotl> Is it possible to make nimsuggest work with files that are to be 'include'd elsewhere in the project?
09:02:43leorizeas long as the Nim compiler can compile your project without any flags, nimsuggest can work with it
09:14:41*kapil____ joined #nim
09:17:15FromDiscord_<exelotl> So do I need to make a config file to tell it which files are supposed to be compiled?
09:20:36leorizenimsuggest should be able to detect your project automatically
09:24:59FromDiscord_<exelotl> Well, my types and procedures are defined in different files, and at the end they're all included into one file, kinda like how sdl2_nim does it
09:26:01leorizethen it should work normally
09:26:15FromDiscord_<exelotl> When I save a file with procedures, I get errors about missing types
09:26:34FromDiscord_<exelotl> If I save the root file the errors go away
09:27:04FromDiscord_<exelotl> But if I go back and save the procedures file the errors come back
09:27:29leorizeI think it might be `nim check` complaining and not `nimsuggest`
09:29:12FromDiscord_<exelotl> Hm maybe, I'm just using the nim vscode extension
09:29:55leorizeyou can try `cd`-ing to the directory and run `nim check` on that file manually
09:30:27FromDiscord_<exelotl> Ok I'll try that when I get the chance, thx
10:01:19*xet7 joined #nim
10:15:31*stefanos82 joined #nim
10:29:57FromGitter<dom96> @mratsim Pro tip: create a Show HN next time
10:30:15FromGitter<mratsim> well last time it didn’t work ;)
10:41:06anamokSay I have this text: "this is (a test text) from somewhere". How to catch the substring within parentheses with strscans? I want to store "a test text" in a variable.
10:45:00Araq"$*($*)$*$." maybe
10:45:24Araqrequires 3 variables and you only use the 2nd
10:45:34*xet7 quit (Quit: Leaving)
10:47:09Araqor you use a custom matcher
10:47:21anamokThanks, it's solved.
10:47:26*xet7 joined #nim
10:48:39Araqsadly it doesn't support $[*(] :-)
10:54:06anamokAraq: $*$. doesn't work. It should mean "take everything until the end and store in a variable", but it doesn't match.
10:54:25Araqyeah probably not
10:54:39Araqthe $* only supports real tokens not meta tokens
10:54:55Araqon the other hand, since you can skip the rest
10:55:08Araq"$*($*)" suffices
11:02:52anamokA workaround could be to add a special character to the end, e.g. '|', and then catch everything until the end with $*| .
11:03:35anamokif we need the end too
11:34:21*xet7 quit (Quit: Leaving)
11:37:46*xet7 joined #nim
11:38:03*Trustable joined #nim
12:13:33*kapil____ quit (Quit: Connection closed for inactivity)
12:23:11*kapil____ joined #nim
12:32:26anamokI have a seq of tuples. In a loop I want to modify a field of each tuple. However, the compiler says the tuples are immutable.
12:33:37anamokHow could I modify the elements of this seq?
12:34:22leorizehow are you modifying them?
12:36:24anamok`for g in groups: g.done = false`
12:38:01leorizeuse the mitems iterator instead
12:38:10leorizethe default items iterator is immutable
12:40:03anamokThanks. Wow, nim is full of surprises :)
12:41:59*filcuc joined #nim
13:01:28*filcuc quit (Ping timeout: 246 seconds)
13:20:03FromGitter<kaushalmodi> shashlick: The windows bit in the nightlies Travis was added by Araq
13:21:08FromGitter<kaushalmodi> I just fixed an interesting issue last night.. looks like the env vars depending on the env vars in matrix need to be in the matrix too
13:22:00FromGitter<kaushalmodi> The global/env vars are evaluated first, and then the env vars in the matrix
13:33:17*Snircle joined #nim
13:33:59*dom96_w joined #nim
13:34:00*dom96_w quit (Client Quit)
13:36:04*dom96_w joined #nim
13:36:40*dom96_w quit (Client Quit)
14:03:38*Trustable quit (Remote host closed the connection)
14:12:19FromDiscord_<hotdog> How can I convert `static[string]` to string literal?
14:12:42FromGitter<mratsim> you can use them as string literal nothing special to do
14:14:51FromDiscord_<hotdog> @mratsim thanks, I thought so. The compiler complains that it's `void` though. Must be something else going wrong
14:15:17*endragor joined #nim
14:15:19FromGitter<mratsim> you probably are passing it through a void proc
14:15:28FromGitter<mratsim> what’s the full line?
14:17:25FromGitter<arnetheduck> the implicit `result` variable is really weird - the other expression blocks in the language don't have it (`block`, `if`, `try`..), why do functions do? I know the argument "but if I want to accumulate my result..", but for that edge case, can just create a local `var` - as is, all it does is create confusion, both for language users ("which should I use?") and implementation (special casing for detecting if result
14:17:25FromGitter... is set / was touched at least once, etc).. it sure is a good candidate for simplification..
14:18:21FromDiscord_<hotdog> @mratsim https://hastebin.com/zodamilori.md
14:18:43FromGitter<Clyybber> `block`, `if` and `try` have no return either
14:19:17FromDiscord_<hotdog> expression: getOrDefault(procTable, )
14:19:17FromDiscord_<hotdog> expression '' is of type: void
14:19:31*endragor quit (Ping timeout: 246 seconds)
14:19:59FromGitter<Clyybber> @arnetheduck It's just a small convenience feature that makes some optimizations easier to do
14:20:26FromGitter<Clyybber> I don't find it confusing
14:25:16FromGitter<Clyybber> I'm all for simplification, but I don't find the implicit result variable to be a complex element of nim
14:25:44FromGitter<mratsim> @hotdog, mmh, for starter you should use untyped for ident not static string, like so: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/nim-lang/Nim?at=5c20ec688d31aa78b1ef3657]
14:25:58FromGitter<mratsim> there is still an issue though.
14:26:38FromGitter<mratsim> This is how I build a function table: https://github.com/status-im/nimbus/blob/master/nimbus/vm/interpreter_dispatch.nim#L23-L49
14:27:47FromGitter<mratsim> or alternatively: https://github.com/mratsim/Arraymancer/blob/master/src/nn_dsl/dsl_types.nim#L59
14:28:32*Cthalupa quit (Ping timeout: 250 seconds)
14:29:03FromDiscord_<hotdog> @mratsim thanks. I'll have a look at your examples
14:29:17*Cthalupa joined #nim
14:29:18FromGitter<mratsim> my exampels are compile-time though
14:30:17FromGitter<mratsim> I’m trying to fix it
14:31:38*a_chou joined #nim
14:32:04FromGitter<arnetheduck> @Clyybber can you elaborate on those optimizations? ⏎ the compiler is more complex for sure, because of it (aka more bugs!). for users, there are 3 subtly different ways (style, opportunity for bugs like forgetting to set, performance) of doing the exact same thing: returning the value of an expression (specially when you view functions as "named expression blocks")
14:33:24*a_chou quit (Client Quit)
14:33:33*kapil____ quit (Quit: Connection closed for inactivity)
14:33:38FromGitter<mratsim> @hotdog, here you go: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/nim-lang/Nim?at=5c20ee42db5b5c6883fe06ce]
14:34:24FromGitter<mratsim> This works as well ⏎ ⏎ ```code paste, see link``` [https://gitter.im/nim-lang/Nim?at=5c20ee70cac5bc2241def894]
14:34:38FromGitter<mratsim> I suppose it’s the missing “a” parameter that threw a confusing error
14:34:57*a_chou joined #nim
14:35:03FromGitter<mratsim> you can open a github issue regarding this error message (it’s not even related to the .() template)
14:35:33FromGitter<mratsim> closure with missing arguments just display, got <>.
14:36:03FromDiscord_<hotdog> @mratsim thanks! That works 😃 Yeah I tried variations of calling it and must have taken out the amount bit at the end
14:36:18FromDiscord_<hotdog> There was a series of confusing errors
14:36:35FromGitter<Clyybber> @arnetheduck Regarding optimizations you better ask Araq about that, but IIRC it makes writetracking easier/or more efficient, and I imagine inlining easier
14:36:54FromDiscord_<hotdog> I'll open an issue for it
14:37:00FromGitter<Clyybber> @arnetheduck What do you mean 3 different ways?
14:37:00FromDiscord_<hotdog> Thanks for your help!
14:37:12FromGitter<Clyybber> Its just 1. dont use result use return
14:37:17FromGitter<Clyybber> 1) use result
14:37:28FromGitter<Clyybber> 1) use both (kinda weird)
14:37:51FromGitter<Clyybber> I could swear I wrote 1., 2. and 3. gitter is weird
14:37:53FromGitter<mratsim> the last expression is also implicitly returned
14:37:58FromGitter<Clyybber> Yeah
14:39:41Araqarnetheduck: not again. what is weird is 'return', mixing setting the result with a control flow operation
14:39:45FromGitter<Clyybber> @arnetheduck Ok, I think I understand, but implicit return is just syntactic sugar that doesn't create any bugs AFAIK, because nim doesn't implicitly discard
14:39:49FromGitter<arnetheduck> ```code paste, see link``` ⏎ ⏎ the first style for example gives you a useful warning in case you leave a dangling expression (`must discard`) [https://gitter.im/nim-lang/Nim?at=5c20efb52863d8612b81982e]
14:39:58Araqand it's not my fault you never used Eiffel or Delphi before.
14:40:07*a_chou quit (Quit: a_chou)
14:41:33FromGitter<arnetheduck> I'm not comparing with other languages, I'm comparing the various features of nim itself and trying to find a red line to explain it
14:43:56FromGitter<Clyybber> @arnetheduck blocks are not eqivalent to procs, but I see where you are coming from.
14:44:30FromGitter<Clyybber> I personally dont like to put a block after a `=`
14:45:35FromGitter<mratsim> it’s just statement vs expressions
14:46:40*abm joined #nim
14:46:52FromGitter<Clyybber> Araq: Am I right in the assumption that: ⏎ ⏎ ```doSomethingUnrelated() ⏎ let a = 42``` ⏎ ⏎ ? [https://gitter.im/nim-lang/Nim?at=5c20f15cd945b96882eb7fd7]
14:47:45FromGitter<arnetheduck> @Clyybber only because `42` is side-effect free - otherwise you'd have to consider order-of-evaluation
14:48:10FromGitter<Clyybber> When would there be a difference regardless?
14:48:43FromGitter<arnetheduck> ```let a = ⏎ doSomething() ⏎ doSomethingElseThatRetuns()``` [https://gitter.im/nim-lang/Nim?at=5c20f1cbab910e7d3ac74d63]
14:49:31FromGitter<Clyybber> Would still be equivalent to ⏎ ⏎ ```doSomething() ⏎ let a = doSomethingElseThatRetuns()``` ⏎ ⏎ ? [https://gitter.im/nim-lang/Nim?at=5c20f1fb92cf4d2242ea5853]
14:49:35*tribly quit (Quit: WeeChat 2.3)
14:49:52*tribly joined #nim
14:50:34FromGitter<mratsim> this won’t return anything because the last one is a statement
14:50:56FromGitter<arnetheduck> yes / no.. the assignment code itself can have subtle side effects now that destructors are a thing.. even without destructors, if you have finalizers, the assignment might hit you
14:51:21FromGitter<arnetheduck> ie `=` does stuff beyond what's visible
14:51:50FromGitter<Clyybber> Wouldn't `=` be called when the block finishes?
14:52:24*stefanos82 quit (Remote host closed the connection)
14:53:11FromGitter<arnetheduck> hm, yeah, good point - not sue
14:54:21FromGitter<Clyybber> Everything else would be illogical
14:55:05FromGitter<arnetheduck> right, makes sense (confused it with another thing - when exactly `a` is created, but you're right
14:56:21*demond joined #nim
14:56:37*demond left #nim ("BBL")
14:58:14FromGitter<Clyybber> IMO that usage of the block syntax is much more confusing than a implicit result variable
15:00:38FromGitter<mratsim> block is useful for scoping, especially when we deal with huge procs like in the current Ethereum specs :/
15:00:55FromGitter<zacharycarter> I think I'll only need slight modifications to get zserge's webview working to support native child windows
15:01:01FromGitter<zacharycarter> which means I should be able to use it to host my game engine
15:01:19FromGitter<zacharycarter> and thus, use it in my editor
15:01:47FromGitter<zacharycarter> apologies - thought I was in OT
15:02:34FromGitter<Clyybber> @mratsim Yeah, sure. I did not mean the block syntax in general... I meant using a `block: ...` as an expression
15:02:53FromGitter<Clyybber> @zacharycarter Where did your messages go? :P
15:04:05FromGitter<mratsim> I like it as well, I use it where I would use a lambda in a functional language
15:04:19FromGitter<Clyybber> @mratsim Because a block to me is imperative, while a block that returns is equivalent to a anonymus function that we call immediately
15:04:42FromGitter<Clyybber> @mratsim Yeah, its basically equivalent to a lambda.
15:05:25FromGitter<Clyybber> But then @arnetheduck's concerns apply to it too
15:06:00FromGitter<Clyybber> As in why there is no return and implicit result in block
15:06:31FromGitter<mratsim> because it’s not a function?
15:06:34FromGitter<Clyybber> But I guess its best to think about a block as just some lines of code.
15:09:51FromGitter<arnetheduck> I'm using block here as example, but common is: ⏎ ⏎ ```let a = ⏎ if b: 42 ⏎ else: 53``` ⏎ ⏎ which is a special case of `case` (which is a special case of pattern matching) [https://gitter.im/nim-lang/Nim?at=5c20f6bfdb5b5c6883fe343b]
15:12:21FromGitter<Clyybber> Thats just syntactic sugar for ⏎ ⏎ ```if b: ⏎ let a = 42 ⏎ else: ⏎ let a = 53``` ⏎ ⏎ ? [https://gitter.im/nim-lang/Nim?at=5c20f7550b7fc97caa921c21]
15:12:41FromGitter<Clyybber> Or am I missing something?
15:13:40FromGitter<arnetheduck> more like ⏎ ⏎ ```var a ⏎ if b: a = 42 ⏎ else: a = 53``` ⏎ ⏎ `a` in that case is the implicit result variable :) [https://gitter.im/nim-lang/Nim?at=5c20f7a4ab910e7d3ac7739e]
15:15:41FromGitter<arnetheduck> but there are some useful guarantees and properties for the `let` style: it's guaranteed to be initialized and you can skip zero-init
15:16:11FromGitter<Clyybber> So one can think of the result variable in a proc as an alias to the variable the proc is assigned to.
15:16:28FromGitter<mratsim> let wouldn’t work @Clyybber if creates a new scope
15:16:41FromGitter<Clyybber> Yeah I just noticed that :D
15:19:27FromGitter<arnetheduck> you can, and the moment you use it once in your proc, the compiler does magic rewrites to your code and takes special result-handling code paths - and you lose the semantic advantages of `let`
15:21:52FromGitter<Clyybber> A proc shouldn't rely on the fact that its result parameter could be mapped to a let variable
15:23:37FromGitter<arnetheduck> no, what I meant was that once you touch result, the semantics of how `proc` is handled change and you lose some ability to have the compiler help you detect that you did in fact "assign" a value to that alias
15:24:51FromGitter<arnetheduck> ```func f(): int = ⏎ result = 42 ⏎ 53``` ⏎ ⏎ is a motivating example [https://gitter.im/nim-lang/Nim?at=5c20fa433c4093612c567202]
15:25:02FromGitter<arnetheduck> (doesn't compile)
15:25:44FromGitter<Clyybber> Doesn't the compiler translate stuff like ⏎ ⏎ `````` [https://gitter.im/nim-lang/Nim?at=5c20fa78d945b96882ebbb81]
15:26:48FromGitter<Clyybber> ```code paste, see link``` ⏎ ⏎ ? [https://gitter.im/nim-lang/Nim?at=5c20fab8ab910e7d3ac788d6]
15:28:00FromGitter<Clyybber> So essentially the problem you have with `result`, is that it is always mutable, but can be mapped to an immutable variable?
15:28:52FromGitter<arnetheduck> which compiler? :) the ast in nim is basically `(assignment (a) (ifexpr (...))`.. then at the end of the day, in the machine code, yeah, immutability is no longer a concept that way
15:29:48FromGitter<arnetheduck> or no. actually it's `(vardef (a) (ifexpr))` where `ifexpr` is the init portion of vardef
15:30:31FromGitter<arnetheduck> bah. can never remember the details, so many different node types in the AST :/
15:30:34FromGitter<Clyybber> So does it ingore the immutability of `a` or does it create a temporary variable?
15:31:49FromGitter<arnetheduck> in the ast, you can spot the immutability, or the fact that a is initialized to the "return value" of the `if` - don't remember what the cgen does after that
15:32:11FromGitter<arnetheduck> there's no ast rewrite involved
15:32:42FromGitter<arnetheduck> the cgen I remember is complicated, with differences between c and c++
15:34:14FromGitter<Clyybber> I guess it will just violate the immutability
15:35:03FromGitter<Clyybber> But that shouldn't matter if it does it correctly
15:35:38FromGitter<Clyybber> @arnetheduck So is your problem that it is additional complexity in cgen or in the ast?
15:36:13*dddddd joined #nim
15:36:41FromGitter<Clyybber> Because one could do the translation of the AST above, and rely on the c backend or the c compiler to optimize that additional variable away
15:37:07FromGitter<Clyybber> Thats the simplification I would be inclined to do
15:39:08FromGitter<Clyybber> And remove ifexpr altogether
15:39:34FromGitter<Clyybber> In the AST that gets passed to the cgen
15:40:18FromGitter<Clyybber> And remove `ifexpr` in the AST that gets passed to the cgen
15:43:50FromGitter<arnetheduck> well, that seems more complex though - first throw away the immutability and then use it again? I'd rather have it the other way around where the ast is simplified the other way so that everything is an expression (much easier to reason about it then) - similar to ssa form
15:45:47*fthe joined #nim
15:46:35FromGitter<Clyybber> Well, immutability is not a concept that can be united with a result variable
15:46:37FromGitter<arnetheduck> but regardless of that - I'm mostly approaching the issue as a language user trying to decide which one to use - and it's a piece of the language puzzle that doesn't quite seem to fit the rest, in terms of coherent design
15:47:46FromGitter<arnetheduck> so in the thought process, education and special-casing is needed to explain it, which is a cost
15:48:04FromGitter<Clyybber> Because an `ifexpr` is special
15:53:32FromGitter<Clyybber> Only one implicit line ⏎ ⏎ ``` var result: T``` ⏎ ⏎ is far less complex than immutability defying `ifexpr` or case expressions. [https://gitter.im/nim-lang/Nim?at=5c2100fb92cf4d2242eab973]
15:54:59FromGitter<Clyybber> IMO `result` is not the source of complexity here.
15:56:00FromGitter<arnetheduck> how does `ifexpr` defy immutability? why is it more complex?
15:56:36*tribly quit (Quit: WeeChat 2.3)
15:57:16*tribly joined #nim
15:57:28FromGitter<arnetheduck> generally, choice is the source of complexity - specially subtle choice.. and of the 3 options available, result seems like the least useful one
16:00:23*Snircle quit (Quit: Textual IRC Client: www.textualapp.com)
16:02:16FromGitter<arnetheduck> ...and the one that fits the other language constructs the least
16:04:29*rq joined #nim
16:05:10*vlad1777d quit (Ping timeout: 250 seconds)
16:10:03*rq quit (Quit: Page closed)
16:22:11*endragor joined #nim
16:23:13FromGitter<alehander42> there is so much code that depends on result
16:23:22FromGitter<alehander42> that this is just a hypothetical discussion
16:28:11FromGitter<arnetheduck> haha, well yes and no.. it's a question for new code as well as gaining understanding in where the language is heading / how it all fits together
16:31:07FromGitter<arnetheduck> for example, constructors and guaranteed-return-value-analysis are up for discussion and affected by this quirk..
16:31:37FromGitter<Clyybber> @arnetheduck Disregard what I said about the complexity of 'ifexpr'. I guess both approaches are complex enough. I agree that result is not needed per se, but OTOH to the user its just syntactic sugar for initializing and returning a variable yourself.
16:32:19FromGitter<alehander42> @arnetheduck I agree with @Clyybber : you can always autoconvert functions with result to functions where its explicitly defined and then returned in the end
16:32:28FromGitter<alehander42> isn't this enough for analysis?
16:33:59FromGitter<Clyybber> To the user its syntqctic sugar, to the language devs its an opportunity for optimization. It's not like the compiler HAS to optimize.
16:34:01FromGitter<alehander42> the fact that the result shorthand exists shouldn't really affect sem checking: at least it didn't seem to be hard to support in my nil ref analysis
16:34:09FromGitter<Clyybber> Yeah
16:34:27FromGitter<alehander42> (admittedly i might have missed something )
16:34:28FromGitter<arnetheduck> no, because as noted, then you lose the guarantee that it *is* assigned to - in the backend as well - and you need to write an analysis pass for it (for example to skip zero-init)..
16:36:39FromGitter<arnetheduck> and the fact that `result` exists changes sem checking - for example, it disables the `last-expression-is-return`
16:39:17*fthe quit (Remote host closed the connection)
16:39:38*fthe joined #nim
16:40:52FromGitter<arnetheduck> it's kind of bad for everyone involved :) the developer loses warnings that all branches assign a result, the semantic checking is more complex because of it and the backend has to do extra analysis
16:42:16FromGitter<Clyybber> Why does it not have to do that analysis if the user decides to return an uninitalized var?
16:42:24FromGitter<mratsim> The issue is not result but the default init then
16:42:44FromGitter<Clyybber> Yeah
16:43:15FromGitter<Clyybber> That seems to be the issue here, in conjunction with let initialization guarantees
16:45:05FromGitter<mratsim> We could ask people that want to keep value uninitialized to explicitly tag the proc {.noinit.}
16:45:36FromGitter<mratsim> otherwise they have to provide a value (and we can’t reuse the not nil code)
16:45:57FromGitter<mratsim> can*
16:48:12FromGitter<arnetheduck> so in the backend, it goes like this right now: `set_result_to_0(); update_result()` - if the first step can be skipped safely, that's a big win.. it's a big win for me as a programmer as well - it's far more common that I want to set a value than that I don't, and I want the compiler to help me detect that dangling else branch that's only one or two spaces away
16:49:17FromGitter<Clyybber> Probably a bad ideq, but cou
16:50:45FromGitter<Clyybber> Probably a bad idea, but could we genrate two functions for every proc, one with initialized result value and the other as it is know, and use them depending on wether the variable the result gets assigned to is immutable or mutable?
16:53:38FromGitter<Clyybber> @arnetheduck How do `let`s guarantees work when one was to do:
16:54:45FromGitter<Clyybber> ```var a #assuming this is uninitialized ⏎ let b = a``` [https://gitter.im/nim-lang/Nim?at=5c210f5437975e7ca91a5567]
16:55:38*plushie joined #nim
16:55:40plushierizon
16:55:44plushieoops
16:57:09FromGitter<arnetheduck> it's not about whether the target variable is mutable or not - the same holds for `var a = if ... else: ...` - it's a matter of the semantic of the language guaranteeing a value in a context or not doing so - the guarantee is useful both for optimization and for delivering a good developer experience
16:57:59FromGitter<arnetheduck> uninitialized doesn't exist in nim (unless you use `{.noinit.}` like @mratsim points out - everything is set to 0, always (even when it's an invalid value for the type :))
16:59:17*Perkol joined #nim
17:03:10FromGitter<Clyybber> So where is the problem then, if result is set to 0 by default too?
17:06:59*fthe quit (Remote host closed the connection)
17:07:25*fthe joined #nim
17:08:57*Snircle joined #nim
17:11:08FromGitter<arnetheduck> for optimization, it's expensive (imagine it's an array of 1000 values).. for the user, well, if I'm writing a function that returns some value, it's likely I want the function to actually calculate that value in all branches of my code
17:11:52*a_b_m joined #nim
17:11:54*abm quit (Ping timeout: 250 seconds)
17:17:32FromGitter<Clyybber> But that would mean that things like
17:18:17FromGitter<Clyybber> ```var a ⏎ return a``` [https://gitter.im/nim-lang/Nim?at=5c2114d9db5b5c6883feea02]
17:18:50FromGitter<Clyybber> would have to
17:19:12FromGitter<Clyybber> (oh god, gitter on mobile is hell)
17:19:16*fthe quit (Ping timeout: 250 seconds)
17:20:09FromGitter<Clyybber> Disregard my unfinished message.
17:20:26FromGitter<Clyybber> What do you mean with
17:20:34*a_b_m quit (Ping timeout: 250 seconds)
17:20:38FromGitter<Clyybber> "I want the function to actually calculate that value in all branches of my code"?
17:20:50FromGitter<Clyybber> Which value?
17:26:07FromGitter<arnetheduck> ```code paste, see link``` [https://gitter.im/nim-lang/Nim?at=5c2116af93cce97d3b8fa84a]
17:27:39FromGitter<arnetheduck> it's just as bad on desktop, sometimes :) ⏎ the return value... errors like above - where some branches fail to return a value, or accidentally overwrite the previous one
17:28:07FromGitter<arnetheduck> if I don't use `result` in the above code, the compiler will warn me
17:32:06FromGitter<Clyybber> Yeah, one looses some warnings.
17:33:07FromGitter<Clyybber> But its all optional
17:34:01*kapil____ joined #nim
17:35:11FromGitter<Clyybber> It's optional elegance with "Use at your own risk" semantics
17:37:17FromGitter<Clyybber> I agree it doesnt fit everywhere, but thats what return is for.
17:37:48*fthe joined #nim
17:42:06FromGitter<arnetheduck> convenience, yes.. elegance, questionable
17:50:04*endragor quit (Remote host closed the connection)
17:54:30*a_b_m joined #nim
17:55:05*endragor joined #nim
18:00:00*endragor quit (Ping timeout: 272 seconds)
18:10:20*Snircle quit (Quit: Textual IRC Client: www.textualapp.com)
18:16:23*Snircle joined #nim
18:17:00*Snircle quit (Remote host closed the connection)
18:19:44*Perkol quit (Quit: Leaving)
18:22:27*Snircle joined #nim
18:46:15*Perkol joined #nim
18:51:29*Perkol quit (Remote host closed the connection)
18:53:23*Perkol joined #nim
18:55:25*Perkol quit (Remote host closed the connection)
18:59:39*Perkol joined #nim
18:59:44*fthe quit (Ping timeout: 246 seconds)
19:01:52*Tyresc joined #nim
19:09:54*Snircle quit (Quit: Textual IRC Client: www.textualapp.com)
19:22:48anamokbye
19:22:53*anamok quit (Remote host closed the connection)
19:26:40*zachk joined #nim
19:27:26*zachk quit (Changing host)
19:27:26*zachk joined #nim
19:52:27*nsf quit (Quit: WeeChat 2.3)
20:04:09*zachk quit (Remote host closed the connection)
20:04:31*zachk joined #nim
20:09:20*zachk quit (Changing host)
20:09:20*zachk joined #nim
20:19:46*Perkol quit (Remote host closed the connection)
20:29:36FromGitter<dom96> Happy holidays everyone! :)
20:36:00FromGitter<alehander42> happy holidays :)
20:52:17FromGitter<zacharycarter> +1
21:28:08*OrganicAnywhere joined #nim
21:28:50*Senketsu joined #nim
21:32:49FromGitter<rayman22201> Happy holidays
21:33:42AraqMerry christmas!
21:40:06OrganicAnywhereMerry christmas everyone! =)
21:42:23*kapil____ quit (Quit: Connection closed for inactivity)
21:47:59*vlad1777d joined #nim
21:48:12*azuri5 joined #nim
21:52:42FromGitter<GULPF> Merry Christmas :)
21:53:45kinkinkijkinmerry holimas
22:09:43*Vladar quit (Remote host closed the connection)
22:15:49*Senketsu quit (Quit: Leaving)
22:32:23FromGitter<Clyybber> Harry christdays
22:39:39*azuri5 quit (Quit: azuri5)
22:49:03*NimBot joined #nim
22:50:00reverehappy festivus federico3
23:04:52*OrganicAnywhere quit (Quit: See you in hell, madafaka~)
23:11:20*druonysus quit (Read error: Connection reset by peer)
23:15:23FromGitter<arnetheduck> yeah, season's greetings everyone!
23:52:41FromGitter<timotheecour> joyeux noel everyone!
23:55:30*endragor joined #nim