00:00:12 | girvo | so I assume they'll live on the stack |
00:00:15 | dom96 | yeah |
00:00:20 | girvo | beautiful |
00:00:35 | dom96 | :D |
00:00:53 | girvo | cryzed: I'm ostensibly creating a "game engine", but to be honest I'm more trying to work out what a completely safe Nim wrapper over SDL2 would look like |
00:01:08 | girvo | thanks dom96 :D |
00:01:09 | cryzed | Sounds really interesting :)! |
00:01:27 | * | zepolen joined #nim |
00:01:35 | girvo | It's something I've wanted to see for ages, and I've had a fair bit of free time for once in my life so I figured it was worth taking a shot at it |
00:01:42 | girvo | So far it's going pretty well! |
00:01:51 | * | jaco60 quit (Ping timeout: 260 seconds) |
00:02:08 | girvo | Though I keep having this need to implement ref counting for the c-allocated vars hahaha, but that's probably me just being a masochist |
00:02:11 | * | pregressive joined #nim |
00:04:09 | girvo | Oh! I also quickly ported a set of disgusting bash scripts into a docopt-based Nim CLI, for managing local Docker containers for web development; think docker-compose with actual persistance for your database |
00:04:40 | cryzed | grr, now I want to finish my shitty markdown parser :D |
00:04:55 | girvo | The Nim code is gross though because I had 30 minutes to do it and my Nim was rusty as hell, heh: https://github.com/girvo/dup |
00:05:08 | girvo | Looking forward to refactoring it to be beautiful inside and out ;) |
00:05:32 | girvo | Oh, and properly safe; currently it's just doing cmdEx with built strings hahaha |
00:05:41 | cryzed | girvo, please do. If you feel like sharing, please also let us (me) know about how you are progressing with your game engine :) |
00:06:02 | * | zepolen quit (Ping timeout: 260 seconds) |
00:06:03 | girvo | cryzed: I will~ ... mainly cause i'll be in here bugging everyone with weird questions :D |
00:06:17 | cryzed | oh, we have our fair share of that, mostly from me recently |
00:06:18 | cryzed | so don't worry |
00:06:59 | * | Learath2 quit (Ping timeout: 260 seconds) |
00:07:26 | girvo | hahaha |
00:07:47 | girvo | Also, the lead dev at work has finally stopped being a negative nancy and took a look at Nim... and loves it lol |
00:08:01 | * | Learath2 joined #nim |
00:08:41 | cryzed | :D |
00:09:33 | girvo | hey dom96: are there any projects around that show C mem management done well that I can take a look at? |
00:09:41 | girvo | In nim, I mean |
00:09:53 | dom96 | hmmm |
00:10:11 | Araq | girvo: no, but the best way to do it is this way |
00:10:12 | girvo | If not, all good :) I'm interested in what a safe wrapper looks like in nim |
00:10:19 | girvo | Oh hi Araq :D |
00:10:29 | dom96 | Nothing jumps to mind |
00:10:36 | Araq | void initT(Foo* foo); // let host language do the allocation |
00:11:06 | girvo | Araq: That's what I've been doing, made sense to me, nice |
00:11:09 | Araq | let x = newFoo() # can use Nim's GC here :-) |
00:11:16 | Araq | initT(x) # pass to C |
00:11:17 | girvo | Yay :D |
00:11:41 | girvo | I've been keeping everything in Nim's GC for as long as possible, only converting to C types right at the end |
00:12:05 | Araq | most C libraries do this though Foo* newFoo(); and then you need to deal with C's manual memory mangement in some way or the other |
00:12:18 | girvo | Araq: Best way of profiling to check for leakages? I guess I'll just run it through valgrind |
00:12:23 | girvo | Yeah that's what I've seen |
00:12:29 | girvo | Hence why I thoguht I'd ask |
00:12:52 | girvo | Getting rid of a lot of the destroy() calls littering the app code would be nice, at least if it means moving them to one place |
00:12:54 | Araq | actually valgrind is quite pointless, just check getOccupiedMem() |
00:13:25 | Araq | that it stays rather constant keeping in mind taht the cycle collector only kicks in after 4 MB |
00:13:30 | girvo | Oh yeah, fair |
00:13:32 | girvo | Nice |
00:13:42 | Araq | that's what our tests do |
00:14:02 | Araq | and from time to time we ensure getOccupiedmem agrees with what the OS reports |
00:14:11 | girvo | Awesome |
00:14:17 | girvo | I'll add it into my debug macros :) |
00:14:23 | * | pilne quit (Read error: Connection reset by peer) |
00:14:48 | * | pilne joined #nim |
00:16:09 | girvo | Is it worth my writing up some documentation on this stuff at all? Maybe even just some larger examples for the "Nim for C Programmers" wiki page |
00:16:57 | girvo | Work's giving me some hours a over the next two weeks to contribute some stuff back to OSS |
00:17:20 | cryzed | girvo, even I can say to that: definitely |
00:17:36 | cryzed | More documentation is always appreciated, I am positive |
00:17:57 | girvo | :) |
00:17:58 | Araq | well it's a wiki, free for anybody to enhance |
00:18:23 | girvo | It's already pretty well done, might just link some larger stuff based on the questions I've run into |
00:18:32 | girvo | Was extremely helpful recently |
00:20:47 | girvo | How safe is the existing SDL wrapper? |
00:22:03 | Araq | just merged a PR to the SDL2 wrapper |
00:23:06 | Araq | and I use it myself fwiw |
00:23:23 | girvo | Awesome :D |
00:23:52 | Araq | somebody needs to port graphics.nim to use SDL2 *wink* |
00:24:10 | girvo | Hah! Funny you say that, sdl2/graphics was next on my list ;) |
00:28:40 | * | Trustable quit (Remote host closed the connection) |
00:33:07 | * | lokulin quit (Ping timeout: 260 seconds) |
00:39:47 | * | lokulin joined #nim |
00:45:38 | * | nicktick joined #nim |
00:47:16 | * | pregressive quit (Remote host closed the connection) |
00:52:41 | * | pregressive joined #nim |
00:58:59 | * | lazypenguin quit (Ping timeout: 264 seconds) |
01:01:46 | * | theduke quit (Remote host closed the connection) |
01:07:16 | girvo | With Nim macros, is it possible to see if a given NimNode has a given method available? |
01:07:48 | girvo | It turned out to not really be needed in my case as the standard Nim typechecker was smart enough to realise what was going on, but I'm curious as to whether its possible |
01:11:55 | Araq | it's complex. |
01:12:11 | Araq | you can generate a 'when compiles' check for example |
01:12:31 | Araq | in general macros should not be exposed the symbol table |
01:12:48 | Araq | to keep the design resonably sound. |
01:17:17 | * | lazypenguin joined #nim |
01:20:59 | * | thotypous quit (Ping timeout: 245 seconds) |
01:23:16 | * | thotypous joined #nim |
02:14:41 | * | [CBR]Unspoken quit (Ping timeout: 246 seconds) |
02:16:14 | girvo | Yeah makes sense Araq |
02:29:40 | * | [CBR]Unspoken joined #nim |
02:31:21 | * | strcmp1 quit (Quit: return 0;) |
02:35:29 | * | strcmp1 joined #nim |
02:36:49 | * | sepisoad2 quit (Quit: Yaaic - Yet another Android IRC client - http://www.yaaic.org) |
03:01:36 | * | zepolen joined #nim |
03:05:59 | * | zepolen quit (Ping timeout: 245 seconds) |
03:17:27 | * | porchswing joined #nim |
03:52:40 | * | pilne quit (Quit: Quit!) |
04:11:03 | * | nicktick quit (Ping timeout: 260 seconds) |
04:14:55 | * | desophos quit (Quit: Leaving) |
04:15:15 | * | desophos joined #nim |
04:24:23 | * | pregressive quit (Remote host closed the connection) |
04:26:10 | * | porchswing quit (Quit: Leaving) |
04:26:31 | * | porchswing joined #nim |
04:26:58 | * | porchswing quit (Client Quit) |
04:27:07 | * | porchswing joined #nim |
04:37:33 | * | pregressive joined #nim |
04:57:21 | * | porchswing quit (Quit: Leaving) |
04:59:01 | * | zepolen joined #nim |
05:21:36 | * | darkf joined #nim |
05:35:59 | * | BitPuffin|osx quit (Ping timeout: 260 seconds) |
05:51:45 | * | pregressive quit (Remote host closed the connection) |
05:53:16 | * | pregressive joined #nim |
06:11:04 | * | SeVenSiXseVeN joined #nim |
06:33:00 | * | pregressive quit (Remote host closed the connection) |
06:35:16 | * | pregressive joined #nim |
06:53:30 | * | bjz joined #nim |
06:53:48 | * | desophos quit (Read error: Connection reset by peer) |
06:54:51 | * | pregressive quit (Remote host closed the connection) |
06:57:22 | * | bjz quit (Max SendQ exceeded) |
06:58:04 | * | bjz joined #nim |
06:59:25 | * | zepolen quit (Remote host closed the connection) |
06:59:52 | * | gokr quit (Quit: Leaving.) |
07:08:12 | * | sepisoad joined #nim |
07:08:22 | * | bjz quit (Ping timeout: 260 seconds) |
07:12:04 | * | girvo quit (Ping timeout: 250 seconds) |
07:17:18 | * | zepolen joined #nim |
07:19:53 | * | cyraxjoe_ joined #nim |
07:20:14 | * | cyraxjoe quit (Ping timeout: 246 seconds) |
07:24:22 | * | bjz joined #nim |
07:27:33 | * | exebook joined #nim |
07:42:29 | * | zepolen quit (Remote host closed the connection) |
07:48:31 | sepisoad | i tried to upgrade to latest nim compiler (0.12) on my raspberry Pi(arch linux)... |
07:49:25 | sepisoad | but the latest available version is 0.11, so i decided to get it from github |
07:50:10 | sepisoad | when i compile nim compiler the version number is 0.10 |
07:50:59 | sepisoad | how come? |
08:08:43 | * | girvo joined #nim |
08:13:15 | * | girvo quit (Ping timeout: 260 seconds) |
08:15:00 | * | sepisoad quit (Quit: Yaaic - Yet another Android IRC client - http://www.yaaic.org) |
08:15:21 | * | sepisoad joined #nim |
08:17:07 | * | yglukhov joined #nim |
08:18:39 | * | sepisoad quit (Read error: Connection reset by peer) |
08:23:25 | * | gokr joined #nim |
08:25:50 | * | bjz_ joined #nim |
08:26:44 | * | bjz quit (Ping timeout: 246 seconds) |
08:28:07 | * | zepolen joined #nim |
08:33:18 | * | zepolen quit (Ping timeout: 260 seconds) |
08:34:42 | * | lazypenguin quit (Ping timeout: 260 seconds) |
08:49:55 | * | Ven joined #nim |
08:50:29 | * | lazypenguin joined #nim |
08:55:27 | * | pregressive joined #nim |
08:55:40 | * | Trustable joined #nim |
08:56:35 | * | sepisoad joined #nim |
08:59:59 | * | pregressive quit (Ping timeout: 246 seconds) |
09:00:21 | reactormonk | sepisoad, wrong branch? |
09:03:39 | * | Demon_Fox quit (Ping timeout: 260 seconds) |
09:06:34 | sepisoad | reactormonk, but i follow the instructions on the github page |
09:07:02 | reactormonk | sepisoad, link? |
09:07:24 | reactormonk | sepisoad, master branch? |
09:10:07 | * | coffeepot joined #nim |
09:10:17 | * | nastavnic joined #nim |
09:11:42 | sepisoad | reactormonk, git clone git://github.com/nim-lang/Nim.git |
09:12:33 | sepisoad | devel branch i guess |
09:14:16 | reactormonk | sepisoad, should be devel, yup. |
09:15:34 | sepisoad | :-( |
09:19:37 | * | Trustable quit (Remote host closed the connection) |
09:20:47 | * | Trustable joined #nim |
09:23:09 | * | jaco60 joined #nim |
09:24:38 | * | makoLine quit (Ping timeout: 260 seconds) |
09:37:22 | * | zepolen joined #nim |
09:40:29 | * | sepisoad quit (Read error: Connection reset by peer) |
09:45:17 | * | coffeepot quit (Quit: http://www.kiwiirc.com/ - A hand crafted IRC client) |
09:47:40 | * | coffeepot joined #nim |
10:09:44 | * | girvo joined #nim |
10:14:34 | * | girvo quit (Ping timeout: 260 seconds) |
10:14:42 | * | cyraxjoe joined #nim |
10:15:30 | * | cyraxjoe_ quit (Ping timeout: 260 seconds) |
10:17:55 | * | sepisoad joined #nim |
10:20:44 | * | sepisoad quit (Read error: Connection reset by peer) |
10:57:48 | * | Ven quit (Quit: My MacBook has gone to sleep. ZZZzzz…) |
11:13:20 | * | nastavnic quit (Ping timeout: 246 seconds) |
11:20:30 | * | Gonzih joined #nim |
11:21:21 | * | Gonzih quit (Client Quit) |
11:21:40 | * | Gonzih joined #nim |
11:22:04 | * | Gonzih quit (Client Quit) |
11:22:50 | * | Gonzih joined #nim |
11:23:22 | * | Gonzih quit (Client Quit) |
11:24:46 | * | gokr quit (Quit: Leaving.) |
11:25:18 | * | gokr joined #nim |
11:27:29 | * | Gonzih joined #nim |
11:27:56 | * | nastavnic joined #nim |
11:31:19 | * | sepisoad joined #nim |
11:33:52 | * | sepis0ad joined #nim |
11:33:53 | * | sepisoad quit (Read error: Connection reset by peer) |
11:42:29 | * | Arrrr joined #nim |
11:44:33 | Arrrr | How can sleep give me these results? http://pastebin.com/w4Jw7F77 |
11:44:40 | Arrrr | It must be bugged or something |
11:45:17 | Arrrr | I sleep in a loop for 1 ms and running stat tells me the max value pushed is '0.016' wut |
11:50:38 | * | Gonzih quit (Quit: WeeChat 1.3) |
11:56:01 | * | irrequietus joined #nim |
11:59:06 | * | sepis0ad quit (Ping timeout: 260 seconds) |
12:05:11 | * | irrequietus quit (Ping timeout: 260 seconds) |
12:05:41 | * | irrequietus joined #nim |
12:10:29 | * | girvo joined #nim |
12:14:44 | * | girvo quit (Ping timeout: 245 seconds) |
12:22:25 | * | lokulin quit (Changing host) |
12:22:25 | * | lokulin joined #nim |
12:30:39 | def- | Arrrr: cpuTime does not measure real time |
12:31:28 | def- | "gets time spent that the CPU spent to run the current process in seconds" - so the CPU doesn't have to do a lot of work when your process is sleeping |
12:31:43 | def- | epochTime is probably what you want |
12:44:18 | Arrrr | but im actually measuring the time it takes to sleep |
12:44:53 | Arrrr | I get sleep is not precise, but if i say "sleep for 1ms" how does it take up to 16ms ? |
12:45:14 | Arrrr | It cannot be the gc |
12:47:25 | * | Ven joined #nim |
12:51:09 | * | filcuc joined #nim |
12:53:13 | * | pregressive joined #nim |
12:56:56 | * | gokr quit (Quit: Leaving.) |
12:57:01 | * | gokr1 joined #nim |
13:08:32 | * | pregressive quit (Remote host closed the connection) |
13:08:53 | * | xet7 joined #nim |
13:11:48 | coffeepot | I think sleep only guarantees waiting for at least the parameter time, but doesn't guarantee it won't wait longer |
13:21:20 | * | irrequietus quit () |
13:27:27 | Arrrr | It must be that |
13:28:26 | * | zepolen quit (Remote host closed the connection) |
13:57:21 | * | irrequietus joined #nim |
14:00:38 | * | ozra joined #nim |
14:10:05 | * | Jehan_ joined #nim |
14:11:01 | Jehan_ | Arrrr: sleep can take longer than the minimum amount of time due to scheduling or other activity in the system. http://pubs.opengroup.org/onlinepubs/009695399/functions/sleep.html |
14:11:14 | * | girvo joined #nim |
14:11:20 | Jehan_ | System timers often don't have granularity that low. |
14:13:26 | * | BitPuffin joined #nim |
14:15:50 | * | girvo quit (Ping timeout: 260 seconds) |
14:26:09 | * | gokr1 quit (Quit: Leaving.) |
14:30:14 | * | irrequietus quit () |
14:37:51 | Arrrr | mmm i see |
14:45:03 | * | filcuc quit (Quit: Konversation terminated!) |
14:45:30 | * | Ven quit (Quit: My MacBook has gone to sleep. ZZZzzz…) |
14:49:00 | * | pregressive joined #nim |
14:50:33 | * | SeVenSiXseVeN quit (Quit: Leaving) |
14:53:44 | * | nicktick joined #nim |
15:10:59 | * | nastavnic quit (Ping timeout: 246 seconds) |
15:11:15 | coffeepot | if you've got an array[0..100, byte] as a buffer, what's the most convenient way to get a string out from the first, say 10 bytes? |
15:11:58 | * | nastavnic joined #nim |
15:12:08 | coffeepot | I was hoping for a toString or something, rather than have to do it manually |
15:14:12 | * | saml joined #nim |
15:15:46 | def- | coffeepot: var s = newString(10); copyMem(addr s[0], addr source[0], 10) |
15:16:18 | coffeepot | Nice one def- :) |
15:18:26 | * | Sornaensis quit (Excess Flood) |
15:18:50 | * | Sornaensis joined #nim |
15:22:18 | * | pregressive quit (Remote host closed the connection) |
15:27:17 | * | Ven joined #nim |
15:29:40 | * | Jehan_ quit (Quit: Leaving) |
15:39:54 | * | nicktick quit (Quit: Leaving.) |
15:40:09 | * | joelmo joined #nim |
15:40:25 | * | nicktick joined #nim |
15:43:01 | cryzed | I'm going to make people angry again: https://gist.github.com/cryzed/3a11d40be667d2444b7a so scenario A can never work? |
15:43:15 | cryzed | Using ref types for attributes in type definitions doesn't make sense? |
15:49:51 | cryzed | All actions that modify a referenced object will automatically copy the object, and simply change the pointer to point to the new object? |
15:55:30 | * | vqrs quit (Max SendQ exceeded) |
15:56:46 | * | vqrs joined #nim |
15:59:52 | coffeepot | uh thats... unexpected |
16:00:00 | coffeepot | for me anyway XD |
16:03:19 | * | nicktick1 joined #nim |
16:03:49 | coffeepot | if that's right altering the contents of a ref would invalidate a stored ref wouldn't it? But that doesn't happen AFAIK - refs are fine to reference |
16:05:52 | cryzed | coffeepot, you cant store redfs |
16:05:54 | cryzed | refs |
16:06:24 | * | nicktick quit (Ping timeout: 256 seconds) |
16:07:22 | coffeepot | I'm sure I've stored plenty of refs and modified them without issue though *confused* |
16:07:47 | coffeepot | is this something to do with the fact it's inherited? |
16:08:02 | coffeepot | doesn't look like it |
16:08:07 | cryzed | there's no inheritance |
16:08:11 | * | nicktick1 quit (Ping timeout: 250 seconds) |
16:08:13 | cryzed | in my example? |
16:08:22 | cryzed | just 2 different classes |
16:08:24 | cryzed | Node and RefNode |
16:08:26 | cryzed | or well types |
16:09:01 | coffeepot | yeah sorry i thought it was but no inheritance |
16:09:06 | coffeepot | odd |
16:09:18 | cryzed | It's what threw me off yesterday, and still does to be honest |
16:09:35 | * | nastavni1 joined #nim |
16:09:36 | coffeepot | well me too tbh |
16:09:48 | cryzed | I was told, if I didnt misunderstand, that its not possible to actually store references |
16:09:48 | coffeepot | I wonder if this is something to do with what repr displays |
16:09:59 | cryzed | repr displays the memory adresses and contents etc. |
16:10:00 | coffeepot | huh?! |
16:10:03 | cryzed | Pretty sure that is correct |
16:10:28 | * | OurRoyalGabe joined #nim |
16:10:31 | cryzed | I would have to ask Ara-q again, but I don't want to ping him. I annoyed him plenty yesterday |
16:10:33 | cryzed | maybe dom96 |
16:10:40 | * | OurRoyalGabe left #nim (#nim) |
16:11:02 | cryzed | coffeepot, do you know of a way to initialize the children attribute of refnode? |
16:11:16 | cryzed | since I can't figure it out |
16:11:58 | * | girvo joined #nim |
16:12:17 | cryzed | Welcome back girvo :) |
16:12:30 | * | nastavnic quit (Ping timeout: 272 seconds) |
16:12:35 | coffeepot | hmm well if it were a seq it'd just be myRefNode.children = @[] ... maybe myRefNode.children = newSeq[seq[string]]() or something? |
16:12:51 | coffeepot | no that doesn't look right XD |
16:13:25 | coffeepot | new newSeq[string]() ? |
16:13:36 | coffeepot | a seq is a ref anyway btw |
16:13:45 | coffeepot | AFAIK |
16:14:34 | cryzed | b:ref 00568048 --> [children = 00568058[]] |
16:14:35 | cryzed | doesnt look like it |
16:15:02 | * | nastavni1 quit (Ping timeout: 272 seconds) |
16:16:56 | * | girvo quit (Ping timeout: 272 seconds) |
16:18:14 | coffeepot | I hope someone can tell you why, will be keeping an eye on chat :) |
16:19:19 | cryzed | yeah me too |
16:21:19 | * | Ven quit (Quit: My MacBook has gone to sleep. ZZZzzz…) |
16:22:03 | Arrrr | what's the matter |
16:22:37 | coffeepot | Arrrr see cryzed code snippet above |
16:22:38 | dom96 | hello guys |
16:22:44 | coffeepot | hello :) |
16:22:46 | cryzed | hello dom96! |
16:22:53 | cryzed | I still can't leave it alone after all |
16:23:00 | cryzed | I need to fully understand how nim's memory management works |
16:23:09 | cryzed | I know I'm making enemies at this point |
16:23:25 | cryzed | Code sample: https://gist.github.com/cryzed/3a11d40be667d2444b7a |
16:23:36 | cryzed | <cryzed> Using ref types for attributes in type definitions doesn't make sense? |
16:23:36 | cryzed | <cryzed> All actions that modify a referenced object will automatically copy the object, and simply change the pointer to point to the new object? |
16:24:15 | coffeepot | cryzed I don't think you are making enemies for asking questions :) |
16:24:29 | cryzed | eh, let's hope -- I can be persistent |
16:25:01 | cryzed | a:ref 00598028 --> [children = nil] |
16:25:01 | cryzed | a:ref 00598028 --> [children = ref 00598038 --> nil] |
16:25:01 | cryzed | b:ref 00598048 --> [children = 00598058[]] |
16:25:01 | cryzed | b:ref 00598048 --> [children = 0059c368[0059c3c8"Hello World"]] |
16:25:05 | cryzed | a full sample output of the script |
16:25:23 | coffeepot | cryzed are you on devel? |
16:25:26 | cryzed | I am |
16:25:43 | cryzed | > git hash: 6f09282352341d750332592fa06988102992a276 |
16:26:18 | Arrrr | The issue is that repr is displaying a different dir when you add a new string? |
16:26:20 | * | nicktick joined #nim |
16:26:39 | dom96 | cryzed: I get consistent memory addresses |
16:26:45 | dom96 | I commented on your gist with my output |
16:27:20 | cryzed | dom96, your children address changed |
16:27:25 | cryzed | in b |
16:27:38 | cryzed | 24050 and 2c050 |
16:28:00 | cryzed | Arrrr, address |
16:28:20 | Arrrr | http://ideone.com/6F2wkR |
16:29:02 | cryzed | So when limiting it to a single element it works? |
16:29:08 | Arrrr | Seq is very strange, it is implemented at the compiler lever, it doesn't work like a value type or a ref type |
16:29:31 | dom96 | What I think happens is that the seq grows so it must reallocated |
16:29:32 | Arrrr | It has a lot of implementations details to make it perform better |
16:29:45 | cryzed | Arrrr, dom96 can either of you then tell me how to initialize a properly in my example? |
16:29:45 | coffeepot | dom96 that makes sense |
16:29:56 | cryzed | specifically a.children? |
16:30:01 | Arrrr | Initialized it with @[] |
16:30:05 | dom96 | what Arrrr did was explicitly specify how big the seq should be allocated. |
16:30:07 | Arrrr | *initialize |
16:30:08 | cryzed | that doesn't work |
16:30:14 | Arrrr | why not |
16:30:18 | cryzed | it expects a ref seq[string] not a seq[string] |
16:30:30 | cryzed | The docs say that new(a.children) should |
16:30:32 | cryzed | oops |
16:30:32 | coffeepot | it doesn't make sense that the 'container' ref should change if a ref within it does thou |
16:30:34 | dom96 | Stop using 'ref seq[string]' |
16:30:34 | cryzed | sandbox.nim(11, 29) Error: type mismatch: got (seq[empty]) but expected 'ref seq[string]' |
16:30:35 | Arrrr | Yesterday i gave you a snippet that does that |
16:30:39 | dom96 | just use 'seq[string]' |
16:30:54 | cryzed | So using ref in attributes doesn't make sense at all? |
16:30:54 | Arrrr | And if i were you, i would do what dom says |
16:31:07 | dom96 | it doesn't make sense on a seq |
16:31:18 | dom96 | because it is already a reference type |
16:31:22 | coffeepot | cryzed using ref should work in attributes but seq is effectively a ref anyway |
16:31:34 | cryzed | I see, alright. |
16:31:46 | dom96 | Writing 'ref int' also doesn't make much sense |
16:31:47 | Arrrr | There is a point on ussing a ref, if you want to reuse it instead of making a copy |
16:32:05 | coffeepot | ref int does make sense if you want to pass around a pointer to an int tho |
16:32:13 | dom96 | btw, have you guys seen this? http://adventofcode.com/ |
16:32:22 | dom96 | Looks like a good way to practice/learn Nim :) |
16:32:32 | cryzed | dom96, one last question then. Is new even needed, isn't new implicitly called when doing MyType()? |
16:32:37 | dom96 | (And other programming languages too) |
16:33:20 | coffeepot | cool link dom96 :) |
16:33:26 | dom96 | cryzed: Indeed, new is implicitly called when you call MyType() |
16:33:32 | dom96 | i.e. the type constructor |
16:33:52 | cryzed | Okay, since I see new being used in some code and I never get why, when the type cosntructor could just have been used |
16:34:09 | dom96 | The type constructor is a relatively new addition to Nim :) |
16:34:14 | coffeepot | so have we confirmed that when having ref object with a ref inside it, if you add to the child ref it does not change the parent ref address? |
16:34:25 | dom96 | Also, in some cases you may not want to specify each attribute. |
16:34:53 | Arrrr | It doesn't coffe, it is only how seq works |
16:35:00 | Arrrr | We have talked about it many times |
16:35:11 | Arrrr | The shallowcopy thing |
16:35:38 | cryzed | <cryzed> coffeepot, if it's a seq it apparently might be moved around in memory -- so the address might change, but it points to the same data exactly |
16:35:39 | cryzed | sorry got disconnected |
16:35:41 | coffeepot | good good, I thought that was a bit weird and surely would make refs unusable if it were true - you'd pass one over and it's address would be changed? That'd be mad |
16:36:17 | Arrrr | Well, seqs and strings |
16:36:29 | coffeepot | cryzed yeah this makes sense for seq as they're just dynamic arrays and need to be resized. It would be upsetting if it happened to a seq's container though |
16:37:05 | coffeepot | which is what your code snippet seemed to show |
16:37:08 | cryzed | coffeepot, ah not -- the reference to the seq itself -- relative to the object instance never changed |
16:38:01 | cryzed | dom96, so what problem did I have yesterday. I used a custom accessor proc to get the correct field, but it ended up returning a copy of that seq field instead of a reference to it |
16:38:07 | dom96 | https://gist.github.com/dom96/eb7ed68cbca07175bafc |
16:38:49 | cryzed | ah neat |
16:39:13 | coffeepot | great :) So what happened in cryzed's snippet for the container ref to change? |
16:39:39 | cryzed | coffeepot, http://i.imgur.com/7bu7P0C.png |
16:39:44 | cryzed | the ref didnt change to the container |
16:39:54 | cryzed | it stayed constant for a and b |
16:40:42 | coffeepot | that's ok then, sanity restored :) |
16:41:38 | cryzed | It is. So now I am trying to recreate my actual problem from yesterday in a small code sample |
16:41:51 | cryzed | (told you, I'd make enemies :P) |
16:43:32 | * | pregressive joined #nim |
16:50:21 | * | nicktick quit (Quit: Leaving.) |
16:53:49 | cryzed | coffeepot, https://gist.github.com/cryzed/5acdc21d1560b8a99d62 |
16:53:53 | cryzed | this is what threw me off yesterday |
16:54:18 | cryzed | dom96, I understood correctly regarding this: https://gist.github.com/cryzed/5acdc21d1560b8a99d62 -- that there's absolutely no way without using ptr or templates to do what I am trying to do? Sorry if I'm annoying you |
16:55:36 | dom96 | cryzed: I'm always happy to help :) |
16:55:46 | cryzed | glad to hear that :) |
16:55:59 | cryzed | The comments explain my thinking hopefully exactly |
16:56:05 | cryzed | from Python I'm used to just work with references |
16:56:10 | cryzed | so this still throws me off a bit |
16:56:33 | cryzed | but yes, the docs say "the assignment operator copies the value" |
16:56:40 | cryzed | or something like that, I remember reading that |
16:56:57 | cryzed | I just don't understand what difference it makes to specify "var" in the children return type or not |
16:58:06 | coffeepot | specifying a var return type means you're returning a mutable value |
16:58:54 | coffeepot | ie; var returns the actual "pointer" to the item so it can be edited |
16:59:03 | NimBot | nim-lang/Nim devel f3d5782 xiongxin [+0 ±1 -0]: 7 div 5 == 1... 2 more lines |
16:59:03 | NimBot | nim-lang/Nim devel ca47256 Dennis Felsing [+0 ±1 -0]: Merge pull request #3627 from xiongxin/devel... 2 more lines |
16:59:31 | coffeepot | otherwise you'd get a copy |
16:59:54 | cryzed | coffeepot, well that doesn't work in the example |
17:00:14 | cryzed | coffeepot, I am attempting to return the correct field -- or a pointer/reference to it |
17:00:23 | cryzed | but I get a copy -- or well maybe I don't |
17:00:36 | cryzed | I assign it to a variable in between so I don't have to execute the proc twice to do something like this |
17:00:46 | cryzed | node.children.delete(node.children.high) |
17:00:52 | cryzed | -- this would execute my custom children proc twice |
17:00:57 | cryzed | I can't do |
17:01:11 | cryzed | var childrenRef = node.children |
17:01:16 | cryzed | childrenRef.delete(childrenRef.high) |
17:01:27 | cryzed | because as soon as the assignment happens the value gets copied, even if it's a var return type |
17:02:22 | dom96 | let me see if I can come up with something |
17:02:48 | cryzed | dom96, alright -- thank you |
17:03:09 | cryzed | https://gist.github.com/cryzed/cc42a92ab57a8c140a5c for reference this works |
17:03:14 | cryzed | and probably really has negligible overhead |
17:03:16 | cryzed | I'm just being silly |
17:03:40 | cryzed | I'm just used being able to store references, and I don't get why I can't. It has to do with memory-safety Ara-q said, but how does it affect memory safety? |
17:04:26 | coffeepot | you definitely can store references, he must have been talking about something specific |
17:04:37 | cryzed | coffeepot, check the example |
17:04:38 | cryzed | execute it |
17:04:53 | cryzed | the var referenceToChildren is a _copy_ after the assignment |
17:04:59 | cryzed | it does not point to the original object's field |
17:05:10 | cryzed | you can modify it, but the object itself does not get modified -- or rather its children attribute |
17:05:25 | coffeepot | yeah it's unexpected |
17:05:41 | cryzed | coffeepot, https://gist.github.com/cryzed/cc42a92ab57a8c140a5c with adjusted output |
17:06:02 | coffeepot | unfortunately I must exit stage left for it is the time of going home! |
17:06:10 | coffeepot | good luck, hopefully there's an easy solution :) |
17:06:16 | cryzed | coffeepot, see you! |
17:06:19 | coffeepot | see ya! |
17:06:23 | cryzed | I almost wish Nim could be changed for this to work haha |
17:06:24 | * | coffeepot quit (Quit: http://www.kiwiirc.com/ - A hand crafted IRC client) |
17:06:36 | cryzed | but there's probably a good reason for it |
17:08:49 | cryzed | dom96, if I understood the reasoning behind it I would probably stop nitpicking at this. Do you understand/know/can explain to me, why the assignment operator always automatically creates a copy -- even of mutably returned data structures from procs (i.e. marked as var)? |
17:09:27 | dom96 | I'm afraid I don't |
17:09:33 | dom96 | All I can do is guess |
17:10:29 | cryzed | dom96, please share your guesses |
17:13:29 | * | yglukhov quit (Ping timeout: 246 seconds) |
17:23:12 | cryzed | I'm almost tempted to create an issue with this snippet on the nim repo: https://gist.github.com/cryzed/cc42a92ab57a8c140a5c |
17:28:05 | cryzed | dom96, would this be a terribly bad idea? I feel many people will run into this issue at some point |
17:28:38 | cryzed | dom96, the docs say "assignment operator will copy the value" -- but since var should just return a _reference_ -- only the reference should be copied, not the value pointed to by the reference |
17:36:40 | dom96 | sorry, got distracted by this weird automated phone call I got. |
17:37:45 | ldlework | Sir, we have detected that you have a virus on your windows desktop. |
17:37:50 | ldlework | Are you the administrator of this computer? |
17:38:03 | ldlework | Sir, I ask you, are you the administrator of this computer? |
17:40:04 | cryzed | dom96, :D no prob. Regarding my question? |
17:40:22 | cryzed | don't you think it should work that way too? |
17:41:00 | dom96 | I'm not sure |
17:42:20 | dom96 | That being said, this works: https://gist.github.com/dom96/1984a7a196dddd658c2f |
17:44:30 | cryzed | that looks good, and basically what I had attempted yesterday. I still feel that when returning a result of a proc marked as var, it shouldnt just copy the returned datastructure during assignment |
17:44:33 | cryzed | why even return it as var then |
17:44:38 | cryzed | in that case at least |
17:44:56 | * | pregressive quit (Remote host closed the connection) |
17:45:12 | * | pregressive joined #nim |
17:45:15 | dom96 | If you feel that way then by all means create an issue |
17:46:29 | cryzed | dom96, you don't? |
17:47:25 | cryzed | dom96, also is it possible to do what your newNode proc does in a single line with the type constructor? I am wondering how to combine the new(result.internalChildren), result.internalChildren[] = @[] step |
17:47:51 | dom96 | cryzed: I would need to think about it more ;) |
17:48:03 | cryzed | Alright, I'll at least create an issue with the code snippet then |
17:48:09 | dom96 | I don't think you can combine those |
17:49:27 | * | pregressive quit (Remote host closed the connection) |
17:49:48 | cryzed | dom96, ah I see |
17:59:34 | * | vendethiel joined #nim |
18:00:02 | * | aziz joined #nim |
18:01:46 | cryzed | dom96, https://github.com/nim-lang/Nim/issues/3628 |
18:02:13 | * | yglukhov joined #nim |
18:06:26 | * | yglukhov quit (Ping timeout: 240 seconds) |
18:09:36 | cryzed | dom96, https://github.com/nim-lang/Nim/issues/3629 I wonder how ling it will take before Ara-q kills me :D |
18:11:37 | dom96 | cryzed: Depends how far away from him you live :P |
18:12:36 | cryzed | Germany |
18:12:39 | cryzed | wait. |
18:12:41 | cryzed | Andreas Rumpf sounds german |
18:12:45 | * | girvo joined #nim |
18:13:08 | cryzed | \o/ ~ |
18:17:18 | * | girvo quit (Ping timeout: 256 seconds) |
18:21:11 | Araq | if you want to create a 'var T' accessor there is no accessor abstraction possible, so I don't know why it's such a big deal for you tbh |
18:21:36 | Araq | the reasonable man would mark the field with an * and call it day. |
18:22:04 | Araq | and would have done so two days ago. |
18:22:13 | Araq | ;-) |
18:22:52 | * | yglukhov joined #nim |
18:24:00 | Araq | and 'var T' is not a first class citizen in the language. you cannot have a 'var T' in an object. |
18:24:34 | Araq | Nim is not like C++ in this respect. |
18:25:53 | Araq | you can do var x = addr thingReturningVar() to preserve the pointer |
18:27:03 | * | cyraxjoe_ joined #nim |
18:27:20 | * | cyraxjoe quit (Ping timeout: 246 seconds) |
18:27:22 | Araq | that precious pointer that allows both to read and write with its changes propagated to the underlying data structure. which is as far away from an "accessor" as it can get. |
18:31:18 | cryzed | Araq, <Araq> the reasonable man would mark the field with an * and call it day. what do you mean by that? |
18:32:04 | cryzed | Araq, and you discouraged me from working with pointers IIRC |
18:32:53 | * | FreeDog is now known as LibreWulf |
18:33:24 | Araq | I mean instead of 'children: seq...' and an accessor proc for it |
18:33:36 | Araq | you use 'children*: seq...' |
18:33:46 | Araq | and don't have an accessor proc. |
18:34:02 | Araq | as far as I followed the discussion this seems to solve all your problems |
18:34:15 | cryzed | Araq, I would have done that -- if I didn't have this issue too: https://github.com/nim-lang/Nim/issues/3629 |
18:35:29 | cryzed | Araq, as in I want nodes with no children and nodes with children -- but not nodes with simply nil-initialized children |
18:35:38 | * | pregressive joined #nim |
18:35:47 | cryzed | but I can't create the correct type variant for that, because I get a redefinition error |
18:35:54 | Araq | yeah and then you move out the 'children' outside the 'case'. |
18:36:06 | cryzed | > as in I want nodes with no children and nodes with children -- but not nodes with simply nil-initialized children |
18:37:01 | Araq | yeah but that's just not possible right now, sorry. |
18:37:13 | Araq | we can make the compiler support that eventually. |
18:37:18 | cryzed | Awesome :) |
18:37:28 | Araq | but then in the implementation the compiler will move the field outside the 'case'. |
18:37:44 | cryzed | So there will be no difference? |
18:38:27 | Araq | there will be a difference in that it will work as you would expect |
18:38:57 | cryzed | ah alright, I simply don't understand what you said then |
18:38:58 | Araq | but for the memory layouts and offsets etc it won't make any difference |
18:39:02 | cryzed | ah I see |
18:40:14 | Araq | that said, that 'children' is always accessable will turn out to be pretty useful, IME |
18:40:32 | * | LibreWulf quit (Remote host closed the connection) |
18:40:36 | Araq | so you can write generic recursion without checking 'if isAtom n' |
18:40:49 | Araq | since 'len' can deal with 'nil' seqs |
18:41:09 | Araq | so you can write a treee walker like so: |
18:41:19 | Araq | proc walk(n: Node) = |
18:41:29 | Araq | for i in 0..<n.len: |
18:41:43 | Araq | walk(n.children[i]) |
18:41:47 | * | LibreWulf joined #nim |
18:41:51 | * | LibreWulf quit (Remote host closed the connection) |
18:42:35 | * | LibreWulf joined #nim |
18:45:20 | cryzed | Araq, you might be right, that might simplify the code |
18:45:58 | cryzed | Araq, however can you explain to me why "var T" are not first citizen of the language? |
18:46:05 | cryzed | first-class |
18:46:45 | Araq | the language tries hard (and fails btw) to ensure memory safety for 'var T'. |
18:47:25 | cryzed | memory safety meaning that you never accidentally try to access an invalid memory address? |
18:47:35 | Araq | yes, pretty much |
18:47:48 | Araq | because 'ptr' is the unsafe pointer already. |
18:48:03 | Araq | and 'var' is usually more convenient to use. |
18:48:14 | Araq | so 'var' should be convenient and *safe*. |
18:48:33 | Araq | and so we have all kinds of restrictions for 'var'. |
18:49:41 | Araq | C# does the same with its 'out' modifier. |
18:49:56 | cryzed | Do you think you can explain to me in which scenarios storing "var T" and accessing it might blow up in my face? Because if I store "var T" the GC should never try to delete the object in memory? |
18:50:29 | Araq | but even ignoring safety you cannot convince me that 'var x = foo(); x = 3 # updates the data structure!' is good code. |
18:51:18 | cryzed | That's not what I'm doing though, I am getting a var-return value for an object. I would have expected for Integer types to work differently |
18:52:05 | Araq | why are ints special? Nim is not Java with its split between primitives and classes. |
18:52:54 | cryzed | Araq, I see. Sorry, I just need to get used to this different behavior that Python and other languages have ingrained in me |
18:54:32 | cryzed | So for the record: 1) have a children attribute for each Nodetype, and use the .field accessor which allows me to actually modify the reference I want to modify. Use a field for selected nodetypes, once that feature is implemented, and use conditional to access the field depending on type. Or use addr and dereference the pointer to access the field |
18:55:58 | cryzed | Araq, is that about right -- did I miss anything? I just have a big interest in understanding exactly how nims work internally -- at least regarding the features I'm regularly exposed to as the end-user. |
18:57:37 | Araq | well you start with (1) and there is no (2) and I'm not sure I understand your summary. |
18:58:01 | cryzed | :D |
18:58:03 | cryzed | You are right |
18:58:32 | Araq | you should have 'children*: seq...' in your object outside the 'case' and mark it with 'XXX move it into case once Nim supports that' |
18:58:39 | cryzed | 1) Create a children field for each of my nodes, even if they don't need one. This allows me to do nodeInstance.children... and actually modify the reference I want to modify without having to store the reference in between and calling a custom children accessor proc in between |
18:59:12 | cryzed | 2) Continue what I'm doing now, and use the custom children accessor proc, but store the address of the returned field as a pointer instead, and dereference it when needed |
18:59:33 | cryzed | 3) Do 1 basically just with the assumption that not all variant types have the children field |
19:00:07 | cryzed | So 1) and 3) |
19:00:39 | cryzed | then again, as you said, actually doing 3) would complicate the code at points |
19:00:43 | cryzed | but make it more logical |
19:01:26 | cryzed | Araq, thanks for your patience |
19:01:26 | * | nastavni1 joined #nim |
19:04:12 | * | darkf quit (Quit: Leaving) |
19:04:41 | * | nastavni1 quit (Client Quit) |
19:06:08 | * | nastavnic joined #nim |
19:11:12 | Araq | you're welcome |
19:36:53 | * | desophos joined #nim |
19:40:29 | * | BaronFumble joined #nim |
19:40:57 | * | pilne joined #nim |
19:41:08 | * | Gonzih joined #nim |
19:41:29 | * | BaronFumble left #nim (#nim) |
19:41:48 | * | Matthias247 joined #nim |
19:54:44 | * | gunn quit (Ping timeout: 245 seconds) |
19:58:40 | * | gunn joined #nim |
19:59:25 | * | makoLine joined #nim |
20:03:20 | * | boopsiesisaway is now known as boopsies |
20:03:55 | * | Arrrr left #nim ("WeeChat 1.2") |
20:13:29 | * | girvo joined #nim |
20:18:14 | * | girvo quit (Ping timeout: 272 seconds) |
20:26:34 | * | mat4 joined #nim |
20:26:36 | mat4 | hi all |
20:26:38 | * | yglukhov quit (Remote host closed the connection) |
20:34:20 | * | BitPuffin quit (Ping timeout: 245 seconds) |
20:35:12 | * | Demon_Fox joined #nim |
20:44:44 | cryzed | hello |
20:58:14 | * | Gonzih quit (Ping timeout: 256 seconds) |
21:18:24 | * | ozra quit (Ping timeout: 252 seconds) |
21:28:24 | * | Gonzih joined #nim |
21:29:31 | * | ozra joined #nim |
21:38:12 | * | bjz_ quit (Read error: Connection reset by peer) |
21:43:55 | * | bjz joined #nim |
21:48:19 | * | bjz quit (Ping timeout: 253 seconds) |
21:52:34 | * | bjz joined #nim |
21:54:19 | * | zepolen joined #nim |
21:57:10 | * | bjz quit (Ping timeout: 256 seconds) |
22:04:31 | * | mat4 quit (Quit: Leaving) |
22:14:19 | * | girvo joined #nim |
22:18:41 | * | girvo quit (Ping timeout: 250 seconds) |
22:26:55 | * | Gonzih quit (Ping timeout: 250 seconds) |
22:35:46 | * | nastavnic quit (Ping timeout: 240 seconds) |
22:44:17 | * | makoLine quit (Read error: Connection reset by peer) |
22:48:43 | * | BitPuffin|osx joined #nim |
22:49:01 | * | vendethiel quit (Ping timeout: 250 seconds) |
23:00:38 | * | boopsies is now known as boopsiesisaway |
23:01:19 | * | makoLine joined #nim |
23:07:02 | * | ephja joined #nim |
23:09:49 | * | solidsnack joined #nim |
23:09:58 | * | pregressive quit (Remote host closed the connection) |
23:10:14 | * | pregressive joined #nim |
23:10:20 | * | pregressive quit (Remote host closed the connection) |
23:11:32 | * | desophos quit (Remote host closed the connection) |
23:15:39 | ephja | how do I make this https://github.com/ephja/nim-glfw/blob/master/src/glfw.nim#L271 work now? failIf is defined here: https://github.com/ephja/nim-glfw/blob/master/src/glfw.nim#L242 |
23:16:02 | ephja | must all those statements be rewritten? |
23:22:06 | ephja | I should take another approach though |
23:24:59 | * | zepolen quit (Remote host closed the connection) |
23:33:07 | * | nastavnic joined #nim |
23:34:33 | * | cyraxjoe_ is now known as cyraxjoe |
23:38:25 | * | nastavnic quit (Ping timeout: 250 seconds) |