00:05:59 | * | vlad1777d quit (Ping timeout: 244 seconds) |
00:12:55 | FromGitter | <Clyybber> Araq: Regarding your comment on static T ; could we make int Literals be convertible to static int? |
00:13:24 | Araq | they are but it's lipstick on a pig |
00:29:14 | * | Cthalupa quit (Ping timeout: 244 seconds) |
00:30:11 | FromGitter | <Clyybber> Araq: What are the fundamental problems of static in your opinion? |
00:30:36 | * | Cthalupa joined #nim |
00:35:39 | Araq | 1. is it a type or a value? |
00:35:59 | Araq | in generics it says "value allowed/required here". |
00:36:21 | Araq | in proc parameters it says "compile-time value required here" |
00:36:47 | Araq | but these are two different things. |
00:37:31 | Araq | 2. it doesn't compose well in the type system |
00:37:41 | Araq | a) what is a 'static' return type? |
00:37:56 | Araq | b) what is a tuple[a: static int; b: int] ? |
00:38:28 | Araq | 3. the type relation between T and static T is unspecified. subtype relation? |
00:38:40 | Araq | but then why does static T match better than T? |
00:39:17 | Araq | 4. what does that enable that the older 'range' type didn't? |
00:40:10 | Araq | 5. what is the type of [1, 2] ? |
00:40:18 | Araq | - array[2, int] |
00:40:27 | Araq | - array[static 2, int] |
00:40:39 | Araq | - array[static 2, static int] ? |
00:40:48 | Araq | - static array[static 2, static int] ? |
00:43:25 | Araq | By the spec the type is 'array[2, int]' btw, no 'static' in sight because it's a broken concept. |
00:44:09 | Araq | it's a type qualifier like 'volatile' or 'const' in C++, broken beyond repair, an endless source of complexity. |
00:45:54 | Araq | C/C++: The type system reflects the requirement for memory-mapped IO interfaces (volatile). Total bullshit, have peek/poke builtins for that ffs. |
00:53:47 | FromGitter | <Clyybber> 'array[2, int]' |
00:54:06 | FromGitter | <Clyybber> Sry, mistyped |
00:54:27 | Araq | it's actually array[range[0..1], int] but I was too lazy to type it out |
00:54:52 | Araq | and there might also be a confusion between 2 and range[0..1] |
00:55:04 | FromGitter | <Clyybber> So does the compiler implicitly convert the 2 Int literal to a range? |
00:55:09 | Araq | but that would add more confusion on top of static. |
00:55:38 | Araq | now apparently you can also calculate with these types/values |
00:56:14 | Araq | proc `&`(a: array[N, T]; b: array[M, T]): array[N+M, T] |
00:56:50 | Araq | but that means that we actually have a '+' on *typedescs* |
00:57:40 | Araq | turning range[N] + range[M] into range[N+M], lifting the + from values into the type domain |
00:58:24 | Araq | that's awesome, but doesn't require 'static' either |
00:59:00 | FromGitter | <Clyybber> Does static allow stuff like static string? |
00:59:55 | Araq | yes but it's not clear what kind of calculations are supported with it |
01:00:32 | Araq | and proc foo(s: static string) does not count, that's not an arbitrary type computation |
01:00:56 | Araq | that's merely an additional constraint on the 's' parameter |
01:03:08 | Araq | proc 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:34 | Araq | proc foo[N: static int]() = echo valueof(N) # clarity. |
01:04:09 | Araq | having said all that, I can now write a spec for it and clean it up |
01:04:29 | Araq | and with a spec we can fix the compiler bugs... |
01:04:30 | FromGitter | <Clyybber> Gitter formatting fucked up your code |
01:04:53 | Araq | read our irclogs then |
01:05:21 | FromGitter | <Clyybber> Yeah will do, or I might as well join by IRC, gitter annoys me a bit :P |
01:08:56 | FromGitter | <Clyybber> Would it make sense to treat identifiers to static int/string like a literal? |
01:14:21 | FromGitter | <Clyybber> So we can say static int is not convertable to int, but is convertible to intLit. |
01:20:00 | FromGitter | <Clyybber> Nevermind, that would mean static int is convertable to int |
01:20:39 | FromGitter | <Clyybber> Which would be fine I guess. |
01:23:40 | FromGitter | <Clyybber> But that would mean it would be equivalent to const int... |
01:23:57 | FromGitter | <Clyybber> which it isn't. |
01:26:06 | FromGitter | <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:33 | FromGitter | <Clyybber> Is that right? |
01:27:31 | Araq | 'const int' is not a type |
01:27:46 | Araq | but I get what you mean, yes |
01:41:04 | FromGitter | <Clyybber> Hmm, yeah static T is pretty complex |
01:42:14 | FromGitter | <Clyybber> I guess the best way to go about them is to treat them the same as literals. |
01:43:21 | FromGitter | <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:13 | PrimHelios | anyone 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:18 | FromGitter | <gogolxdong> Is there an easy way to split a seq to subseqs sizes 4? |
02:56:08 | FromGitter | <zacharycarter> https://nim-lang.org/docs/sequtils.html#distribute%2Cseq%5BT%5D%2CPositive |
02:56:53 | FromGitter | <gogolxdong> not into 4 seqs, into seqs of size 4. |
02:57:20 | FromGitter | <gogolxdong> tried distribute. |
02:57:24 | FromGitter | <zacharycarter> ah - sorry |
03:00:05 | * | banc quit (Quit: Bye) |
03:00:14 | * | wildlander quit (Quit: have a nice xmas o/) |
03:12:30 | FromGitter | <gogolxdong> ```code paste, see link``` [https://gitter.im/nim-lang/Nim?at=5c204e9e5064a51f83691dff] |
03:12:49 | FromGitter | <gogolxdong> I can only make this. |
03:16:18 | * | banc joined #nim |
03:22:27 | PrimHelios | was that segfault because newDiscord was returning "ref Discord" which is already a ref object? |
03:24:28 | FromGitter | <zacharycarter> PrimHelios - I can't say that's the reason for the segfault |
03:24:47 | FromGitter | <zacharycarter> but you're correct that newDiscord should be returning Discord not ref Discord |
03:25:04 | FromGitter | <zacharycarter> ref Discord would insinuate that you're returning a gc-traced ref to an already gc-traced ref |
03:25:14 | FromGitter | <zacharycarter> I assume that is why though |
03:25:37 | FromGitter | <zacharycarter> try removing it and replacing it and see if the segfault comes and goes |
03:25:56 | PrimHelios | i did. just changed the "ref" keyword and it compiles and runs just fine now |
03:26:18 | FromGitter | <zacharycarter> cool - good catch I didn't see that initially when you asked |
03:28:19 | PrimHelios | so, does that mean declaring an object as "ref object" means that every instance is a traced reference? |
03:28:41 | FromGitter | <zacharycarter> yes |
03:29:13 | PrimHelios | ah, cool. i've never had this much control over stuff before :P |
03:29:18 | FromGitter | <zacharycarter> you can also use unsafe ptr if you want |
03:29:36 | FromGitter | <zacharycarter> which would be a unsafe reference not traced by the GC |
03:30:16 | PrimHelios | gosh, a lot more control than python. i kinda love it to be honest |
03:30:20 | FromGitter | <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:04 | FromGitter | <zacharycarter> Nim is definitely lower-level than Python |
03:31:24 | FromGitter | <zacharycarter> and if you're looking for a more performant python, Nim is a nice option to explore |
03:32:09 | PrimHelios | yeah, 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:49 | FromGitter | <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:03 | FromGitter | <zacharycarter> for web and game programming |
03:34:25 | FromGitter | <zacharycarter> once I have my engine in a more stable state - I'll work on an editor in Nim |
03:35:19 | FromGitter | <zacharycarter> it does have some very attractive features |
03:48:31 | shashlick | @zacharycarter: what kind of editpr |
03:49:09 | FromGitter | <zacharycarter> 3d game editor |
03:49:33 | FromGitter | <zacharycarter> which uses the engine I'm working on |
04:00:28 | FromGitter | <zacharycarter> shashlick: this one - https://github.com/zacharycarter/zeal |
04:13:07 | shashlick | Nice |
04:16:44 | FromGitter | <zacharycarter> thanks |
04:16:57 | FromGitter | <zacharycarter> most of it I didn't write :P but I have gotten it working on macos |
04:17:16 | FromGitter | <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:11 | FromGitter | <kaushalmodi> @Araq Some progress with nightlies Travis: https://travis-ci.org/nim-lang/nightlies/builds/471757921 |
05:37:50 | FromGitter | <kaushalmodi> The nightlies releases are now publishing as before: https://github.com/nim-lang/nightlies/releases |
05:38:28 | FromGitter | <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:46 | kinkinkijkin | what is the best way to see if a seq contains an item matching a given item ? it's probably in sequtils right |
05:44:56 | leorize | kinkinkijkin: `if item in seq` |
05:45:16 | kinkinkijkin | oh that's a lot easier than i was going to da |
05:45:20 | kinkinkijkin | do * |
05:48:34 | kinkinkijkin | wait, 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:10 | shashlick | @kaushalmodi: you got windows running on travis? |
05:49:53 | leorize | kinkinkijkin: no, it can only look for the entire item |
05:50:07 | leorize | I'd suggest using `tables` module instead if you need such use case |
05:59:01 | * | dddddd quit (Remote host closed the connection) |
06:00:01 | FromGitter | <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:10 | shashlick | ya looks like he figured it out too - https://github.com/nim-lang/nightlies/blob/master/.travis.yml#L21 |
06:01:41 | shashlick | --hints:on|off|list |
06:01:54 | FromGitter | <xmonader> oh! thanks! |
06:03:10 | FromGitter | <xmonader> ```code paste, see link``` ⏎ ⏎ much better [https://gitter.im/nim-lang/Nim?at=5c20769ecac5bc2241dc1e5c] |
06:04:53 | shashlick | you could set --verbosity:0 eventually |
06:07:44 | FromGitter | <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:08 | anamok | hi |
07:00:46 | anamok | When 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:33 | shashlick | you could try $+$. but not sure if it will work though |
07:06:19 | * | Vladar joined #nim |
07:06:53 | anamok | Here is my current code: http://ix.io/1wGH/nim |
07:10:37 | leorize | anamok: try this string: "$*from $w to $w$*." |
07:10:54 | leorize | you'd need a `tmp` variable to discard the `$*` match |
07:13:32 | anamok | Thanks, it works. Could you explain what it means? I don't see why they are different, once it's $* , then it's $*. |
07:17:40 | leorize | $* requires a token after it for a match |
07:22:39 | anamok | And what is $*. ? What does the . mean for strscans? |
07:23:40 | * | endragor joined #nim |
07:24:53 | leorize | anamok: a literal `.` |
07:27:21 | anamok | If I remove the "0.10.2", then how to say "go until then end and match everything"? |
07:27:58 | leorize | from what I can see, you'd need a custom matcher |
07:28:06 | leorize | http://nim-lang.github.io/Nim/strscans.html#user-definable-matchers |
07:28:17 | * | endragor quit (Ping timeout: 268 seconds) |
07:28:35 | kinkinkijkin | oh 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:42 | kinkinkijkin | absolutely no reason for this |
07:30:27 | anamok | use choosenim to install Nim |
07:31:28 | kinkinkijkin | im building manually right now |
07:31:41 | * | nsf joined #nim |
07:31:58 | shashlick | I'm thinking of making a Nim snap |
07:34:05 | anamok | shaslick: $+$. doesn't work |
07:44:33 | PrimHelios | kinkinkijkin: i've noticed quite a few ubuntu packages are ridiculously out of date, unfortunately :\ |
07:45:05 | leorize | anamok: proc tilEoL(input: string; start: int): int = input.high - start |
07:45:16 | leorize | ^ that's a custom matcher that'll skip the rest of the input |
07:45:36 | leorize | use it like this "$[tilEoL]" |
07:46:55 | anamok | leorize: 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:18 | FromDiscord_ | <exelotl> Is it possible to make nimsuggest work with files that are to be 'include'd elsewhere in the project? |
09:02:43 | leorize | as 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:15 | FromDiscord_ | <exelotl> So do I need to make a config file to tell it which files are supposed to be compiled? |
09:20:36 | leorize | nimsuggest should be able to detect your project automatically |
09:24:59 | FromDiscord_ | <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:01 | leorize | then it should work normally |
09:26:15 | FromDiscord_ | <exelotl> When I save a file with procedures, I get errors about missing types |
09:26:34 | FromDiscord_ | <exelotl> If I save the root file the errors go away |
09:27:04 | FromDiscord_ | <exelotl> But if I go back and save the procedures file the errors come back |
09:27:29 | leorize | I think it might be `nim check` complaining and not `nimsuggest` |
09:29:12 | FromDiscord_ | <exelotl> Hm maybe, I'm just using the nim vscode extension |
09:29:55 | leorize | you can try `cd`-ing to the directory and run `nim check` on that file manually |
09:30:27 | FromDiscord_ | <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:57 | FromGitter | <dom96> @mratsim Pro tip: create a Show HN next time |
10:30:15 | FromGitter | <mratsim> well last time it didn’t work ;) |
10:41:06 | anamok | Say 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:00 | Araq | "$*($*)$*$." maybe |
10:45:24 | Araq | requires 3 variables and you only use the 2nd |
10:45:34 | * | xet7 quit (Quit: Leaving) |
10:47:09 | Araq | or you use a custom matcher |
10:47:21 | anamok | Thanks, it's solved. |
10:47:26 | * | xet7 joined #nim |
10:48:39 | Araq | sadly it doesn't support $[*(] :-) |
10:54:06 | anamok | Araq: $*$. doesn't work. It should mean "take everything until the end and store in a variable", but it doesn't match. |
10:54:25 | Araq | yeah probably not |
10:54:39 | Araq | the $* only supports real tokens not meta tokens |
10:54:55 | Araq | on the other hand, since you can skip the rest |
10:55:08 | Araq | "$*($*)" suffices |
11:02:52 | anamok | A workaround could be to add a special character to the end, e.g. '|', and then catch everything until the end with $*| . |
11:03:35 | anamok | if 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:26 | anamok | I 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:37 | anamok | How could I modify the elements of this seq? |
12:34:22 | leorize | how are you modifying them? |
12:36:24 | anamok | `for g in groups: g.done = false` |
12:38:01 | leorize | use the mitems iterator instead |
12:38:10 | leorize | the default items iterator is immutable |
12:40:03 | anamok | Thanks. Wow, nim is full of surprises :) |
12:41:59 | * | filcuc joined #nim |
13:01:28 | * | filcuc quit (Ping timeout: 246 seconds) |
13:20:03 | FromGitter | <kaushalmodi> shashlick: The windows bit in the nightlies Travis was added by Araq |
13:21:08 | FromGitter | <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:00 | FromGitter | <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:19 | FromDiscord_ | <hotdog> How can I convert `static[string]` to string literal? |
14:12:42 | FromGitter | <mratsim> you can use them as string literal nothing special to do |
14:14:51 | FromDiscord_ | <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:19 | FromGitter | <mratsim> you probably are passing it through a void proc |
14:15:28 | FromGitter | <mratsim> what’s the full line? |
14:17:25 | FromGitter | <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:25 | FromGitter | ... is set / was touched at least once, etc).. it sure is a good candidate for simplification.. |
14:18:21 | FromDiscord_ | <hotdog> @mratsim https://hastebin.com/zodamilori.md |
14:18:43 | FromGitter | <Clyybber> `block`, `if` and `try` have no return either |
14:19:17 | FromDiscord_ | <hotdog> expression: getOrDefault(procTable, ) |
14:19:17 | FromDiscord_ | <hotdog> expression '' is of type: void |
14:19:31 | * | endragor quit (Ping timeout: 246 seconds) |
14:19:59 | FromGitter | <Clyybber> @arnetheduck It's just a small convenience feature that makes some optimizations easier to do |
14:20:26 | FromGitter | <Clyybber> I don't find it confusing |
14:25:16 | FromGitter | <Clyybber> I'm all for simplification, but I don't find the implicit result variable to be a complex element of nim |
14:25:44 | FromGitter | <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:58 | FromGitter | <mratsim> there is still an issue though. |
14:26:38 | FromGitter | <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:47 | FromGitter | <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:03 | FromDiscord_ | <hotdog> @mratsim thanks. I'll have a look at your examples |
14:29:17 | * | Cthalupa joined #nim |
14:29:18 | FromGitter | <mratsim> my exampels are compile-time though |
14:30:17 | FromGitter | <mratsim> I’m trying to fix it |
14:31:38 | * | a_chou joined #nim |
14:32:04 | FromGitter | <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:38 | FromGitter | <mratsim> @hotdog, here you go: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/nim-lang/Nim?at=5c20ee42db5b5c6883fe06ce] |
14:34:24 | FromGitter | <mratsim> This works as well ⏎ ⏎ ```code paste, see link``` [https://gitter.im/nim-lang/Nim?at=5c20ee70cac5bc2241def894] |
14:34:38 | FromGitter | <mratsim> I suppose it’s the missing “a” parameter that threw a confusing error |
14:34:57 | * | a_chou joined #nim |
14:35:03 | FromGitter | <mratsim> you can open a github issue regarding this error message (it’s not even related to the .() template) |
14:35:33 | FromGitter | <mratsim> closure with missing arguments just display, got <>. |
14:36:03 | FromDiscord_ | <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:18 | FromDiscord_ | <hotdog> There was a series of confusing errors |
14:36:35 | FromGitter | <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:54 | FromDiscord_ | <hotdog> I'll open an issue for it |
14:37:00 | FromGitter | <Clyybber> @arnetheduck What do you mean 3 different ways? |
14:37:00 | FromDiscord_ | <hotdog> Thanks for your help! |
14:37:12 | FromGitter | <Clyybber> Its just 1. dont use result use return |
14:37:17 | FromGitter | <Clyybber> 1) use result |
14:37:28 | FromGitter | <Clyybber> 1) use both (kinda weird) |
14:37:51 | FromGitter | <Clyybber> I could swear I wrote 1., 2. and 3. gitter is weird |
14:37:53 | FromGitter | <mratsim> the last expression is also implicitly returned |
14:37:58 | FromGitter | <Clyybber> Yeah |
14:39:41 | Araq | arnetheduck: not again. what is weird is 'return', mixing setting the result with a control flow operation |
14:39:45 | FromGitter | <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:49 | FromGitter | <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:58 | Araq | and it's not my fault you never used Eiffel or Delphi before. |
14:40:07 | * | a_chou quit (Quit: a_chou) |
14:41:33 | FromGitter | <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:56 | FromGitter | <Clyybber> @arnetheduck blocks are not eqivalent to procs, but I see where you are coming from. |
14:44:30 | FromGitter | <Clyybber> I personally dont like to put a block after a `=` |
14:45:35 | FromGitter | <mratsim> it’s just statement vs expressions |
14:46:40 | * | abm joined #nim |
14:46:52 | FromGitter | <Clyybber> Araq: Am I right in the assumption that: ⏎ ⏎ ```doSomethingUnrelated() ⏎ let a = 42``` ⏎ ⏎ ? [https://gitter.im/nim-lang/Nim?at=5c20f15cd945b96882eb7fd7] |
14:47:45 | FromGitter | <arnetheduck> @Clyybber only because `42` is side-effect free - otherwise you'd have to consider order-of-evaluation |
14:48:10 | FromGitter | <Clyybber> When would there be a difference regardless? |
14:48:43 | FromGitter | <arnetheduck> ```let a = ⏎ doSomething() ⏎ doSomethingElseThatRetuns()``` [https://gitter.im/nim-lang/Nim?at=5c20f1cbab910e7d3ac74d63] |
14:49:31 | FromGitter | <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:34 | FromGitter | <mratsim> this won’t return anything because the last one is a statement |
14:50:56 | FromGitter | <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:21 | FromGitter | <arnetheduck> ie `=` does stuff beyond what's visible |
14:51:50 | FromGitter | <Clyybber> Wouldn't `=` be called when the block finishes? |
14:52:24 | * | stefanos82 quit (Remote host closed the connection) |
14:53:11 | FromGitter | <arnetheduck> hm, yeah, good point - not sue |
14:54:21 | FromGitter | <Clyybber> Everything else would be illogical |
14:55:05 | FromGitter | <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:14 | FromGitter | <Clyybber> IMO that usage of the block syntax is much more confusing than a implicit result variable |
15:00:38 | FromGitter | <mratsim> block is useful for scoping, especially when we deal with huge procs like in the current Ethereum specs :/ |
15:00:55 | FromGitter | <zacharycarter> I think I'll only need slight modifications to get zserge's webview working to support native child windows |
15:01:01 | FromGitter | <zacharycarter> which means I should be able to use it to host my game engine |
15:01:19 | FromGitter | <zacharycarter> and thus, use it in my editor |
15:01:47 | FromGitter | <zacharycarter> apologies - thought I was in OT |
15:02:34 | FromGitter | <Clyybber> @mratsim Yeah, sure. I did not mean the block syntax in general... I meant using a `block: ...` as an expression |
15:02:53 | FromGitter | <Clyybber> @zacharycarter Where did your messages go? :P |
15:04:05 | FromGitter | <mratsim> I like it as well, I use it where I would use a lambda in a functional language |
15:04:19 | FromGitter | <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:42 | FromGitter | <Clyybber> @mratsim Yeah, its basically equivalent to a lambda. |
15:05:25 | FromGitter | <Clyybber> But then @arnetheduck's concerns apply to it too |
15:06:00 | FromGitter | <Clyybber> As in why there is no return and implicit result in block |
15:06:31 | FromGitter | <mratsim> because it’s not a function? |
15:06:34 | FromGitter | <Clyybber> But I guess its best to think about a block as just some lines of code. |
15:09:51 | FromGitter | <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:21 | FromGitter | <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:41 | FromGitter | <Clyybber> Or am I missing something? |
15:13:40 | FromGitter | <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:41 | FromGitter | <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:11 | FromGitter | <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:28 | FromGitter | <mratsim> let wouldn’t work @Clyybber if creates a new scope |
15:16:41 | FromGitter | <Clyybber> Yeah I just noticed that :D |
15:19:27 | FromGitter | <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:52 | FromGitter | <Clyybber> A proc shouldn't rely on the fact that its result parameter could be mapped to a let variable |
15:23:37 | FromGitter | <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:51 | FromGitter | <arnetheduck> ```func f(): int = ⏎ result = 42 ⏎ 53``` ⏎ ⏎ is a motivating example [https://gitter.im/nim-lang/Nim?at=5c20fa433c4093612c567202] |
15:25:02 | FromGitter | <arnetheduck> (doesn't compile) |
15:25:44 | FromGitter | <Clyybber> Doesn't the compiler translate stuff like ⏎ ⏎ `````` [https://gitter.im/nim-lang/Nim?at=5c20fa78d945b96882ebbb81] |
15:26:48 | FromGitter | <Clyybber> ```code paste, see link``` ⏎ ⏎ ? [https://gitter.im/nim-lang/Nim?at=5c20fab8ab910e7d3ac788d6] |
15:28:00 | FromGitter | <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:52 | FromGitter | <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:48 | FromGitter | <arnetheduck> or no. actually it's `(vardef (a) (ifexpr))` where `ifexpr` is the init portion of vardef |
15:30:31 | FromGitter | <arnetheduck> bah. can never remember the details, so many different node types in the AST :/ |
15:30:34 | FromGitter | <Clyybber> So does it ingore the immutability of `a` or does it create a temporary variable? |
15:31:49 | FromGitter | <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:11 | FromGitter | <arnetheduck> there's no ast rewrite involved |
15:32:42 | FromGitter | <arnetheduck> the cgen I remember is complicated, with differences between c and c++ |
15:34:14 | FromGitter | <Clyybber> I guess it will just violate the immutability |
15:35:03 | FromGitter | <Clyybber> But that shouldn't matter if it does it correctly |
15:35:38 | FromGitter | <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:41 | FromGitter | <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:07 | FromGitter | <Clyybber> Thats the simplification I would be inclined to do |
15:39:08 | FromGitter | <Clyybber> And remove ifexpr altogether |
15:39:34 | FromGitter | <Clyybber> In the AST that gets passed to the cgen |
15:40:18 | FromGitter | <Clyybber> And remove `ifexpr` in the AST that gets passed to the cgen |
15:43:50 | FromGitter | <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:35 | FromGitter | <Clyybber> Well, immutability is not a concept that can be united with a result variable |
15:46:37 | FromGitter | <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:46 | FromGitter | <arnetheduck> so in the thought process, education and special-casing is needed to explain it, which is a cost |
15:48:04 | FromGitter | <Clyybber> Because an `ifexpr` is special |
15:53:32 | FromGitter | <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:59 | FromGitter | <Clyybber> IMO `result` is not the source of complexity here. |
15:56:00 | FromGitter | <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:28 | FromGitter | <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:16 | FromGitter | <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:13 | FromGitter | <alehander42> there is so much code that depends on result |
16:23:22 | FromGitter | <alehander42> that this is just a hypothetical discussion |
16:28:11 | FromGitter | <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:07 | FromGitter | <arnetheduck> for example, constructors and guaranteed-return-value-analysis are up for discussion and affected by this quirk.. |
16:31:37 | FromGitter | <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:19 | FromGitter | <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:28 | FromGitter | <alehander42> isn't this enough for analysis? |
16:33:59 | FromGitter | <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:01 | FromGitter | <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:09 | FromGitter | <Clyybber> Yeah |
16:34:27 | FromGitter | <alehander42> (admittedly i might have missed something ) |
16:34:28 | FromGitter | <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:39 | FromGitter | <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:52 | FromGitter | <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:16 | FromGitter | <Clyybber> Why does it not have to do that analysis if the user decides to return an uninitalized var? |
16:42:24 | FromGitter | <mratsim> The issue is not result but the default init then |
16:42:44 | FromGitter | <Clyybber> Yeah |
16:43:15 | FromGitter | <Clyybber> That seems to be the issue here, in conjunction with let initialization guarantees |
16:45:05 | FromGitter | <mratsim> We could ask people that want to keep value uninitialized to explicitly tag the proc {.noinit.} |
16:45:36 | FromGitter | <mratsim> otherwise they have to provide a value (and we can’t reuse the not nil code) |
16:45:57 | FromGitter | <mratsim> can* |
16:48:12 | FromGitter | <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:17 | FromGitter | <Clyybber> Probably a bad ideq, but cou |
16:50:45 | FromGitter | <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:38 | FromGitter | <Clyybber> @arnetheduck How do `let`s guarantees work when one was to do: |
16:54:45 | FromGitter | <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:40 | plushie | rizon |
16:55:44 | plushie | oops |
16:57:09 | FromGitter | <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:59 | FromGitter | <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:10 | FromGitter | <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:08 | FromGitter | <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:32 | FromGitter | <Clyybber> But that would mean that things like |
17:18:17 | FromGitter | <Clyybber> ```var a ⏎ return a``` [https://gitter.im/nim-lang/Nim?at=5c2114d9db5b5c6883feea02] |
17:18:50 | FromGitter | <Clyybber> would have to |
17:19:12 | FromGitter | <Clyybber> (oh god, gitter on mobile is hell) |
17:19:16 | * | fthe quit (Ping timeout: 250 seconds) |
17:20:09 | FromGitter | <Clyybber> Disregard my unfinished message. |
17:20:26 | FromGitter | <Clyybber> What do you mean with |
17:20:34 | * | a_b_m quit (Ping timeout: 250 seconds) |
17:20:38 | FromGitter | <Clyybber> "I want the function to actually calculate that value in all branches of my code"? |
17:20:50 | FromGitter | <Clyybber> Which value? |
17:26:07 | FromGitter | <arnetheduck> ```code paste, see link``` [https://gitter.im/nim-lang/Nim?at=5c2116af93cce97d3b8fa84a] |
17:27:39 | FromGitter | <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:07 | FromGitter | <arnetheduck> if I don't use `result` in the above code, the compiler will warn me |
17:32:06 | FromGitter | <Clyybber> Yeah, one looses some warnings. |
17:33:07 | FromGitter | <Clyybber> But its all optional |
17:34:01 | * | kapil____ joined #nim |
17:35:11 | FromGitter | <Clyybber> It's optional elegance with "Use at your own risk" semantics |
17:37:17 | FromGitter | <Clyybber> I agree it doesnt fit everywhere, but thats what return is for. |
17:37:48 | * | fthe joined #nim |
17:42:06 | FromGitter | <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:48 | anamok | bye |
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:36 | FromGitter | <dom96> Happy holidays everyone! :) |
20:36:00 | FromGitter | <alehander42> happy holidays :) |
20:52:17 | FromGitter | <zacharycarter> +1 |
21:28:08 | * | OrganicAnywhere joined #nim |
21:28:50 | * | Senketsu joined #nim |
21:32:49 | FromGitter | <rayman22201> Happy holidays |
21:33:42 | Araq | Merry christmas! |
21:40:06 | OrganicAnywhere | Merry 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:42 | FromGitter | <GULPF> Merry Christmas :) |
21:53:45 | kinkinkijkin | merry holimas |
22:09:43 | * | Vladar quit (Remote host closed the connection) |
22:15:49 | * | Senketsu quit (Quit: Leaving) |
22:32:23 | FromGitter | <Clyybber> Harry christdays |
22:39:39 | * | azuri5 quit (Quit: azuri5) |
22:49:03 | * | NimBot joined #nim |
22:50:00 | revere | happy 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:23 | FromGitter | <arnetheduck> yeah, season's greetings everyone! |
23:52:41 | FromGitter | <timotheecour> joyeux noel everyone! |
23:55:30 | * | endragor joined #nim |