<< 16-08-2022 >>

01:14:43FromDiscord<creikey> In reply to @dom96 "You’re honestly better off": I tested this attack with a cloudflare websockets proxied server https://github.com/treeform/ws/issues/42 and cloudflare did not stop the server from receiving the packet, causing the VPS to allocate gigabytes of memory and stall
01:21:19*PMunch quit (Ping timeout: 268 seconds)
01:22:29FromDiscord<Elegantbeef> > You’re honestly better off just not using the internet and moving into the woods↵FTFY
01:25:00FromDiscord<creikey> In reply to @Elegantbeef "> You’re honestly better": to be honest
01:25:22FromDiscord<!Patitotective> beef says that because he lives with bears
01:25:29FromDiscord<creikey> I'm sad that deepbeef is on hold the bot will not be invited
01:25:40FromDiscord<creikey> the only other option is to like use the discord client and scrape it like that
01:25:43FromDiscord<creikey> probably would take forever
01:37:26FromDiscord<Elegantbeef> Alternatively put all that effort into something worthwhile
01:37:42FromDiscord<Elegantbeef> Making an AI replicate a jackass isnt something worth anyone's time
01:39:06FromDiscord<SrMordred> sent a code paste, see https://play.nim-lang.org/#ix=47Jg
01:39:17FromDiscord<Elegantbeef> It's an unsafe pointer o the first element
01:39:19FromDiscord<Elegantbeef> to\
01:39:39FromDiscord<Elegantbeef> So if the pointer outlives `text` you'll have issues, but most APIs luckily dont hold onto cstrings
01:40:11FromDiscord<SrMordred> oh wait, nim strings are null terminated?
01:40:19FromDiscord<Elegantbeef> Most languages that use pascal strings actually internally make cstrings, so you can for free get a safe temporary C string
01:40:45FromDiscord<Elegantbeef> It's a single extra byte that ensures free C interop
01:41:28FromDiscord<!Patitotective> In reply to @Elegantbeef "So if the pointer": ~~imgui when~~
01:41:32FromDiscord<SrMordred> ahhh, nice. i thought that cstring created a string. ↵that´s better tbh 🙂 (at least when interoping with c)
01:41:40FromDiscord<Elegantbeef> Yep
01:41:56FromDiscord<Elegantbeef> The only downside is if the API dumbly takes ownership of that cstring
01:42:44FromDiscord<Elegantbeef> In that case you'd have to hold onto string and make it outlive the library
01:42:51FromDiscord<SrMordred> then i would need to make sure that the original string are alive somewhere
01:42:53FromDiscord<Elegantbeef> Libraries that do that are far and few inbetween though
01:43:05FromDiscord<SrMordred> yeah, normally are copied or used on the moment
01:43:17FromDiscord<Elegantbeef> Exactly
01:43:42FromDiscord<Elegantbeef> I know imgui as patito mentioned has an API that takes a `cstring` but expects it to be allocated with their allocator, so you can accidentally pass the wrong 'type'
01:44:32FromDiscord<Elegantbeef> Given that i've been toying with a statically typed custom allocated type C's type system is a joke 😛
01:44:51FromDiscord<SrMordred> coincidentally, i'm making a ui system on top of raylib for my needs ;p
01:45:33FromDiscord<Elegantbeef> Hopefully it can be a nice retained declarative UI
01:45:39FromDiscord<Elegantbeef> That's clearly the bes
01:45:41FromDiscord<Elegantbeef> best\
01:46:40FromDiscord<!Patitotective> In reply to @Elegantbeef "Hopefully it can be": i havent started the imgui declarative wrapper yet 💀 💀 ↵ill insipirate from owlkettle
01:47:17FromDiscord<!Patitotective> btw owlkettle's author uploaded a video about it https://www.youtube.com/watch?v=O44x_la1o_M :p
01:47:37FromDiscord<Elegantbeef> Nifty
01:48:36FromDiscord<Elegantbeef> Wow no inspiration from my GUI
01:49:12FromDiscord<!Patitotective> which
01:49:26FromDiscord<!Patitotective> oh i remember
01:49:32FromDiscord<Elegantbeef> https://github.com/beef331/truss3d/blob/master/examples/guitest.nim#L22-L141
01:49:56FromDiscord<SrMordred> sent a code paste, see https://play.nim-lang.org/#ix=47Jh
01:50:00FromDiscord<Elegantbeef> Oh god i hate it
01:50:01FromDiscord<SrMordred> https://media.discordapp.net/attachments/371759389889003532/1008915503009505290/unknown.png
01:50:12FromDiscord<!Patitotective> In reply to @Elegantbeef "https://github.com/beef331/truss3d/blob/master/exam": hmmmmmmmmmmmmmm perhaps
01:50:23FromDiscord<!Patitotective> In reply to @SrMordred "i have some ideias,": please no
01:50:36FromDiscord<Elegantbeef> Builder pattern i guess works, but i really dislike it
01:53:21FromDiscord<!Patitotective> i liked the appstate owlkettle thing, rather than global vars 💀
01:53:24FromDiscord<SrMordred> i tested all the ui libs out there and i always hit something simple that are made hard because the ui make a lot of things already for u. ↵but im my case i want something more simple, but want control to put the things on the pixel that i want. ↵for now its been nice to be able to put a centralized text with no effort
01:53:34FromDiscord<Elegantbeef> What global variables?↵(@!Patitotective)
01:53:43FromDiscord<!Patitotective> In reply to @SrMordred "i tested all the": ~~imgu-~~
01:53:48FromDiscord<!Patitotective> In reply to @Elegantbeef "What global variables? (<@762008715162419261>)": `btns`
01:54:07FromDiscord<Elegantbeef> That's for the test, just like owlkettle you'd cache those on an object
01:54:11FromDiscord<!Patitotective> sent a code paste, see https://play.nim-lang.org/#ix=47Ji
01:54:35FromDiscord<Elegantbeef> For my game i have a `editorGui: seq[UIElement]` for the world editor
01:54:47FromDiscord<Elegantbeef> They're both retained GUI so... they're identical
01:55:04FromDiscord<SrMordred> imgui dont fit my needs. nor raygui, nor egui nor none xD
01:55:32FromDiscord<Elegantbeef> Remember patito my GUI is for games not for programs
01:55:41FromDiscord<Elegantbeef> So there isnt a place to just inject render/update calls
01:55:56FromDiscord<Elegantbeef> Owlkettle handles the entire program loop
01:56:05FromDiscord<!Patitotective> hMmMm
01:57:29FromDiscord<Elegantbeef> And with that stream of defensiveness... 😄
01:57:40FromDiscord<!Patitotective> should my declarative wrapper only draw things and not manage the actual app? so you can do your custom thing or maybe letting you change the default managing
01:57:54FromDiscord<Elegantbeef> That's between you and your god
01:59:45FromDiscord<!Patitotective> sent a code paste, see https://play.nim-lang.org/#ix=47Jj
01:59:50FromDiscord<!Patitotective> (edit)
02:02:30FromDiscord<!Patitotective> sent a code paste, see https://play.nim-lang.org/#ix=47Jm
02:02:37FromDiscord<Elegantbeef> What about what?
02:03:57FromDiscord<Elegantbeef> I mean you can do whatever you want patito, for my macro it's easier to not specialise procedures
02:04:00FromDiscord<Elegantbeef> It's like 30 loc
02:07:47FromDiscord<!Patitotective> hMmmM ok
02:09:37FromDiscord<Elegantbeef> For context pat, it's a very braindead simple macro https://github.com/beef331/truss3d/blob/master/src/truss3D/gui.nim#L96-L124
02:10:13FromDiscord<Elegantbeef> And really that `gotPos` is redundant and i should just make `pos` optional
02:11:32FromDiscord<Elegantbeef> I also really should replace all usages of vmath with a concept
02:15:34FromDiscord<SrMordred> i need to experiment with nim asts again. ↵got a little traumatised after rust macros.
02:16:22FromDiscord<Elegantbeef> I like Nim's macros, there are tedious thing with the typed AST, but it's generally a good experience
02:16:44FromDiscord<Elegantbeef> I did start wrapping the API to make writing macros a bit more ergonomic https://github.com/beef331/micros/
02:17:43FromDiscord<SrMordred> oh looks pretty nice at first glance
02:19:17FromDiscord<voidwalker> Any chance I'd get help for nimx here ? I want to draw images (https://github.com/yglukhov/nimx/blob/master/test/sample03_image.nim) as elements in a collection view (https://github.com/yglukhov/nimx/blob/master/test/sample07_collections.nim) so they get arranged automatically on window resize, like the netflix grid or something like that
02:19:36FromDiscord<voidwalker> And have them be clickable
02:19:48FromDiscord<Elegantbeef> It doesnt cover the entire AST presently, but yea it makes it more like using accessors and less like navigating AST manually
02:20:03*jmdaemon joined #nim
02:20:18*jmd_ quit (Ping timeout: 248 seconds)
02:22:39FromDiscord<Elegantbeef> I'd imagine you make your own view that on draw iterates all elements to draw and organises them into a grid
02:23:04FromDiscord<Elegantbeef> I've never used nimx so i dont know how to do anything with it
02:28:20FromDiscord<!Patitotective> In reply to @voidwalker "And have them be": not sure how nimx works but you could check if the mouse is clicked and an image is hovered
02:28:22FromDiscord<voidwalker> I wanted them to be collections, since the collection elements already can be autoarranged with their properties
02:28:57FromDiscord<voidwalker> Otherwise I'd have to find some algorithms for arranging items into a grid, depending on window sizes and such.. ugh
02:30:44FromDiscord<!Patitotective> In reply to @voidwalker "Otherwise I'd have to": you just have to know each element's size and divide it by the window size
02:30:47FromDiscord<!Patitotective> not so hard
02:31:56FromDiscord<Elegantbeef> SO why cant you just use a collection?
02:34:42FromDiscord<voidwalker> I don't know how to draw on the collection "Rect"s
02:34:58FromDiscord<voidwalker> In the sample code they are generated like this:
02:35:16FromDiscord<voidwalker> sent a code paste, see https://play.nim-lang.org/#ix=47Jr
02:35:25FromDiscord<Elegantbeef> You'd just use an image instead of `newView` i'd believe
02:35:33FromDiscord<voidwalker> (edit) "https://play.nim-lang.org/#ix=47Jr" => "https://play.nim-lang.org/#ix=47Js"
02:36:15FromDiscord<voidwalker> The drawimage proc works like this:
02:36:25FromDiscord<voidwalker> https://media.discordapp.net/attachments/371759389889003532/1008927180849434725/unknown.png
02:37:14FromDiscord<voidwalker> but newRect looks like an anonymous Rect, to try and specify the toRect parameter
02:39:50FromDiscord<Elegantbeef> ImageSampleView is a view
02:40:10FromDiscord<Elegantbeef> So you'd setup the image then add it
02:41:20FromDiscord<voidwalker> Yeah I already figured out how to add the images in the sample code for ImageSampleView
02:41:44FromDiscord<voidwalker> But this whole concept of views and rects, I do not yet understand how they piece together
02:42:43FromDiscord<Elegantbeef> Yea me either i never grasp these types of APIs properly
02:58:36*arkurious quit (Quit: Leaving)
03:19:40*jmd_ joined #nim
03:20:17*jmdaemon quit (Ping timeout: 252 seconds)
03:20:51FromDiscord<flaorabtc> https://t.me/+sj30hB-ZyA03Nzg0I'll 20 people on how to earn $10,000 or more in just 3day's from the crypto market.but you will pay me 10% commission when you receive your profit. if interested send me a direct message, for more information... Contact via📩📩📩📩📩📩📩📩TELEGRAM💬@@FLORAGORDONhttps://t.me/+sj30hB-ZyA03Nzg0
03:21:25FromDiscord<SaAnd> @Moderator
03:30:22FromDiscord<!Patitotective> <@&371760044473319454>
03:30:42FromDiscord<Girvo> Dumb question; I have an enum, ish. basically a set of uint16's that have meaning. `msgNoop` = 0, `msgSync` = 1, and so on. But we do not have every single `uint16` defined. We receive a uint16 over the network, and I'm currently casting it, to work out what it is and use it, but that obviously is unsafe and would break if it's a number thats not defined in the enum yet. I'm sure there is a better cleaner approach, so figured I'd ask
03:31:58FromDiscord<Elegantbeef> `type Message = distinct uint16`?
03:32:00FromDiscord<!Patitotective> if your enum does not have holes in it you can check if the number you receive is in `0..YourEnum.high` and if not you know it is not valid
03:32:27FromDiscord<Elegantbeef> If it's not contiguous it's fun
03:32:30FromDiscord<Girvo> Perfect
03:32:33FromDiscord<Girvo> In our case it is 🙂
03:32:44FromDiscord<Girvo> `.high` is exactly what I was chasing haha
03:35:16FromDiscord<Elegantbeef> Also please tell me you were not doing `cast[MyEnum](val)` 😛
03:35:51FromDiscord<Girvo> So what I did was I thought "what would cause beef the most pain to see" and did that 😄
03:36:04FromDiscord<Elegantbeef> You can just do `MyEnum(myValue)`
03:36:28FromDiscord<Girvo> (I know I'm just messing with ya haha)
03:41:21FromDiscord<Girvo> Is it possible to ask the system to drop it's buffered data in a socket on the floor? I know I can check `socket.hasBufferedData` but I'm not sure what to do with it if it is true, and I've received a tag (and length and message) that I don't want to care about
03:41:46FromDiscord<Girvo> Sorry, `hasDataBuffered`
03:42:22FromDiscord<Elegantbeef> If you dont need buffered data you can create the socket unbuffered
03:42:40FromDiscord<Elegantbeef> Otherwise i dont imagine you can
03:42:56FromDiscord<Girvo> Okay, fair enough. Short of closing/reopening the socket
03:44:02FromDiscord<Girvo> Theres no way of asking the socket how much data it has buffered, is there?
03:44:22FromDiscord<Elegantbeef> I do not know, dont imagine so
03:44:30FromDiscord<Girvo> Yeah I can't see anything in `std/net` at least
04:09:00FromDiscord<Girvo> sent a code paste, see https://play.nim-lang.org/#ix=47JC
04:11:17FromDiscord<Girvo> sent a code paste, see https://play.nim-lang.org/#ix=47JD
04:14:41FromDiscord<Girvo> sent a code paste, see https://play.nim-lang.org/#ix=47JF
04:15:19FromDiscord<!Patitotective> (you can do `2u16` btw)
04:15:28FromDiscord<Girvo> Oh shit haha thats nicer 😄 appreciate it
04:19:56FromDiscord<Elegantbeef> Are you using `copyMem` for the getting types or doing `cast[ptr T](a[ind].addr)[]`?
04:23:40FromDiscord<Girvo> The latter at the moment
04:23:48FromDiscord<Girvo> Well, technically both
04:23:52FromDiscord<treeform> sent a code paste, see https://play.nim-lang.org/#ix=47JH
04:23:59FromDiscord<treeform> `addr buffer` takes address of the string structure not the data
04:25:16FromDiscord<treeform> and its `newSeq`
04:25:21FromDiscord<treeform> it it should have bytes in it to send
04:28:27FromDiscord<Girvo> sent a code paste, see https://play.nim-lang.org/#ix=47JI
04:28:37FromDiscord<Elegantbeef> `newSeq[byte](4)`
04:28:38FromDiscord<Girvo> So I must've missed something haha
04:28:44FromDiscord<Girvo> Ah yeah it needs a size
04:28:45FromDiscord<treeform> "it it should have bytes in it to recv"
04:28:51FromDiscord<Girvo> ^ I'm with you
04:29:14FromDiscord<treeform> it might be simpler to ↵`buffer = socket.recv(4)`
04:30:00FromDiscord<treeform> that is what i do: https://github.com/treeform/ws/blob/master/src/ws.nim#L332
04:30:19FromDiscord<Elegantbeef> That does allocate a new string though
04:30:41FromDiscord<Elegantbeef> Girvo is embedded that's a nono
04:31:28FromDiscord<treeform> if that's the case yeah
04:33:15FromDiscord<treeform> but arc ref counting would take care the string even in embedded
04:33:30FromDiscord<Elegantbeef> yea but you're allocating
04:40:02NimEventerNew Nimble package! imnotify - A notifications library for Dear ImGui, see https://github.com/Patitotective/ImNotify
04:49:27FromDiscord<Ras> In reply to @Girvo "Man I am doing": what is this for btw
04:49:43FromDiscord<Ras> seems an awful lot like something I've been working on for the last few days
04:53:24FromDiscord<Girvo> hah its a TLV-based TCP message system for communicating to an embedded microcontroller
04:53:57FromDiscord<Ras> ahhh, okay
04:54:35FromDiscord<Ras> not related to my thing in any way then :p
04:57:43FromDiscord<Ras> @dom96 y'all were talking about sqlite the other day, this was just posted on HN, seems relevant to your discussion
04:57:45FromDiscord<Ras> https://antonz.org/sqlite-is-not-a-toy-database/
05:03:54FromDiscord<Phil> sent a long message, see http://ix.io/47JL
05:13:40FromDiscord<Girvo> Everyone always says "but I _will_ be write heavy" despite them building Yet Another Blog System where they post once a month at best lol
05:17:00FromDiscord<Girvo> sent a code paste, see https://paste.rs/nXH
05:17:15FromDiscord<Girvo> Ignore the double `and` just a typo copying it over
05:17:19FromDiscord<Elegantbeef> `(buf[1].uint16 shl 8)`
05:17:37FromDiscord<Girvo> (edit) "https://play.nim-lang.org/#ix=47JO" => "https://play.nim-lang.org/#ix=47JN"
05:17:45FromDiscord<Elegantbeef> also should be `or` no?
05:18:02FromDiscord<Elegantbeef> `and` would only keep the same bits
05:18:53FromDiscord<Rika> This is why you use the dedicated stuff in bitops
05:19:10FromDiscord<Girvo> Yeah Rika I'm about 2 seconds away from doing exactly that lol
05:19:24FromDiscord<Girvo> I was just trying to make sure I understood what it was actually doing
05:19:31FromDiscord<Rika> I’ll always be here to scold you for not using it 😉
05:19:59*rockcavera quit (Remote host closed the connection)
05:20:00FromDiscord<Girvo> sent a code paste, see https://play.nim-lang.org/#ix=47JP
05:20:01FromDiscord<Girvo> Yeah works 😄 cheers beef haha
05:20:19FromDiscord<Elegantbeef> `and` being bitwise on ints was a mistake that even araq dislikes
05:20:24FromDiscord<Elegantbeef> Nim2.0 change?! 😄
05:20:32FromDiscord<Girvo> Hah I'd definitely be okay with that breaking change
05:21:55FromDiscord<Rika> In reply to @Elegantbeef "`and` being bitwise on": I don’t dislike it personally
05:22:14FromDiscord<Rika> I’m not sure what the downside is
05:22:14FromDiscord<Girvo> sent a code paste, see https://play.nim-lang.org/#ix=47JQ
05:24:10FromDiscord<Prestige> I find myself trying to use & like other languages, but I'm on the same page with Rika about it
05:24:30FromDiscord<Rika> I dislike &
05:24:47FromDiscord<Rika> And I especially dislike |
05:28:00FromDiscord<Phil> TIL that `let x = 5 or 2` is valid nim
05:28:27FromDiscord<Phil> I don't understand why it is valid nim, but it does compile
05:28:49FromDiscord<Elegantbeef> `not` and `and` are the cause of many bugs 😄
05:28:49FromDiscord<Rika> That’s the bitwise or
05:29:14FromDiscord<Elegantbeef> all the bits on in 5 and all the bits on in 2
05:29:17FromDiscord<Rika> In reply to @Elegantbeef "`not` and `and` are": Not sure what you mean
05:29:43FromDiscord<Elegantbeef> Between order of operations and accidental usage of `not` `and` can cause issues
05:29:50FromDiscord<Elegantbeef> `not 10 == 30`
05:30:26FromDiscord<Rika> I guess I use parentheses very often
05:32:17FromDiscord<Girvo> I don't use them enough in Nim
05:32:20FromDiscord<Girvo> It looks nicer without them 😛
05:32:26FromDiscord<Ras> oof, as someone new to nim, i would've never thought that the `or` and `and` keywords do bitwise operations - i would've only expected `|` and `&` to do those
05:34:29*kenran joined #nim
05:34:31*kenran quit (Client Quit)
05:42:31FromDiscord<Girvo> sent a code paste, see https://play.nim-lang.org/#ix=47JS
05:43:05FromDiscord<Girvo> I know `length` is right in this case, it's `2` as I have a two-byte `uint16` as `[4]` and `[5]` of data
05:43:13FromDiscord<Elegantbeef> length - 1?
05:44:18FromDiscord<Ras> how would one go about `discard`-ing in a synchronous proc but `await`-ing in an async proc when using the multisync macro? lines 4 and 6 https://media.discordapp.net/attachments/371759389889003532/1008974460654714960/unknown.png
05:44:35FromDiscord<Elegantbeef> `await` is removed with multisync afaik
05:45:06FromDiscord<Ras> yeah, as far as the documentation says, multisync strips `await`s when called synchronously
05:45:26FromDiscord<Girvo> sent a code paste, see https://play.nim-lang.org/#ix=47JT
05:45:57FromDiscord<Elegantbeef> Oh
05:46:01FromDiscord<Elegantbeef> `value[0].addr`
05:46:04FromDiscord<Elegantbeef> Or use an array
05:46:40FromDiscord<Girvo> Yeah shit thats what it was!
05:46:41FromDiscord<Girvo> Cheers 🙂
05:47:02FromDiscord<Girvo> And yeah it'll be moved to an array shortly, this was just my first-pass at it with seq
05:48:31FromDiscord<Elegantbeef> You can also do `when c is Connection` i think↵(@Ras)
05:48:44FromDiscord<Ras> ah, great, thanks
05:50:15FromDiscord<Girvo> sent a code paste, see https://play.nim-lang.org/#ix=47JU
06:24:05*vicecea quit (Remote host closed the connection)
06:24:33*vicecea joined #nim
06:30:29FromDiscord<Ras> how do i actually.. return a future? very last line here https://media.discordapp.net/attachments/371759389889003532/1008986085658984528/unknown.png
06:32:58FromDiscord<Rika> Probably with explicit “return”
06:34:49FromDiscord<Ras> huh
06:35:00FromDiscord<Ras> also, what does this error mean https://media.discordapp.net/attachments/371759389889003532/1008987221371654204/unknown.png
06:35:30FromDiscord<Elegantbeef> Compile the code
06:35:40FromDiscord<Elegantbeef> That just states there is an issue with the template/generic
06:39:42*PMunch joined #nim
06:58:06FromDiscord<creikey> I have this asyncCheck'd function, where a few function calls deep an exception is raised and it's not caught in the block where I catch it here. What gives? https://media.discordapp.net/attachments/371759389889003532/1008993033410330634/unknown.png
06:58:43FromDiscord<Elegantbeef> https://nim-lang.org/docs/asyncdispatch.html#asynchronous-procedures-handling-exceptions
06:58:54FromDiscord<creikey> yeah I thought asynCheck re-raises it
06:59:02FromDiscord<Rika> No not necessarily
06:59:05FromDiscord<creikey> https://media.discordapp.net/attachments/371759389889003532/1008993280643584040/unknown.png
06:59:07FromDiscord<Rika> Sometimes it doesn’t work
06:59:13FromDiscord<Rika> I assume
06:59:18FromDiscord<Elegantbeef> > The async procedures also offer limited support for the try statement.
06:59:24FromDiscord<Rika> Otherwise there wouldn’t be that warning yes
07:00:03FromDiscord<creikey> In reply to @Elegantbeef "https://nim-lang.org/docs/asyncdispatch.html#asynch": if I yield the async dispatcher does other stuff right? It doesn't stall the whole thread like await
07:00:16FromDiscord<creikey> oh I see asyncCheck is completely not what I want
07:01:02FromDiscord<flywind> !eval type Mystring = string; echo typeof(default(Mystring))
07:01:03NimBotCompile failed: Unable to open output log
07:03:36FromDiscord<flywind> It prints "string" in arc.
07:04:00FromDiscord<Elegantbeef> That seems correct
07:04:44FromDiscord<flywind> This still prints MyString
07:04:55FromDiscord<flywind> sent a code paste, see https://play.nim-lang.org/#ix=47K5
07:06:24FromDiscord<flywind> (edit) "This still prints MyString ... " added "in ARC"
07:06:35FromDiscord<Elegantbeef> It's quite questionable what is correct 😄
07:09:15FromDiscord<flywind> Yeah, I agree. My PR for default fields accidentally make the former one prints "string" in refc too. I'm checking this.
07:09:56FromDiscord<creikey> wait but like this is what I want to do https://media.discordapp.net/attachments/371759389889003532/1008996012985155584/unknown.png
07:10:26FromDiscord<creikey> like I would just write that code if I used yield instead of asyncCHeck
07:10:27FromDiscord<creikey> (edit) "asyncCHeck" => "asyncCheck"
07:13:31FromDiscord<Rika> What
07:13:34FromDiscord<Rika> What do you want to do
07:14:07FromDiscord<creikey> call some code I wrote from an async function and if it raises an exception catch it
07:14:18FromDiscord<creikey> I think I figured it out though
07:14:26FromDiscord<creikey> one of the functions in the call stack isn't tagged as async
07:14:45FromDiscord<creikey> I'm not completely sure about the semantics of it but I think that means the exception doesn't set the future as failed
07:14:49FromDiscord<creikey> and so it's uncaught
07:14:50FromDiscord<creikey> or something
07:16:23FromDiscord<Rika> In reply to @creikey "call some code I": Await should raise as well?
07:16:50FromDiscord<creikey> In reply to @Rika "Await should raise as": yeah asyncCheck keeps running
07:17:12FromDiscord<Rika> Well that’s because async check is more akin to a process fork then ignore
07:18:22*PMunch quit (Quit: Leaving)
07:23:15FromDiscord<creikey> like instead of this, I want to just get the data from the async function and if it failed re-raise the exception from the call sight, until the function I have handling the http requests handles it in a root try/catch statement https://media.discordapp.net/attachments/371759389889003532/1008999360496934942/unknown.png
07:23:25*PMunch joined #nim
07:27:35*gsalazar joined #nim
07:30:12FromDiscord<Girvo> Anyone have suggestions for a serialisation protocol thats space-efficient (binary, ideally) and works well in Nim?
07:30:22FromDiscord<creikey> In reply to @Girvo "Anyone have suggestions for": binny?
07:31:43FromDiscord<Elegantbeef> not really a protocol
07:32:56FromDiscord<Girvo> @creikey Looks interesting. We don't necessarily _need_ support from other languages, but it would be a nice-to-have. But BSON et al. all have various downsides, esp. for embedded use (its silly, but BSONs lack of support for uint8 and uint16 annoy me, and for some of our data really matters. Can be worked around of course, but ideally I don't want to lol)
07:33:17FromDiscord<creikey> In reply to @Girvo "<@180866243819995136> Looks interesting. We": I don't know how good capnproto's nim bindings are but it has excellent cross langaue support
07:33:32FromDiscord<Elegantbeef> Nim does have protobuf support
07:33:37FromDiscord<Girvo> yeah, i was also looking at MsgPack, ProtoBufs, etc.
07:33:55FromDiscord<Elegantbeef> Frosty might be the thing to go with, though you'd have to re-implement your format
07:34:06FromDiscord<Elegantbeef> It'd allow you to serialise directly to your target with a specific format
07:34:14FromDiscord<Girvo> Oh Frosty looks nice
07:34:27FromDiscord<Girvo> Wouldn't be too hard to wire in the TLV structure either
07:35:00FromDiscord<Girvo> `nimph clone disruptek/frosty` what in the hell is nimph haha
07:35:15FromDiscord<Elegantbeef> Disruptek's package manager
07:35:25FromDiscord<Girvo> Hah neat. Never heard of it
07:35:46FromDiscord<Elegantbeef> You've never met dis, but he writes great software, just a bit too abrasive so no longer here
07:36:19FromDiscord<Elegantbeef> Actually you might've met him
07:36:24FromDiscord<Elegantbeef> Forgot you used to use nim
07:36:31FromDiscord<Girvo> Haha yeah I remember him
07:36:46FromDiscord<creikey> async nim may have been a mistake to use for this
07:37:10FromDiscord<creikey> just watched the talk by the nim in action guy, it's just a macro that converts the proc to an iterator
07:37:22FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=47Ke
07:37:22FromDiscord<Girvo> join me on the threaded dark side mwahaha
07:37:32FromDiscord<creikey> sent a code paste, see https://play.nim-lang.org/#ix=47Kf
07:37:35FromDiscord<Girvo> I'm kidding, don't, it's pain over here 😭
07:37:51FromDiscord<creikey> sent a code paste, see https://play.nim-lang.org/#ix=47Kg
07:38:07FromDiscord<Elegantbeef> That's not what async is doing
07:38:12FromDiscord<Elegantbeef> https://github.com/nim-lang/Nim/blob/version-1-6/lib/pure/asyncmacro.nim#L128-L131
07:39:00FromDiscord<creikey> so like you can't use try: with await at all ever? what does "unreliable" mean in the docs, under what circumstances does that fail
07:39:24FromDiscord<Elegantbeef> Actually that's kinda what it does
07:39:30FromDiscord<Elegantbeef> No clue how it is i've never really used async
07:39:43FromDiscord<Girvo> I reckon I'm going to go with MessagePack via `msgpack4nim` -- seems nice, and fits what I'm after
07:40:21FromDiscord<Elegantbeef> You could consider trying chronos' async
07:40:38FromDiscord<creikey> I just don't like how I don't understand what's going on in my program right now
07:40:42FromDiscord<creikey> like what code is actually running
07:43:26FromDiscord<creikey> I think my biggest point of confusion, is how do the callbacks actually work?
07:43:37FromDiscord<creikey> like when you call asyncCheck like this https://media.discordapp.net/attachments/371759389889003532/1009004488096481370/unknown.png
07:43:45FromDiscord<creikey> it registers a callback which raises the exception right
07:44:05FromDiscord<creikey> does that exception then get handled in the function asyncCheck was called in?
07:44:06FromDiscord<Elegantbeef> https://github.com/nim-lang/Nim/blob/version-1-6/lib/pure/asyncfutures.nim
07:44:26FromDiscord<Elegantbeef> It should go up the stack
07:44:39FromDiscord<Rika> Await will re raise the error
07:44:41FromDiscord<creikey> that's so weird though, like it's a function inside a function
07:44:45FromDiscord<Rika> I don’t think async check will
07:45:00FromDiscord<Elegantbeef> `discard await X`?
07:45:20FromDiscord<creikey> In reply to @Rika "I don’t think async": it does that though in the screenshot I sent right
07:45:24FromDiscord<Rika> No
07:45:40FromDiscord<creikey> it raises the exception in a proc declared inside a proc declared inside a proc
07:45:48FromDiscord<Rika> The callback is not called in the same function as the proc that calls async check
07:45:57FromDiscord<creikey> no way that's crazy
07:46:01FromDiscord<creikey> oohhh I get it
07:46:02FromDiscord<Rika> What
07:46:04FromDiscord<creikey> so what's the point of asyncCheck
07:46:06FromDiscord<creikey> wait
07:46:08FromDiscord<creikey> it just like
07:46:10FromDiscord<creikey> calls the callback
07:46:13FromDiscord<Ras> In reply to @Elegantbeef "Compile the code": i did, everything compiles and runs fine
07:46:15FromDiscord<Elegantbeef> do discard `Future[T]`
07:46:16FromDiscord<Ras> i have no idea why it's complaining
07:46:18FromDiscord<creikey> in the async runner
07:46:20FromDiscord<Ras> or what it's even complaining about
07:46:21FromDiscord<Rika> Async check does not call the
07:46:22FromDiscord<Rika> Yes
07:46:24FromDiscord<creikey> ohhhhh
07:46:26FromDiscord<creikey> that makes so much more sense
07:46:30FromDiscord<Elegantbeef> Phantom error restart editor if doesnt fix it cry↵(@Ras)
07:46:39FromDiscord<Ras> i am crying
07:46:51FromDiscord<creikey> so I should never use asyncCheck if I want my program to not crash on an exception
07:47:03FromDiscord<Rika> I guess
07:47:07FromDiscord<creikey> await reraises it though, but not "reliably" according to the documentaion
07:47:08FromDiscord<creikey> (edit) "documentaion" => "documentation"
07:47:22FromDiscord<Rika> Async check adds the handler to the future so you could do this (wait brb)
07:47:29FromDiscord<creikey> https://media.discordapp.net/attachments/371759389889003532/1009005465218322453/unknown.png
07:47:31FromDiscord<creikey> this is what await is
07:47:49FromDiscord<creikey> I don't really get this
07:48:04FromDiscord<creikey> https://media.discordapp.net/attachments/371759389889003532/1009005609095548948/unknown.png
07:48:05FromDiscord<creikey> auto in nim??}
07:48:06FromDiscord<creikey> (edit) "nim??}" => "nim??"
07:48:11FromDiscord<Elegantbeef> Yes
07:48:14FromDiscord<Rika> yes
07:48:17FromDiscord<Elegantbeef> It's often a nice way of writing generics
07:48:48FromDiscord<Elegantbeef> The multiasync await is for the sync variant
07:48:54FromDiscord<Elegantbeef> It creates a locally scoped await that is a no op
07:49:03FromDiscord<Elegantbeef> The latter is the one that's called for async procedrues
07:49:05FromDiscord<creikey> ohhh if you await on
07:49:09FromDiscord<creikey> something that's not async
07:49:10FromDiscord<creikey> it just does nothing
07:49:23FromDiscord<Elegantbeef> Inside multisync yes
07:49:28FromDiscord<creikey> this whole time I thought await was a language keyword or something
07:49:34FromDiscord<Rika> no lol
07:49:37FromDiscord<Ras> the multisync macro strips awaits
07:49:47FromDiscord<Rika> nim async is fully implemented as a library
07:49:55FromDiscord<creikey> In reply to @Rika "nim async is fully": like zero help from the compiler?
07:50:05FromDiscord<creikey> I tried reading the async macro but it was incomprehensible
07:50:05FromDiscord<Elegantbeef> Indeed
07:50:06FromDiscord<Rika> other than macros and closure iterators
07:50:13FromDiscord<Elegantbeef> This is why macro systems are good
07:50:23FromDiscord<Elegantbeef> Macro systems allow heavily extending the language in user space
07:50:32FromDiscord<Girvo> Indeed. A good language shouldn't need compiler support to add async behaviour
07:50:42FromDiscord<Elegantbeef> Rust devs cry
07:50:58FromDiscord<creikey> I thought rust async was all macros too
07:51:02FromDiscord<Elegantbeef> To be fair Girvo i'm surprised we got remoterefs to work in Nim's type system
07:51:04FromDiscord<Rika> is it
07:51:09FromDiscord<Elegantbeef> No rust is compiler support
07:51:23FromDiscord<Rika> In reply to @Girvo "Indeed. A good language": not sure why you think so, i'm not sure what i think of it myself
07:51:26FromDiscord<creikey> my brain is fried from nim async rn
07:51:47FromDiscord<Elegantbeef> Remember that in Rust all macro usage uses `!` and only can capture one block of code either `{}` or `()`
07:51:57FromDiscord<Girvo> @ElegantBeef I sort of am, but sort of am not surprised. There was nothing obvious that I could see that meant it _couldn't_ work, but then I remember trying to do some higher-kinded types stuff back in the v0.10 days and broke the compiler doing something that it technically could do lol
07:52:06FromDiscord<Ras> i literally just rewrote my library to support async alongside sync and i've found nim's async to be excellent to work with
07:52:08FromDiscord<Elegantbeef> so `async fn name(){}` wouldnt be possible with it
07:52:26FromDiscord<creikey> In reply to @Ras "i literally just rewrote": yeah I think I just don't know what's going on enough to avoid pitfalls
07:52:30FromDiscord<Rika> nim async is kinda funky but it aint bad at all no
07:52:30FromDiscord<creikey> I'm learning though
07:52:46FromDiscord<Elegantbeef> I know atleast one rust programmer that wishes Rust's was done in macro to not cause a engrained async system that requires compiler updates
07:53:04FromDiscord<Phil> Out of curiosity, was that you jumping in completely new to async or is nim's async just different?
07:53:12FromDiscord<Elegantbeef> The benefit of a async library means you can have multiple implementations that can coexist(atleast mostly)
07:53:13FromDiscord<Rika> who are you asking
07:53:16FromDiscord<Phil> question aimed at creikey
07:53:21FromDiscord<Girvo> In reply to @Rika "not sure why you": From a language implementation perspective, adding special-cased handling for async behaviour is a bit of a code-smell, IMO. But I'm biased for sure lol
07:53:34FromDiscord<creikey> In reply to @Isofruit "Out of curiosity, was": I've been using nim's async for 4 weeks with this program and read multiple documentation pages multiple itmes
07:53:35FromDiscord<Rika> In reply to @Girvo "From a language implementation": i see, that makes sense to me
07:53:37FromDiscord<creikey> (edit) "itmes" => "times"
07:53:55FromDiscord<Phil> In reply to @creikey "I've been using nim's": Nah meant more if you e.g. had to code asynchronously in other languages before
07:54:12FromDiscord<creikey> In reply to @Isofruit "Nah meant more if": yeah I did embedded async with micropython, pretty nice
07:54:14FromDiscord<creikey> also did async in python
07:54:17FromDiscord<creikey> and I wrote an async server in rust
07:54:19FromDiscord<Elegantbeef> I personally think the compiler should be a super small core and extensible in userspace as it makes it very good to write code with
07:54:23FromDiscord<creikey> that was used in production awhile ago
07:54:27FromDiscord<Elegantbeef> When you can make first class features in user space you have a good language
07:54:28FromDiscord<Phil> Because async is one of those things that imo first needs to break your brain in a very special kind of way before you start to get it
07:54:29FromDiscord<creikey> I also have written a good amount of async js
07:54:45FromDiscord<creikey> server side and client side
07:54:55FromDiscord<Phil> Check, then nim's async is just a bit different then I guess
07:54:56FromDiscord<creikey> I'm probably forgetting something else that I've done though I'm not very good at recording what I do
07:55:13FromDiscord<creikey> In reply to @Isofruit "Check, then nim's async": I just don't know what's going on, like await only works sometimes? what?
07:55:22FromDiscord<Phil> Like, rxjs legit broke me for a while before it made sense.
07:55:24FromDiscord<Elegantbeef> The thing that really makes it click to me is that `await`, `waitFor` and friends are just "give up CPU for async operations"
07:55:24FromDiscord<creikey> what does a function being "unreliable" even mean
07:55:42FromDiscord<Elegantbeef> I think huan said that sometimes try except will not compile
07:55:59FromDiscord<Elegantbeef> When it fails it sounded like it was a compile time failure not runtime, i might be wrong
07:55:59FromDiscord<creikey> I'm fine with not compiling but it made it sound like it would just sometimes not work, but still compile
07:56:22FromDiscord<creikey> In reply to @Elegantbeef "The thing that really": await and waitFor sound like they do the same thing to me is why it's been confusing
07:56:43FromDiscord<Elegantbeef> well `waitFor` is blocking and `await` is not
07:56:52FromDiscord<Elegantbeef> Hence why await on non async is an error
07:56:53FromDiscord<enthus1ast> waitFor drives its own async poll loop
07:57:02FromDiscord<creikey> yeah waitFor is the thing that starts the event handler
07:57:10FromDiscord<creikey> in other languages you use await for both
07:57:16FromDiscord<creikey> or the event handler is just started at the top
07:57:21FromDiscord<creikey> (edit) "at the top" => "implicitly"
07:57:25FromDiscord<creikey> because it's baked into the language
07:57:27FromDiscord<Elegantbeef> I mean you dont use them for both
07:57:35FromDiscord<Elegantbeef> You can waitfor an async procedure inside async code
07:57:51FromDiscord<enthus1ast> sent a code paste, see https://play.nim-lang.org/#ix=47Kj
07:57:57FromDiscord<Girvo> In reply to @Rika "i see, that makes": As an addition, any language with Generator support can have coroutines added, which can match the semantics of async/await 🙂 The only reason to special case it is to ensure `yield` isn't confusing with two subtly different usages. PHP got Async support via libraries this way!
07:58:19FromDiscord<enthus1ast> this is usefull for combining the async loop with other external event loops like for guis etc
07:58:20FromDiscord<Phil> In reply to @Elegantbeef "well `waitFor` is blocking": Wait... await is not blocking?
07:58:23FromDiscord<Phil> But... what?
07:58:37FromDiscord<Ras> it blocks in the current proc, no?
07:58:39FromDiscord<Elegantbeef> not blocking in the respects of async code
07:58:47FromDiscord<Elegantbeef> async gives up the cpu to operate
07:58:55FromDiscord<creikey> In reply to @Isofruit "Wait... await is not": I think await waits for the future you provide it and frees up the dispatcher to do other things
07:58:59FromDiscord<Elegantbeef> await says "here we will run a 'continuation'"
07:59:12FromDiscord<creikey> I have 0 clue how the dispatcher "resumes" the function though
07:59:15FromDiscord<creikey> with no compiler help
07:59:22FromDiscord<Elegantbeef> closure procedures
07:59:22FromDiscord<creikey> like isn't there a function stack and stuff
07:59:22FromDiscord<Girvo> Continuations, typically
07:59:28FromDiscord<Phil> Ohh not blocking as in your code is still waiting for future completion, but while it does so other operations can complete
07:59:35FromDiscord<creikey> yeah
07:59:44FromDiscord<Elegantbeef> closure iterators\
07:59:46FromDiscord<Phil> If that's the case, why use waitfor?
07:59:53FromDiscord<Phil> If that literally blocks your CPU
07:59:57FromDiscord<Phil> (edit) "If that literally blocks your ... CPU" added "entire"
07:59:59FromDiscord<Phil> (edit) "If that literally blocks your entire CPU ... " added "Thread"
07:59:59FromDiscord<Elegantbeef> You only want your cpu to operate on that code
08:00:26FromDiscord<Rika> if you want to not use async
08:00:26FromDiscord<Elegantbeef> There are cases you may want that
08:00:33FromDiscord<enthus1ast> î often use waitFor when i use an async lib but my code is pretty much sync
08:00:35FromDiscord<creikey> In reply to @Elegantbeef "closure iterators\*": so the function's stack is on the heap? https://media.discordapp.net/attachments/371759389889003532/1009008758241906758/unknown.png
08:00:46FromDiscord<creikey> like in every async function all local variables aren't in the stack but are allocated on the heap
08:00:54FromDiscord<Elegantbeef> The environment is stored on the heap
08:01:06FromDiscord<Elegantbeef> That doesnt mean all local afaik
08:01:18FromDiscord<Elegantbeef> That's only the persistent variables
08:01:43FromDiscord<creikey> like somewhere the cpu is doing jmp to after the await statement, and all of the cpu's registers are the same as they were when it jmp'd to other things
08:01:58FromDiscord<Elegantbeef> Dont talk asm with me i dont speak that way
08:02:00FromDiscord<creikey> like the state of the function is the same
08:02:06FromDiscord<creikey> somehow
08:02:16FromDiscord<Elegantbeef> closure iterators are continuable functions
08:02:21FromDiscord<Girvo> Do you know much about coroutines and continuations?
08:02:28FromDiscord<Elegantbeef> So the way async macro works is to insert `yield` calls where they make sense
08:02:31FromDiscord<creikey> In reply to @Girvo "Do you know much": yeah coroutines work like this
08:03:25FromDiscord<Elegantbeef> https://nim-lang.org/docs/intern.html#code-generation-for-closures
08:03:32FromDiscord<Elegantbeef> Good writeup to explain how closures work in Nim
08:03:39FromDiscord<Girvo> Oh neat, it uses lambda lifting?
08:03:47FromDiscord<Elegantbeef> Yea
08:04:40FromDiscord<Girvo> Do we have escape analysis?
08:04:52FromDiscord<Elegantbeef> Nim does have some
08:05:12FromDiscord<Elegantbeef> This is why you cannot make a closure use a `var T`
08:05:28FromDiscord<Phil> To this day in my brain has understood the difference between closure and anonymous proc only "intellectually". Like, I know the difference is that the closure also captures its environment, but the consequences that arrive from that have never computed for me.
08:06:11FromDiscord<Phil> Like yeah, you get a variable from your surroundings... so a copy of the ref or value depending on its types so it might lead to side-effects if it's a ref-type... so?
08:06:18FromDiscord<Girvo> Yeah the unfortunate over-use of "closure" to just mean "anonymous procedure" in certain circles confuses things sometimes lol
08:06:19FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=47Ko
08:06:52FromDiscord<Elegantbeef> Yea the fun part with calling conventions is they're very much not equivlent
08:07:15FromDiscord<creikey> what is lambda lifting 😭
08:07:23FromDiscord<creikey> I'm like 5 terms deep rn
08:07:43FromDiscord<d4rckh> is there any when defined flag i can use to have different logic for when im compiling as a dll on windows?
08:07:50FromDiscord<Girvo> Lambda lifting is a way to "lift" a local function into a global scope, to put it badly/simply
08:07:53FromDiscord<creikey> no way the compiler moves lambda functions to global scope and passes captures variables as parameters???
08:07:55FromDiscord<Girvo> https://en.wikipedia.org/wiki/Lambda_lifting
08:07:58FromDiscord<creikey> that's incredible
08:07:59FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=47Kp
08:08:06FromDiscord<creikey> that's like how I would think to do it off the top of my head
08:08:08FromDiscord<creikey> but no idea how to do it
08:08:13FromDiscord<Rika> oh man lambda lifting might actually melt your mind
08:08:17FromDiscord<Girvo> Hahaha
08:08:19FromDiscord<Elegantbeef> When you're a compiler it's 'easy'
08:08:33FromDiscord<creikey> this is actually trolling
08:08:38FromDiscord<Rika> lol
08:08:39FromDiscord<Elegantbeef> this is also the only real compiler support async has, i think there have been specific PRs to get lambda lifting done
08:08:44FromDiscord<creikey> functional langauges are a lie
08:08:47FromDiscord<Elegantbeef> done for async\
08:08:57FromDiscord<Girvo> All of this is very much in the functional programming language theoretics stuff, so if you've not come from programming language implementation or Lisps, it can seem a bit hairy
08:09:17FromDiscord<creikey> I should learn lisp at some point once I'm done spending hours trying to get an exception to be caught in nim async
08:09:20FromDiscord<Elegantbeef> Speaking of calling conventions, girvo did you see my bigbrain idea of using `{.inline.}` for the remotre refs
08:09:43FromDiscord<Elegantbeef> Since they dont exist at runtime we can use 'inline pointer procs' 😄
08:09:48FromDiscord<Girvo> Ah I don't think I picked up on it -- shit yeah thats nice haha
08:09:59FromDiscord<creikey> > Repeated lifts may be used to convert a program written in lambda calculus into a set of recursive functions, without lambdas. This demonstrates the equivalence of programs written in lambda calculus and programs written as functions
08:10:00FromDiscord<creikey> is this proven
08:10:08FromDiscord<Girvo> Yes
08:10:14FromDiscord<creikey> what does that proof even look like
08:10:15FromDiscord<creikey> alien alnguage
08:10:17FromDiscord<creikey> (edit) "alnguage" => "language"
08:10:18FromDiscord<Girvo> Maths :
08:10:20FromDiscord<Girvo> (edit) ":" => "🙂"
08:10:36FromDiscord<Elegantbeef> It's a very minimal benefit but it does increase the chance that we get inlined code with the allocation and deallocations
08:10:50FromDiscord<Girvo> Yeah and with this, any possible benefit is worth it
08:11:08FromDiscord<Girvo> And it doesn't make it unclear or anything, so definitely worth it
08:11:20FromDiscord<Elegantbeef> I still dont know what to call it though, RemoteRef feels wrong
08:11:31FromDiscord<Girvo> Yeah I agree
08:11:51FromDiscord<Girvo> `FarRef` lol
08:11:54FromDiscord<creikey> lambda lifting is wackiest thing I've learned about this month
08:12:32FromDiscord<Girvo> Wait til you see how you can represent natural numbers using nothing but functions 😉
08:12:38FromDiscord<Phil> sent a code paste, see https://paste.rs/DXW
08:12:59FromDiscord<Girvo> https://sskelkar.github.io/representing-natural-numbers-in-lambda-calculus/ its pretty awesome!
08:13:34FromDiscord<Girvo> SICP is a book I highly recommend reading and working through if you find this stuff interesting
08:13:36FromDiscord<creikey> sent a code paste, see https://play.nim-lang.org/#ix=47Kr
08:14:02FromDiscord<creikey> In reply to @Girvo "SICP is a book": if this is like rabbithole that doesn't help me write better programs I wouldn't want to
08:14:32FromDiscord<Girvo> Oh no, its one of the few books in this area that can _absolutely_ help you write better programs. But it's definitely a rabbithole!
08:14:42FromDiscord<Elegantbeef> The reason it cannot be captured is it's unsafe to hold onto a pointer↵(@Phil)
08:14:58FromDiscord<creikey> In reply to @creikey "so the first lambda": this is wrong
08:14:59FromDiscord<Elegantbeef> You do not know where that pointer came from it might be a stack variable
08:15:22FromDiscord<Elegantbeef> As such if you dont do escape analysis you get a stack variable and attempt to use it and it's wrong
08:15:36FromDiscord<Phil> In reply to @Elegantbeef "You do not know": So capturing means I must have a pointer to that exact value, I can't just do a copy of that value and keep it
08:15:36FromDiscord<Elegantbeef> Remember closures do not run where they're made
08:15:36FromDiscord<Elegantbeef> Or rather do not have to run
08:15:52FromDiscord<creikey> sent a code paste, see https://play.nim-lang.org/#ix=47Kt
08:15:52FromDiscord<creikey> wait but isn't that fine
08:16:05FromDiscord<Elegantbeef> Well of course you can copy, but Nim assumes that for `var T` you want to hold onto the value
08:16:07FromDiscord<Elegantbeef> So it tells you it'd outlive the origin
08:16:25FromDiscord<Elegantbeef> As such you can either unsafely cast it to a pointer before the closure and use that or use a `ref T`
08:16:45FromDiscord<Elegantbeef> Since refs are Gc'd you can safely capture them as the closure ticks their lifetime
08:17:13FromDiscord<Elegantbeef> Closures actually copy the stack values declared in their stack scope, but for references they cannot
08:17:40FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=47Kv
08:18:27FromDiscord<Phil> So an environment can consist of copied variable values and references to outside variable values
08:18:33FromDiscord<Phil> environment of a closure
08:18:57FromDiscord<Elegantbeef> It can hold onto any value that is safe to hold onto 😄
08:19:00FromDiscord<Phil> And due to the var I tell nim I want a reference to a in my environment
08:19:21FromDiscord<Elegantbeef> attempting to hold onto `var T` in nim is saying "I want a checked pointer to T"
08:19:34FromDiscord<Elegantbeef> The error is due to that checked part
08:19:45FromDiscord<Elegantbeef> If you do `ptr T` there is no error
08:20:22FromDiscord<Phil> But then I basically risk a runtime error (panic? not sure)
08:20:26FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=47Ky
08:20:39FromDiscord<Elegantbeef> No the issue with `ptr T` is not panics really
08:20:47FromDiscord<creikey> I'm sorry for using asyncCheck everywhere and making my program randomly crash I was listening to Free Bird when I wrote it
08:20:48FromDiscord<Elegantbeef> The issue with `ptr T` is dangling pointers
08:21:13FromDiscord<d4rckh> In reply to @d4rckh "is there any when": up
08:21:15FromDiscord<Elegantbeef> the safety that `var T` gives you is that the pointer isnt nil and also it's not dangling
08:21:16FromDiscord<Phil> Ah, which might keep memory unfree'd though it should be free'd ?
08:21:33FromDiscord<Elegantbeef> `when defined(windows) and defined(library)` i think
08:21:38FromDiscord<Elegantbeef> No
08:21:51FromDiscord<Elegantbeef> Dangling pointers are pointers to the stack that outlive their usage
08:22:11FromDiscord<d4rckh> ty
08:22:51FromDiscord<creikey> In reply to @Girvo "Oh no, its one": I'm looking at this book, I want to solve engineering problems and make good programs this seems like puzzle solving. Are those the same thing? I have no idea
08:23:17FromDiscord<Elegantbeef> What is printed?
08:23:20FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=47Kz
08:23:43FromDiscord<Elegantbeef> remove `doOtherThing()` and what is printed?
08:24:02FromDiscord<Elegantbeef> You do have to love Nim to being so simple to explain dangling pointers
08:24:20FromDiscord<creikey> sent a code paste, see https://play.nim-lang.org/#ix=47KA
08:24:27FromDiscord<Elegantbeef> That's not fine
08:24:34FromDiscord<creikey> (edit) "https://play.nim-lang.org/#ix=47KA" => "https://play.nim-lang.org/#ix=47KB"
08:24:43FromDiscord<creikey> but like A hasn't left the stack yet when the proc that increments it is called
08:24:45FromDiscord<Elegantbeef> That's a compiletime error that capturing `a` is unsafe
08:24:57FromDiscord<Elegantbeef> Except this procedure doesnt know you passed it a global variable
08:25:11FromDiscord<Elegantbeef> the global variable is declared after it and indirected with `var T`
08:25:13FromDiscord<creikey> returning a proc that captures a parameter is just like returning a struct that captures a parameter right?
08:25:36FromDiscord<Elegantbeef> returning a proc that captures a parameter is a closure procedure
08:25:39FromDiscord<mratsim> a closure is a struct, ptr to function + environment
08:26:08FromDiscord<creikey> like this is all fine right
08:26:10FromDiscord<creikey> sent a code paste, see https://play.nim-lang.org/#ix=47KC
08:26:11FromDiscord<creikey> how is that different
08:26:21FromDiscord<Elegantbeef> Cause you cannot hold onto `var int`
08:26:27FromDiscord<creikey> oh you can't do that either?
08:26:28FromDiscord<Elegantbeef> Nim doesnt have a borrow checker by default
08:27:20FromDiscord<creikey> I don't understand this error message though https://media.discordapp.net/attachments/371759389889003532/1009015488971538512/unknown.png
08:27:30FromDiscord<mratsim> {.experimental: "views".} might allow holding the var int
08:28:40*PMunch quit (Quit: Leaving)
08:28:43FromDiscord<mratsim> In reply to @creikey "I don't understand this": I wouldn't trudst the error message as you're treading an "here be dragons" code path
08:29:30FromDiscord<mratsim> 1. except maybe (big maybe) with the views flag, you can't assign "var T", it's not a first-class type
08:30:15FromDiscord<creikey> can you have a var type in an object?
08:30:26FromDiscord<ElegantBeef> With views you can
08:30:28FromDiscord<ElegantBeef> Not without
08:30:35FromDiscord<mratsim> try with `{.experimental: "views".}`
08:30:36*PMunch joined #nim
08:30:39FromDiscord<mratsim> unsure
08:30:57FromDiscord<Elegantbeef> Are we back?!
08:31:00FromDiscord<Elegantbeef> We are!
08:32:08FromDiscord<Elegantbeef> Due to the lack of views being on by default you cannot hold onto `var T` `lent T` or `openArray` presently
08:32:30FromDiscord<Elegantbeef> In 10 years when views come you'll be able to use them and it'll be borrow checked just like Rust's
08:32:54FromDiscord<Elegantbeef> Presently views is extremely experimental and results in a ton of bugs/codegen issues
08:33:44FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=47KE
08:34:49FromDiscord<Elegantbeef> Welcome to dangling pointers
08:34:59FromDiscord<Phil> But... but that's its own stack variable!!!
08:35:04FromDiscord<Elegantbeef> `var a = 100` is a stack variable
08:35:14FromDiscord<Elegantbeef> so when you take the address of it you're taking the address of the stack
08:35:22FromDiscord<Phil> Is this the kind of crap that folks in C have to deal with on the regular?
08:35:32FromDiscord<Elegantbeef> then when you call `doOtherThing()` you write `30000` over that `100` then increment it
08:35:45FromDiscord<mratsim> In reply to @Isofruit "Is this the kind": assembly
08:35:48FromDiscord<Elegantbeef> So then when the program echos from that pointer it gets `30001` since that's in stack
08:35:57FromDiscord<mratsim> why take an address of an int
08:36:08FromDiscord<Elegantbeef> To explain dangling pointers to phil
08:36:29FromDiscord<Phil> The fact that the `var a` in `doOtherThing` is not getting its own piece of memory kind of breaks me
08:36:41FromDiscord<Elegantbeef> This is what the stack is for
08:36:44FromDiscord<enthus1ast> crazy; this also depends on the mm
08:37:17FromDiscord<Elegantbeef> The stack is a small chunk of reused memory that is often overwritten
08:37:32FromDiscord<mratsim> In reply to @Isofruit "The fact that the": Actually, here it's simple enough that compiled it doesn't use memory but register only or even optimized away
08:37:35FromDiscord<Elegantbeef> This is why dangling pointers are sketchy, they dont behave like other pointer issues
08:37:43FromDiscord<mratsim> In reply to @Elegantbeef "This is what the": it was a rhetorical question
08:37:55FromDiscord<Elegantbeef> Ah ok wasnt clear
08:39:31FromDiscord<Elegantbeef> Phil learning stack, he's going to be a god soon
08:40:14FromDiscord<Elegantbeef> Well with refc you have more operations so it's likely to corrupt the stack automatically
08:40:23FromDiscord<Elegantbeef> Orc/Arc are deterministic so corrupt the stack deterministically
08:40:32FromDiscord<Phil> In reply to @Elegantbeef "so when you take": Wait, "the address of the stack" as in that is one single namespace and any variable on the stack of equal name is equal?↵Like if I had an addr to a variable called "potato" any reassignment to "potato" writes to the same potato?↵Wait, could I even do redefinitions of one being `var potato = "potato"` and elsewhere `var potato = 5` ?
08:40:42FromDiscord<Elegantbeef> No
08:40:45FromDiscord<Elegantbeef> The name of the variable doesnt matter
08:40:50FromDiscord<Elegantbeef> It's a local variable in a procedure
08:41:02FromDiscord<Elegantbeef> It writes to the same spot in memory when the procedure stackframe is added
08:41:15FromDiscord<Elegantbeef> When you call `doThing` it grows the stack for that `a`
08:41:27FromDiscord<Elegantbeef> Then after the call the stack shrinks again
08:41:51FromDiscord<Elegantbeef> Then when you call `doOtherThing` it grows the stack again, so the two variables reside at the same place in memory
08:42:04FromDiscord<Elegantbeef> Which is why when you mutate that location after it appears to back propagate
08:42:39FromDiscord<Elegantbeef> Cause the two variables happen to take the same memory location on the stack, so taking address of the first accidently points to the second
08:43:11FromDiscord<Elegantbeef> The stack is linear memory, so when you take an address of it you never want that pointer to outlive the procedure
08:43:17FromDiscord<Elegantbeef> This part of what a borrow checker does
08:46:02FromDiscord<Phil> That is some wildly complicated source of errors
08:46:19FromDiscord<Elegantbeef> It's not that complicated 😄
08:49:24FromDiscord<Elegantbeef> Learning that the stack is a fixed size ticker tape that your scoped value types are stored to is the first step!
08:50:17FromDiscord<Elegantbeef> Just dont think all value types are stored there like whoever did the otherday
08:52:40FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=47KG
08:53:03FromDiscord<Phil> That's the first time I got exposed to this type of memory corruption I think
08:53:24FromDiscord<Elegantbeef> Yep and since it's not a checked pointer it doesnt give any indication
08:54:05*PMunch quit (Quit: Leaving)
08:54:17FromDiscord<Elegantbeef> These types of errors are why `ref` and `var` exist
08:54:53FromDiscord<Elegantbeef> These safe pointer types give you memory safety
08:55:05FromDiscord<Phil> It just seems like such a wild error that you get to provoke by coincidentally creating pointers to the same stack memory area
08:55:20FromDiscord<Elegantbeef> Atleast some variation of memory safety, there is dispute on what memory safety constitutes
08:55:23*PMunch joined #nim
08:55:57FromDiscord<Elegantbeef> You can do the same thing to the heap of course
08:56:14FromDiscord<Elegantbeef> Where you accidently free the memory you have on the heap but dont nil the pointer
08:56:19*PMunch quit (Client Quit)
08:56:25FromDiscord<Elegantbeef> It'll appear to work fine until you allocate onto that chunk again
08:56:45FromDiscord<Phil> With basically little to no type-safety checks in place I can see how you can easily break your own memory in C
08:56:49FromDiscord<Elegantbeef> Cause of how the heap works depending on what you're doing it might be a while before you allocate a block that fits the memory/page
08:57:22FromDiscord<Elegantbeef> Yea C's pointer types especially are comically bad
08:57:28FromDiscord<Elegantbeef> The fuck does a `T` even mean
08:58:03FromDiscord<Elegantbeef> That can mean `ptr ptr T` or `ptr UncheckedArray[T]`
08:58:23FromDiscord<Elegantbeef> There's probably even more that can mean
08:58:52FromDiscord<Elegantbeef> Pascal is a better language for a basis of an ABI language
09:06:22FromDiscord<4zv4l> is there a kind of Mutex type or something in Nim ?↵to modify a variable that is shared between threads
09:06:23FromDiscord<Phil> TIL back in the day Pascal and C were head to head, and now here we are, with nim with strong references to Pascal, generating C code
09:07:26FromDiscord<Elegantbeef> `std/locks`↵(@4zv4l)
09:08:47FromDiscord<4zv4l> why does the Lock need to be init and deinit ?
09:09:38FromDiscord<Elegantbeef> Not a clue
09:10:58FromDiscord<4zv4l> also how can I detach a Thread↵https://nim-lang.org/docs/threads.html
09:11:01FromDiscord<4zv4l> didn't find here
09:11:40FromDiscord<Elegantbeef> Dont think you can
09:12:04FromDiscord<4zv4l> what
09:12:11FromDiscord<4zv4l> cannot detach thread ?
09:12:18*PMunch joined #nim
09:12:29FromDiscord<Phil> For those that don't casually multi-thread, difference of detach to create?
09:12:32FromDiscord<Elegantbeef> Threads are threads they run the code you give them from when you create them
09:13:08FromDiscord<Elegantbeef> Based off C++ it seems like `createThread` does that
09:13:08FromDiscord<4zv4l> but what if I don't need to wait for it and just let it clean everything by itself ?
09:13:12FromDiscord<Elegantbeef> > Detaches the thread represented by the object from the calling thread, allowing them to execute independently from each other.
09:13:29FromDiscord<Elegantbeef> You literally just `createThread` and it starts detatched then
09:13:39FromDiscord<4zv4l> alright
09:13:43FromDiscord<4zv4l> so don't need to join
09:13:45FromDiscord<Elegantbeef> Why the hell would a thread start attached
09:13:52FromDiscord<Elegantbeef> That seems like someone designed the C++ API backwards
09:14:29FromDiscord<4zv4l> sent a code paste, see https://play.nim-lang.org/#ix=47KP
09:14:35FromDiscord<Phil> ... I'm scared to ask what an attached thread is. In my mind-model threads are always independant from one another except in the regard that one thread might signal another or they might both access the same piece of memory
09:14:49FromDiscord<Phil> (edit) "is. In" => "is, but what is it?↵In"
09:14:56FromDiscord<Elegantbeef> Basically phil it's who does the cleanup
09:15:04FromDiscord<4zv4l> In reply to @Elegantbeef "> Detaches the thread": where did you see that description ?
09:15:11FromDiscord<Elegantbeef> From the C++ manual
09:15:18FromDiscord<4zv4l> oh not from Nim alright
09:15:19FromDiscord<Elegantbeef> The first result of "detach thread" i could find
09:15:25FromDiscord<Phil> As in who frees the memory they access and the memory the thread itself occupied?
09:15:40FromDiscord<4zv4l> so in Nim you don't have to call join if you don't want to wait for them right ?
09:15:56FromDiscord<Elegantbeef> You `joinThread` to blocking wait
09:16:07FromDiscord<Elegantbeef> If you dont want to block wait and want them to run you dont call anything but `createThread`
09:16:24FromDiscord<4zv4l> alright
09:16:28FromDiscord<4zv4l> thank you
09:17:13*PMunch quit (Quit: Leaving)
09:17:30FromDiscord<Phil> > In other words sets a thread's affinity. If you don't know what this means, you shouldn't use this proc.↵I like the style of whoever wrote the thread docs
09:19:35FromDiscord<4zv4l> yeah funny one xD
09:20:26FromDiscord<4zv4l> In reply to @Isofruit "> In other words": wondering what happen if you give too many cores you don't have to that function
09:21:13*PMunch joined #nim
09:21:31FromDiscord<Elegantbeef> Your OS scheduler handles it
09:22:00FromDiscord<4zv4l> so throws an error or give as much cores as it can ?
09:22:52FromDiscord<Elegantbeef> it probably just gives you a random core, but no clue
09:29:12FromDiscord<creikey> https://github.com/nim-lang/Nim/blob/version-1-6/lib/pure/asyncdispatch.nim#L1961 where is the source of this function?
09:29:45FromDiscord<Elegantbeef> https://github.com/nim-lang/Nim/blob/version-1-6/lib/pure/asyncdispatch.nim#L1649
09:29:49FromDiscord<creikey> yeah found it
09:29:50FromDiscord<creikey> with google
09:32:56FromDiscord<mratsim> In reply to @Isofruit "It just seems like": Not just an error, all exploits via "buffer overflow" use that
09:33:39FromDiscord<mratsim> In reply to @4zv4l "why does the Lock": register to the Linux/Windows kernel
09:35:44FromDiscord<Ras> In reply to @mratsim "Not just an error,": UAF seems like a more appropriate vuln to draw parallels here
09:42:54FromDiscord<creikey> can you await multiple futures in nim?
09:43:01FromDiscord<creikey> (edit) removed "in nim?"
09:43:02FromDiscord<creikey> (edit) "futures" => "futures?"
09:46:59FromDiscord<Rika> Yes
09:47:12FromDiscord<creikey> is it just straight up like
09:47:13FromDiscord<creikey> comma separte them
09:47:16FromDiscord<creikey> (edit) "separte" => "separate"
09:47:27FromDiscord<Rika> https://nim-lang.org/docs/asyncfutures.html#all%2Cvarargs%5BFuture%5BT%5D%5D
09:47:30FromDiscord<Rika> No
09:48:05FromDiscord<creikey> I think I should try to describe my actual problem so I can get higher level direction instead of looking to features like that
09:48:17FromDiscord<creikey> basically, I'm using the ws library to handle clients in a game right
09:48:33FromDiscord<creikey> standard stuff like this https://media.discordapp.net/attachments/371759389889003532/1009035930956480543/unknown.png
09:48:58*jmd_ quit (Ping timeout: 244 seconds)
09:49:14FromDiscord<creikey> at some point one of the clients will "start the game", so I have a long running operation where the timing of the game is managed
09:49:32FromDiscord<creikey> where the server will wait 60 seconds or whatever configured amount, announce to all the clients in the lobby the next phase of the game has started, etc
09:50:17FromDiscord<creikey> I used asyncCheck before to start that function but I think that's wrong because the exceptions spawned by it won't be caught, because my waitFor event loop isn't in a try: catch
09:50:30FromDiscord<creikey> I think what I should do is just register a callback on the future that does some logging if it fails for whatever reason then does nothing
09:50:40FromDiscord<creikey> is this correct?
09:54:05FromDiscord<Phil> My takeaway is that memory is evil
09:54:16FromDiscord<mratsim> In reply to @creikey "I think what I": Your future can return an error code or a variant, and you can log as well, in-place, for debugging
09:54:19FromDiscord<Phil> (in reference to the earlier debate)
09:55:04FromDiscord<mratsim> In reply to @Isofruit "My takeaway is that": it's something to learn
09:55:13FromDiscord<mratsim> and the abstraction of it something to appreciate
09:55:30FromDiscord<creikey> In reply to @mratsim "and the abstraction of": writing linked list in rust is classic just remembered that
09:55:43FromDiscord<mratsim> it also explain why unsafeAddr is considered unsafe or why Rust is important
09:56:35FromDiscord<mratsim> though I think the memory safety part is overblown. It's way less tricky than deadlocks, livelocks and race conditions which the borrow checker doesn't prevent at all.
09:57:28FromDiscord<creikey> In reply to @mratsim "though I think the": yeah, in rust I found I still spent a lot of time debugging compared to C/C++, it was just logic errors/subtle properties of RAII/etc
09:57:31FromDiscord<Phil> ... Can you even do that without making it impossible to program useful stuff?
09:57:44FromDiscord<creikey> I really wish a new programming language would make debugging easier instead of trying to eliminate bugs with language features
09:57:57*vicecea quit (Remote host closed the connection)
09:58:05FromDiscord<creikey> like imagine if you put as much effort into making the rust compiler as you did into like the super ultra debugger 3000 that helped out and visualized all of that stuff
09:58:22FromDiscord<creikey> so much more productive
09:58:27*vicecea joined #nim
09:58:45FromDiscord<Phil> Hmmm shouldn't rust be capable of preventing race conditions since it can prevent shared mutable state (outside of databases but for that shit I think bets are off in general)
09:58:54FromDiscord<Phil> (edit) "Hmmm shouldn't rust be capable of preventing race conditions since it can prevent shared mutable state (outside of databases but for that shit I think bets are off in general) ... " added "?"
10:00:23FromDiscord<Phil> I guess I just answered my own question I am realizing
10:01:22FromDiscord<mratsim> In reply to @Isofruit "Hmmm shouldn't rust be": they prevent data races with ownership, but race conditions are different
10:01:59FromDiscord<mratsim> https://en.wikipedia.org/wiki/Dining_philosophers_problem
10:05:04FromDiscord<mratsim> sent a long message, see http://ix.io/47KX
10:05:15FromDiscord<mratsim> (edit) "http://ix.io/47KX" => "http://ix.io/47KY"
10:10:30FromDiscord<Rika> Don’t some rust programmers conflate the two?
10:11:26FromDiscord<dom96> In reply to @creikey "I think what I": yes, for server apps you should create a `asyncLog` proc that you can call to set up this call back
10:32:21FromDiscord<Ras> i have a list of enums: https://media.discordapp.net/attachments/371759389889003532/1009046955722289192/unknown.png
10:32:54FromDiscord<Ras> and a list of corresponding objects
10:32:57FromDiscord<Ras> https://media.discordapp.net/attachments/371759389889003532/1009047103516971038/unknown.png
10:33:10FromDiscord<mratsim> In reply to @Rika "Don’t some rust programmers": sure they do, and then they think Rust is the holy grail for thread safety
10:33:37FromDiscord<Ras> how would one go about associating these? I'd like to look up the enum to see which object to unmarshall json to
10:34:00FromDiscord<mratsim> In reply to @Ras "how would one go": object variant?
10:34:00FromDiscord<Ras> i think a switch is the easiest option, probably?
10:34:03FromDiscord<Ras> object variant?
10:34:38FromDiscord<mratsim> https://nim-lang.org/docs/tut2.html#object-oriented-programming-object-variants
10:35:23FromDiscord<mratsim> see: https://github.com/mratsim/chirp8/blob/master/src/cpu.nim#L25-L89
10:35:40FromDiscord<Ras> oh, fancy
10:35:41FromDiscord<Ras> thanks
10:35:46FromDiscord<creikey> In reply to @dom96 "yes, for server apps": Did you see my thing about cloudflare not stopping big websockets packets? Is this something I should fork ws and block to prevent or should I not worry about it?
10:50:26FromDiscord<Ras> @mratsim unfortunately, doesn't work for my case
10:50:29FromDiscord<Ras> https://media.discordapp.net/attachments/371759389889003532/1009051520014229604/unknown.png
10:51:40FromDiscord<Ras> actually, since everything has a base of 0x8000000, i can just base everything off 0 and just do a logical and later
10:51:51FromDiscord<Ras> (edit) "logical and" => "bitwise AND"
11:07:47FromDiscord<krisppurg> quick question, when was duplicatemoduleimport added to nim?
11:09:54FromDiscord<Ras> In reply to @mratsim "https://nim-lang.org/docs/tut2.html#object-oriented": actually, i still can't do that, as multiple different "kinds" can have the same value
11:10:16FromDiscord<Ras> the compiler complains that i'm trying to redefine it
11:10:33FromDiscord<Ras> https://media.discordapp.net/attachments/371759389889003532/1009056565292175360/unknown.png
11:14:34FromDiscord<Rika> Yes you will have to change the field name
11:18:32*PMunch quit (Quit: Leaving)
11:28:31FromDiscord<Ras> that's not possible in my case
11:28:56FromDiscord<Ras> as the json i'm unmarshalling is not mine
11:29:13FromDiscord<Ras> i just did a case statement
11:30:53*dnh joined #nim
11:34:09FromDiscord<Rainbow Asteroids> if all of your variants have the field `change`, then you can put the change string outside of the case statement
11:34:27FromDiscord<Ras> nope, unfortunately not all of them do
11:34:37FromDiscord<Ras> some of them have a duplicate "id" as well, which others lack
11:34:43FromDiscord<Ras> (edit) ""id"" => "`id`"
11:44:26*PMunch joined #nim
11:57:28*PMunch quit (Quit: Leaving)
12:06:56FromDiscord<rakgew> sent a code paste, see https://play.nim-lang.org/#ix=47Li
12:06:57FromDiscord<b1rdf00d> sent a code paste, see https://paste.rs/dWK
12:09:19*PMunch joined #nim
12:18:06FromDiscord<dom96> In reply to @creikey "Did you see my": I didn't, no. Might be worthwhile to handle in the ws library
12:18:13FromDiscord<domosokrat> sent a code paste, see https://play.nim-lang.org/#ix=47Lk
12:19:48FromDiscord<creikey> In reply to @dom96 "I didn't, no. Might": I did test just sending a frame with a really big promised size but the actual data wasn't that big, and it seemed like cloudflare handled it, but I forgot to do a control experiment locally to see if I did it right
12:22:05FromDiscord<rakgew> domosokrat thank you so much!!↵now the ptr has some content. so in general when C says\: `something` it would be `addr ptr something` in nim?
12:24:12FromDiscord<Ras> In reply to @b1rdf00d "I ran into this": interesting, thanks
12:27:17FromDiscord<rakgew> ah ok - it looks different on the book link - thx!
12:33:57FromDiscord<rakgew> coming from python, C with all its ptrs and addrs are still fairly confusing to me..
12:34:31FromDiscord<domosokrat> rakgew\: Yes, in general if in C a function parameter is `f(something p)` it means to pass the address to an `something p`. Which translates to `var p: ptr something; f(addr p)`
12:35:34FromDiscord<rakgew> I see. thank you so much for explaining!
12:38:02*xet7 quit (Quit: Leaving)
12:39:10FromDiscord<rakgew> in the example ot the scm book what would be the equivalent to this stragne line in nim?\:↵`git_commit commit = (git_commit)head_commit;`↵left side seems clear-ish to me\: a ptr variable of type git\_commit, but what is going on on the other side of `=` ? are they casting head commit into `ptr git_commit` ?
12:41:15FromDiscord<EyeCon> In reply to @Girvo "Anyone have suggestions for": CBOR - I hope no one said it yet, I was away for some time
12:41:35FromDiscord<EyeCon> No direct Nim support but it's easy to do it yourself
12:41:47FromDiscord<EyeCon> If you're interested, I can share some code
12:41:52FromDiscord<rakgew> cool it worked\: `let git_commit = cast[ptr git_commit](head_commit)`
12:42:06FromDiscord<demotomohiro> `f(something p)` might also means to pass the array of pointers. We cannot tell what you what the C function takes only from signature. You would better to check the manual or refernce of the library.
12:43:54FromDiscord<rakgew> @demotomohiro thanks for the headsup on multiple meaning.↵yep, I m reading it in the libgit2 api docs\:↵https://libgit2.org/libgit2/#HEAD/group/repository/git_repository_open
12:44:49FromDiscord<rakgew> @demotomohiro are you the author of\:↵https://internet-of-tomohiro.netlify.app/nim/clibrary.en.html↵by any chance? that was very helpful for me!!
12:47:13FromDiscord<mratsim> mmmh, the forum search / user history doesn't allow me to find this thread because it only display 10 results: https://media.discordapp.net/attachments/371759389889003532/1009080893220069426/unknown.png
12:49:53FromDiscord<demotomohiro> In reply to @rakgew "<@288750616510201856> thanks for the": That is the case @domosokrat said.
12:50:47FromDiscord<demotomohiro> In reply to @rakgew "<@288750616510201856> are you the": Yes. I'm glad to help you.
12:52:13FromDiscord<mratsim> sent a long message, see http://ix.io/47Lp
12:52:41FromDiscord<demotomohiro> In reply to @Girvo "Anyone have suggestions for": https://github.com/jangko/msgpack4nim↵msgpack is binary, space effient and there is pure Nim library.
13:02:23FromDiscord<Rika> In reply to @EyeCon "No direct Nim support": https://git.sr.ht/~ehmry/nim_cbor
13:03:15FromDiscord<Rika> also pure nim iirc
13:03:40FromDiscord<Rika> its "json but binary, but also better than bson"
13:05:10FromDiscord<EyeCon> In reply to @Rika "https://git.sr.ht/~ehmry/nim_cbor": Ah, thanks, now that you mention it I think I saw this implementation but it was lacking something, can't remember exactly what it was
13:30:48*gsalazar quit (Read error: Connection reset by peer)
13:31:00*gsalazar joined #nim
13:32:00ehmrynim_cbor has a wierd interface, I'm not sure how people use cbor in practice
13:33:27ehmryEyeCon if you remember what it was let me know
13:33:28FromDiscord<Rika> i used it before; ended up changing most of the library anyway xd never upstreamed it because i never finished changing it
13:33:42FromDiscord<Rika> sorry i also forgot what changes i needed
13:35:01ehmryseems like whenever you are using cbor you want some application specific optimizations
13:50:25ehmrythe proper thing to do would be a CDDL to Nim code generator, which I would do if there where more CDDL schemas
13:54:22FromDiscord<Rika> does that stand for "common data description language" or smth
13:54:25FromDiscord<Rika> close
13:54:34FromDiscord<Rika> concise data definition language
14:12:23FromDiscord<EyeCon> In reply to @ehmry "EyeCon if you remember": Sure, I'll take a look again
14:15:07FromDiscord<EyeCon> ehmry: Based on how I used CBOR in a toy project, can it be that it doesn't serialize/unserialize objects directly (a la jsony)?
14:15:44FromDiscord<EyeCon> That's how I planned to use CBOR anyway
14:17:42*jkl quit (Ping timeout: 268 seconds)
14:18:03*jkl joined #nim
14:23:28PMunchHuh, I've been considering to write a small program which can add files and webpages to a taskwarrior task and allow me to open those things automatically. Lo and behold I did some googling and someone had already written such a tool, and it's written in Nim!
14:23:32PMunchhttps://github.com/jschlatow/taskopen
14:28:25*arkurious joined #nim
14:30:32FromDiscord<Rika> nice
14:34:36*PMunch quit (Quit: Leaving)
14:36:23FromDiscord<rakgew> sent a code paste, see https://paste.rs/Chg
14:41:42FromDiscord<rakgew> sent a code paste, see https://play.nim-lang.org/#ix=47LZ
14:44:24FromDiscord<rakgew> is ther clever way to turn it into array of strings?
14:45:27FromDiscord<mratsim> In reply to @rakgew "is ther clever way": Whats the type of ``strings`` ?
14:45:34FromDiscord<rakgew> when I `echo tag_list.strings[]` it gives me\: "v0.1.0"↵but shoud there not be all tags?
14:46:20FromDiscord<rakgew> type of strings is\: `ptr cstring`
14:47:16FromDiscord<rakgew> but I hoped I could find all tags in there and just need to split with special char.. (?)
14:48:34FromDiscord<mratsim> sent a code paste, see https://play.nim-lang.org/#ix=47M2
14:50:08FromDiscord<mratsim> In reply to @rakgew "when I `echo tag_list.strings[]`": you probably wrapped it wrong
14:50:21FromDiscord<rakgew> @mratsim thanks so much! will try.. (I never implemented an itertor in nim but I m sure I can find info on that in the docs)
14:50:54FromDiscord<rakgew> well it is wrapped by nimgit2 via nimterop
14:54:11FromDiscord<mratsim> sent a code paste, see https://play.nim-lang.org/#ix=47M5
14:54:48FromDiscord<rakgew> amazing! thanks heaps!!
14:54:52FromDiscord<mratsim> Be sure to properly allocate and deallocate the memory to store the cstring
14:55:35FromDiscord<rakgew> will try! \:-D
14:57:35*kenran joined #nim
14:59:07*kenran quit (Client Quit)
15:11:02FromDiscord<rakgew> sent a code paste, see https://paste.rs/l5c
15:12:19FromDiscord<rakgew> are there now 2 versions of git\_strarray with the same name?
16:11:07FromDiscord<ezquerra> Would it be possible to have something akin to Python's breakpoint() keyword, which would make gdb pause whenever the keyword is used? I've been trying to use gdb to debug some nim code and I was not able to do it because gdb only knows about the compiled nim code
16:11:23FromDiscord<ezquerra> I find that debugging is one of the weakest parts of the "nim experience"
16:13:15FromDiscord<ezquerra> Or maybe it is just that I don't have things setup correctly 😅
16:16:49FromDiscord<auxym> yeah tooling for nim in general (including debugging) isn't it's strong point
16:17:23FromDiscord<ezquerra> In an ideal world I'd be able to just create a breakpoint in VSCode, start a debug session and the program would pause when the breakpoint is hit, showing all the nim variable names (not the translated C ones) in the VSCode debugger
16:18:22FromDiscord<auxym> I'm not aware of anything like python's breakpoint statement, but gdb is pretty powerful, you can set breakpoints in a startup file. I think the saem nim extension for vscode supports debugging now, too? I wasn't able to get it working though
16:19:14FromDiscord<Rika> nim has a gdb wrapper
16:19:26FromDiscord<ezquerra> But I would settle for something less fancy, like creating breakpoints using an explicit breakpoint() call which would pause the program and maybe drop me into some kind of basic (nim) "repl" which would let me echo the list of variables that are in scope with their values or something like that
16:19:31FromDiscord<Generic> it only works with gc ref though if, on those days where it decides to work at all
16:19:43FromDiscord<Generic> do you compile with --debugger:native?
16:19:52FromDiscord<ezquerra> I did that
16:20:01FromDiscord<ezquerra> Then I ran gdb myprogram.exe
16:20:20FromDiscord<ezquerra> But I did not know how to set a breakpoint based on the nim filename and line number
16:20:40FromDiscord<Generic> weird, did you try a few different locations
16:22:31FromDiscord<Generic> ?
16:22:57FromDiscord<Rika> have you seen this
16:22:58FromDiscord<Rika> https://internet-of-tomohiro.netlify.app/nim/gdb.en.html
16:23:10*Jjp137 quit (Ping timeout: 244 seconds)
16:28:25FromDiscord<ezquerra> I did not know about that
16:34:54FromDiscord<ezquerra> sent a long message, see http://ix.io/47MA
16:43:09FromDiscord<domosokrat> That sounds like a gdb without python support.
16:43:59FromDiscord<domosokrat> But I have no idea where to find one with it for windows
17:04:14FromDiscord<rakgew> yay - I was able to solve the git\_strarray from earlier with a snippet from gittyup lib\:↵`echo "[INFO]: ", cstringArrayToSeq(cast[cstringArray](tag_list.strings), tag_list.count)`↵with that it nicley lists all the git tags into a cstring seq. \:-D
17:08:59*jmdaemon joined #nim
17:28:41*pro joined #nim
17:37:18FromDiscord<ezquerra> The gdb that I am using is the one that is part of the windows nim distribution, so I would expect it to work well with the nim-gdb.py script?
17:38:16*pro quit (Quit: pro)
17:43:49FromDiscord<domosokrat> I would have expected that too.↵(@ezquerra)
17:48:59*xet7 joined #nim
17:49:15FromDiscord<ezquerra> In any case, I just gave it a try on a Linux system. In there nim-gdb fails because it cannot find nim-gdb.py. It looks for it on /home/ezquerra/.nimble/tools/nim-gdb.py, but there is no tools folder under .nimble. Instead I can find the file in /home/ezquerra/.choosenim/toolchains/nim-1.6.6/tools/nim-gdb.py
17:50:37FromDiscord<ezquerra> sent a long message, see http://ix.io/47MW
17:50:53FromDiscord<ezquerra> However, I can still not set breakpoints by referencing the nim source files
17:52:53*rockcavera joined #nim
17:52:53*rockcavera quit (Changing host)
17:52:53*rockcavera joined #nim
17:58:01FromDiscord<ezquerra> Are people just using echo for debugging?
17:59:51FromDiscord<Rainbow Asteroids> pros use `stdout.write`
18:03:40FromDiscord<ezquerra> In most cases when I am debugging all I want is to be able to see or explore the values of the variables that are in scope on a certain location. Is there a way to do that with a macro, for example?
18:05:35FromDiscord<domosokrat> There is dump in the sugar module
18:06:01FromDiscord<domosokrat> Ah, you want all, I guess.
18:06:06FromDiscord<ezquerra> Yeah, but you must manually dump the vars you are interested in
18:06:07FromDiscord<ezquerra> yeah
18:06:20FromDiscord<domosokrat> Ignore my answer then
18:06:23FromDiscord<ezquerra> That is the most basic feature of a debugger
18:06:59FromDiscord<ezquerra> Can a macro get the list of the variables that can be accessed from the current scope?
18:09:31FromDiscord<domosokrat> I just tried nim-gdb. I can set breakpoints for nim files.
18:10:56FromDiscord<Phil> .... You can?
18:11:06FromDiscord<Phil> As in, you can inspect the value stuff has at a given time?
18:11:13FromDiscord<Phil> Like java debugger breakpoints?
18:12:00FromDiscord<Phil> In reply to @ezquerra "Are people just using": Someone who jumped into nim from higher level languages: Yes, that is my debugging way of life, though mostly less debugging and more logging
18:12:19FromDiscord<Phil> Which amounts to the same in the end but the latter one has a fancy framework attached!
18:13:24FromDiscord<domosokrat> @ezquerra\: I don't know about java debugger breakpoints. But inspecting variables works, e.g. via `info locals`
18:13:25FromDiscord<Phil> (edit) "Someone" => "As someone"
18:13:32FromDiscord<Prestige> In reply to @Isofruit "As in, you can": I can as well
18:13:45FromDiscord<Phil> wild, I'll need to look into that
18:14:03FromDiscord<domosokrat> sorry, should have tagged @Phil
18:14:32FromDiscord<Phil> I assume demo has a guide for that?
18:16:32FromDiscord<Phil> He does! Sweet↵Thanks @demotomohiro
18:25:44FromDiscord<ezquerra> In reply to @domosokrat "<@974046326088163438>\: I don't know": How can I use info locals if I cannot set a breakpoint?
18:27:14*xaltsc quit (Ping timeout: 255 seconds)
18:28:08*xaltsc joined #nim
18:28:24FromDiscord<ezquerra> In reply to @Isofruit "Which amounts to the": I think logging has its place, but an using an actual debugger can help a lot in many cases
18:28:53FromDiscord<domosokrat> The thing is, for me something like `break five_clique.nim:115` works↵(@ezquerra)
18:33:25*Jjp137 joined #nim
18:37:18FromDiscord<ezquerra> In reply to @domosokrat "The thing is, for": Umm, I just recompiled and tried again (on Linux) and it worked!
18:37:30FromDiscord<ezquerra> It is probably not the recompilation but something that I was doing wrong before
18:39:57FromDiscord<ezquerra> So this seems better than I thought :). However, it does not work out of the box on Linux, and it does not seem to work at all on Windows :/
18:51:07FromDiscord<krisppurg> sent a code paste, see https://play.nim-lang.org/#ix=47Ni
18:59:08FromDiscord<Kermithos> are you on windows?
19:01:07FromDiscord<domosokrat> are you using openssl3? nim currently does not work with openssl3
19:11:31*PMunch joined #nim
19:45:48*kenran joined #nim
19:49:18FromDiscord<erde74> sent a code paste, see https://play.nim-lang.org/#ix=
20:27:06FromDiscord<Bung> whats this meaning in c `sizeof(IOleObject )`
20:35:05ehmryEyeCon: I may have done that already https://git.sr.ht/~ehmry/nim_cbor/commit/c7c3ae0d9c82c7bcffbb919abd0fcc4992110770
20:42:53*niminal joined #nim
20:42:59*kenran quit (Quit: WeeChat info:version)
20:43:20FromDiscord<Elegantbeef> It gets the size of a pointer↵(@Bung)
20:44:08FromDiscord<Bung> but pointer size is constant ?
20:44:42FromDiscord<Bung> int32 or int64 depends on arch
20:44:58FromDiscord<Elegantbeef> Yes?
20:45:03FromDiscord<Elegantbeef> They get the size of a pointer from that
20:45:41FromDiscord<Elegantbeef> It my be the size of the struct, but no clue it's ambiguous
20:46:45FromDiscord<Prestige> I would think that means the size of the pointer, but I don't know all of C's weirdness
20:46:48FromDiscord<Bung> dont know, first time see at end
20:47:25FromDiscord<Elegantbeef> If `IOleObject` is a typedef'd pointer it could be dereferencing it
20:48:09FromDiscord<Bung> so its dereferencing and size of struct
20:48:17FromDiscord<Elegantbeef> No clue
20:48:25FromDiscord<Elegantbeef> C is a very ambiguous language
20:48:42FromDiscord<domosokrat> definitely size of a pointer to IOleObject
20:49:29FromDiscord<domosokrat> dereferencing would be sizeof(\ IOleObect) and only if IOleObject is a valirable
20:49:47FromDiscord<domosokrat> variable
20:50:21FromDiscord<Prestige> Yeah..
20:50:21FromDiscord<Elegantbeef> I figured as much but i never remember dereferencing properly or how C's sizeof works
20:50:31FromDiscord<Prestige> could also test it out if you weren't sure, I suppose
21:03:24*PMunch quit (Quit: leaving)
21:20:11qwrC is pretty straightforward, pointer type is totally separate from the pointed type, whatever it happens to be, so sizeof pointer gives the pointers size, usually 4 on 32-bit platforms and 8 on 64-bit platforms
21:21:26qwronly weirdness is imho, that sizeof operator works both on values and (types)
21:22:13FromDiscord<Generic> that's useful because there's no way in C to get the type of a value
21:22:14FromDiscord<Elegantbeef> I dont think the latter part is that weird
21:38:40*dnh quit (Quit: Textual IRC Client: www.textualapp.com)
21:55:16*niminal quit (Ping timeout: 268 seconds)
22:19:08*djanatyn1 is now known as djanatyn
23:19:00*rockcavera quit (Read error: Connection reset by peer)
23:19:19*rockcavera joined #nim
23:19:19*rockcavera quit (Changing host)
23:19:19*rockcavera joined #nim