<< 29-12-2022 >>

00:08:35*ltriant quit (Ping timeout: 260 seconds)
00:11:26*rockcavera quit (Read error: Connection reset by peer)
00:11:46*rockcavera joined #nim
00:11:46*rockcavera quit (Changing host)
00:11:46*rockcavera joined #nim
00:12:12FromDiscord<djazz> sent a code paste, see https://play.nim-lang.org/#ix=4jPF
00:12:21*tiorock joined #nim
00:12:21*tiorock quit (Changing host)
00:12:21*tiorock joined #nim
00:12:21*rockcavera quit (Killed (tantalum.libera.chat (Nickname regained by services)))
00:12:21*tiorock is now known as rockcavera
00:12:32*ltriant joined #nim
00:12:34FromDiscord<djazz> use uint you say? 😅
00:17:28FromDiscord<djazz> ah I see now
00:25:13*PMunch quit (Quit: leaving)
00:35:59*jmdaemon joined #nim
00:49:06FromDiscord<T0lk1en> What’s up bros
01:01:03*derpydoo quit (Ping timeout: 256 seconds)
01:10:39*ltriant quit (Ping timeout: 260 seconds)
01:32:45FromDiscord<jvsg> unrelated. But does anyone know of good chatroom/forum on canada based programmers or tech professionals?
01:33:08FromDiscord<jvsg> \<insert leaf joke here\>
02:29:42FromDiscord<Elegantbeef> Well if you want tech unprofessionals i'm here
03:13:57*ltriant joined #nim
03:19:05*ltriant quit (Ping timeout: 268 seconds)
03:30:01*ltriant joined #nim
03:52:14*rockcavera quit (Ping timeout: 260 seconds)
04:03:21*zkv joined #nim
04:03:28zkvHi *
04:07:42*rockcavera joined #nim
04:10:19*ltriant quit (Ping timeout: 260 seconds)
04:16:47FromDiscord<sOkam!> sent a code paste, see https://play.nim-lang.org/#ix=4jQa
04:33:03FromDiscord<Rika> Make the operators yourself
04:33:18FromDiscord<Rika> Personally I would rather and not over the symbols
04:34:06*arkurious quit (Quit: Leaving)
04:34:09FromDiscord<Rika> Maybe something in the bit ops module would be much better than either
04:34:25FromDiscord<Rika> Lots of “mask” “flip” kinds of procedures there
04:34:27FromDiscord<Rika> https://nim-lang.org/docs/bitops.html
04:45:14*zkv quit ()
04:52:31FromDiscord<sOkam!> sent a code paste, see https://play.nim-lang.org/#ix=4jQd
04:52:59*wallabra quit (Ping timeout: 264 seconds)
04:53:16*wallabra joined #nim
04:53:39*ltriant joined #nim
05:01:22FromDiscord<sOkam!> sent a code paste, see https://paste.rs/562
05:05:38FromDiscord<Elegantbeef> Yea though the C is faster
05:09:22FromDiscord<sOkam!> faster in which way?
05:09:39FromDiscord<sOkam!> data accessing, or just in the generation?
05:10:19FromDiscord<sOkam!> its only run once on loading... so if its faster just for generation, then the C version can go f itself
05:11:07FromDiscord<sOkam!> if its faster for data reading, then I might need a different approach, possibly?
05:12:01FromDiscord<Elegantbeef> Nim 0s the memory and then you add to a sequence which has checks and increments the len
05:12:51FromDiscord<sOkam!> i was thinking of setting the values with `result.data[cluster] = 255`
05:13:27FromDiscord<Elegantbeef> I mean it's minor and likely wont matter 😄
05:13:33FromDiscord<Elegantbeef> `newSeqWith` might be faster
05:14:26FromDiscord<amadan> sent a code paste, see https://play.nim-lang.org/#ix=4jQl
05:14:54FromDiscord<Elegantbeef> Yea it would
05:15:30*ltriant quit (Ping timeout: 272 seconds)
05:16:42FromDiscord<sOkam!> i'm still hella confused by the rounding up to 32 part of the C code ⚰️
05:24:20*ltriant joined #nim
05:25:19FromDiscord<sOkam!> Oh, I saw something by accident with some code I wrote for echoing what the processing is doing↵Seems like `1672`, the clusterCount, is being rounded up to `1696` 🤔 ↵So the whole thing might just be asking to allocate a size enough to fit the data, and some padding to align to 32bits, and have nothing to do with the data itself (what i thought)
06:05:35*ltriant quit (Ping timeout: 268 seconds)
06:19:51FromDiscord<sOkam!> can you free a ref before the gc does it?↵also, is it worth doing that at all, or should just ignore it?
06:43:20*rockcavera quit (Remote host closed the connection)
06:45:50FromDiscord<Elegantbeef> You cannot manually free GC types
06:46:06FromDiscord<Elegantbeef> You can do `GcRef` and `GcUnref` with a `GCFullCollect` but that's not really freeing it before the gc
06:46:12FromDiscord<Elegantbeef> That's just helping the GC along
07:21:34FromDiscord<Phil> Alright, back up again.↵What is the second node of a proc definition?↵I've stared at a simple one, but there the node at index "1" is just an empty node
07:21:43FromDiscord<Phil> I know the first one is the proc's name
07:24:05FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jQL
07:24:12*ltriant joined #nim
07:25:13FromDiscord<Phil> (edit) "https://play.nim-lang.org/#ix=4jQL" => "https://paste.rs/NHc"
07:27:43FromDiscord<Phil> Argh, that's actually defined in the docs, found it
07:28:14FromDiscord<Phil> Wait, that makes no sense
07:28:27FromDiscord<Elegantbeef> `name constraint, generic, args, pragma, body, result sym`
07:29:06FromDiscord<Elegantbeef> `proc a{t}[T](t: int): T {.cdecl.} = echo "Hello"`
07:29:20FromDiscord<Elegantbeef> that's basically the most loaded a procedure can be it should fill every slot
07:31:07FromDiscord<Elegantbeef> Think there are some reserved slot
07:32:03FromDiscord<Phil> The above proc has 8 nodes though, you described 7, is one of thw two emptyNodes still undescribed?
07:32:13FromDiscord<Phil> Because nnkAsgn I think is the body, so the newSymNode is the result sym I think
07:32:22FromDiscord<Elegantbeef> Correct
07:32:30FromDiscord<Elegantbeef> I think there is a reserved or deprecated position
07:33:04FromDiscord<Phil> That's index 5 then
07:34:12FromDiscord<Phil> sent a long message, see http://ix.io/4jQN
07:34:41FromDiscord<Phil> Glimpse in the doc confirms that 5 is just reserved for future use
07:53:20*ltriant quit (Ping timeout: 255 seconds)
07:54:00FromDiscord<Phil> In reply to @Elegantbeef "Correct": Okay, so what is this check here:↵`procs[1].sameType(a.getType())`↵Shouldn't index 1 be stuff for term rewriting for macros and templates? Why does it matter?
07:55:36FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jQR
07:55:51FromDiscord<Elegantbeef> should check the params
07:56:16FromDiscord<Elegantbeef> `procs[1]` isnt a proc it's a stmtlist of `generatedPointerProc, ... argument type`
07:56:31FromDiscord<Elegantbeef> We arent using a proc we're using our own ast there
08:00:42FromDiscord<Phil> Ohhh so what you're doing is you're instantiating a version of the generic proc first via `myProc`, which you can then set via `setMyProc`
08:00:52FromDiscord<Phil> (edit) "a" => "an explicit"
08:03:02FromDiscord<Elegantbeef> Correct
08:06:16FromDiscord<Elegantbeef> What's actually going on is on first call we instantiate a pointer proc and point it to a anonymous version of the source proc, then in future calls that's what we refer to
08:06:20*wallabra_ joined #nim
08:06:23FromDiscord<Phil> sent a long message, see http://ix.io/4jQS
08:06:48FromDiscord<Elegantbeef> `myProc` is `testProc` in this case
08:06:57FromDiscord<Elegantbeef> or `genericOtherProc`
08:07:04*wallabra quit (Ping timeout: 268 seconds)
08:07:15FromDiscord<Phil> Aye, I'd want to mock `genericOtherProc` and only test code in `testProc` in this example
08:07:16*wallabra_ is now known as wallabra
08:07:18FromDiscord<Elegantbeef> Basically for generics we replace the procedure with a macro and a `set` macro
08:08:03*ltriant joined #nim
08:08:05FromDiscord<Phil> I'll have to first wrap my head around this and then try out my scenario because if that works it feels kinda wild
08:09:19FromDiscord<Phil> As that would mean nim somehow figured out that it needed to first do the `myProc` calls in my test to generate the necessary procs, then link those mock-procs to when they're called in `ModuleUnderTest.testProc`
08:09:42FromDiscord<Elegantbeef> It's not somehow
08:09:47FromDiscord<Elegantbeef> You're literally replacing the proc for a macro
08:10:14FromDiscord<Elegantbeef> The `when false` branch of the code i provided would've been the source procedure
08:12:45*ltriant quit (Ping timeout: 260 seconds)
08:13:36*lucerne joined #nim
08:14:19FromDiscord<Phil> I think I'll continue this when I understand more about the code, diving back into it
08:14:50FromDiscord<Elegantbeef> The idea is that the `mock` macro would generate the else branch of that code example
08:15:07FromDiscord<Phil> But the mock macro needs to be called first
08:15:40FromDiscord<Elegantbeef> Yes?
08:15:52FromDiscord<Phil> And `ModuleUnderTest.testProc` expects one of the procs that the generated `mock` macro will generate to be there
08:16:23FromDiscord<Elegantbeef> You annotate your generic proc with mock
08:16:47FromDiscord<Elegantbeef> It checks if it's generic, if it is not it emits a normal pointer proc, otherwise it emits this macro mess
08:17:21*lucerne quit (Remote host closed the connection)
08:21:13FromDiscord<Phil> sent a code paste, see https://paste.rs/SBX
08:21:34FromDiscord<Elegantbeef> correct
08:21:48FromDiscord<Phil> So there would already be references to actually generated `toString` procedures floating around that `testProc` can link to, they're just... nil or sth?
08:21:49FromDiscord<Elegantbeef> Though i dont think `macro toString[T](x: T)` compiles 😄
08:22:22FromDiscord<Elegantbeef> The first call would instantiate and add a pointer proc to the cache table
08:22:23FromDiscord<Elegantbeef> Well cacheseq
08:22:43FromDiscord<Elegantbeef> That pointer proc then would be accessible across your project and interacted with using `setToString`
08:26:15FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jQV
08:26:38FromDiscord<sOkam!> how do you check if a seq if currently empty, in comparison with it having just one item at index 0?
08:27:08FromDiscord<sOkam!> does len == 0 mean that?
08:27:11FromDiscord<Phil> Could you rephrase that?
08:27:18FromDiscord<Phil> len == 0 means no item in seq at all
08:27:28FromDiscord<sOkam!> its probably a stupid question, but i always get lost in the stupid dum things 😔
08:27:37FromDiscord<Phil> if you have an item in a seq at index 0 it has len == 1
08:28:03FromDiscord<sOkam!> kk, was probably confusing id0 with len0 being the same thing, but they arent. tyty
08:28:17FromDiscord<Phil> I am as confused as I was before, but happy to have helped
08:30:43FromDiscord<Elegantbeef> I guess it doesnt really matter↵(@Phil)
08:31:09FromDiscord<Elegantbeef> It could just be `result.add newCall(sym, ...args)`
08:31:23FromDiscord<Elegantbeef> Yes i'm using python syntax as pseudo code
08:31:56FromDiscord<Elegantbeef> The reason that code existed the way it did was due to having `result = newStmtList()` inside the case where we dont have a pointer proc existing
08:32:53FromDiscord<Phil> ` result.add newCall(sym, a)`↵Can not confirm that this works, the if else solution appears to be more correct
08:33:20FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4jQW
08:33:30FromDiscord<Elegantbeef> Well do `result = newStmtList()`
08:33:38FromDiscord<Elegantbeef> and remove the present `result = newStmtList()`
08:33:40FromDiscord<Elegantbeef> it'll certainly work
08:33:44*ltriant joined #nim
08:34:59FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4jQY
08:36:50FromDiscord<Elegantbeef> I assume you've looked at the generated AST for the code
08:37:19FromDiscord<Phil> Somewhat, mostly at the AST within generatedProcs
08:37:36FromDiscord<Phil> And noticed that the AST in there appears to just be the ways that the macro was invoked or sth
08:38:02FromDiscord<Elegantbeef> It's the ast we made
08:38:28FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4jQZ
08:38:41FromDiscord<Elegantbeef> it should be `newStmtList(sym, args)`
08:38:54FromDiscord<Elegantbeef> where args is all of your procedure's arguments
08:39:16FromDiscord<Phil> Ohhhh we fill that seq as part of the proc that generates procs (or doesn't)
08:39:25FromDiscord<Elegantbeef> Correct
08:39:30FromDiscord<Elegantbeef> We're making our own instantiation table
08:39:45FromDiscord<Elegantbeef> the first node is the pointer proc's symbol
08:39:56FromDiscord<Elegantbeef> The following is each argument
08:40:09FromDiscord<Elegantbeef> This allows us to type check later when we invoke this and generate a pointer proc
08:40:28FromDiscord<Elegantbeef> We're practically doing generic instantiations
08:40:45FromDiscord<Elegantbeef> This will get more complicated of course
08:40:58FromDiscord<Elegantbeef> Since you will need to replace all symbols that are the parameters with new parameter symbols
08:42:13FromDiscord<Elegantbeef> In the new generated procedure
08:42:13FromDiscord<Elegantbeef> Though i think they're idents since it's generic so it might be fine
08:42:17FromDiscord<Phil> I'll likely fail, but I can try. I already got a basic truth of macros ingrained in me as part of the learning process:↵Each syntax construct has a fixed pattern of Nodes that describe what it does.
08:42:30FromDiscord<Elegantbeef> Yep
08:42:42FromDiscord<Elegantbeef> Once you learn it's not completely arbitrary it makes life easier
08:43:01FromDiscord<Phil> That was something I didn't know before, for example. And the macro docs define for a lot (I assume not all) of the language constructs what these patterns look like
08:43:20FromDiscord<Elegantbeef> I mean to be fair you shouldnt need to know any of this
08:43:24FromDiscord<Elegantbeef> It's fucking inane that you do
08:43:49FromDiscord<Phil> And its also important that any node is either: EmptyNode or the actual node intended to be there
08:43:58FromDiscord<Phil> (edit) "And its also important that any node is either: EmptyNode or the actual node ... intended" added "with the kind"
08:44:16FromDiscord<Elegantbeef> This is why i really like the premise of micros, it doesnt labour you with the actual AST
08:45:01FromDiscord<Elegantbeef> You have a `routineNode` you can just do `.name` and get the name of it, want the parameters you do `.params` want to add a parameter you just do `.add identDef(ident"hello", int)`
08:45:35FromDiscord<Phil> In reply to @Elegantbeef "It's fucking inane that": I mean, at this point I'm only like 20% convinced I'll actually achieve what I want before I hit something that makes me want to declare "this is not good enough for the user, so not worth it", but learning about macros along the way in general is nice.
08:46:10FromDiscord<Phil> In reply to @Elegantbeef "You have a `routineNode`": So basically you use the type-system to enshrine that static node pattern?
08:46:19FromDiscord<Elegantbeef> Yes
08:46:35FromDiscord<Phil> Comprehension has started to unfold
08:47:53FromDiscord<Phil> What does getType actually return? I see the docs on it and it returns question marks to me.↵Like, just the actual typedesc of a type inside of a node?
08:48:08FromDiscord<Phil> Trying to wrap my head around `procs[1].sameType(a.getType())`
08:51:50FromDiscord<Phil> ... Can you use options in macros?
08:52:02FromDiscord<Phil> Nah, unlikely, nevermind
08:56:22FromDiscord<Phil> Also, what is `procs[0]`.↵It points to a SymNode `newSymNode("myProc"),`↵But the SymNodes in `CacheSeq` all look like this, do they have different IDs and can be differentiated based on that?
08:56:33FromDiscord<Elegantbeef> For instance
08:56:37FromDiscord<Elegantbeef> I dont know i might be crazy
08:56:39FromDiscord<Elegantbeef> If you can guess what that does without any comments or me explaining i'll give you 10 imaginary points 😛
08:56:42FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4jR3
08:57:06FromDiscord<Elegantbeef> it is the macro version of `typeOf`
08:57:21FromDiscord<Phil> Bridge may be dying unless you posted that actually 09:56 ETC
08:57:26FromDiscord<Elegantbeef> Oh jeez bridge moment 😄
08:57:34FromDiscord<Phil> Check, ok lets see
08:58:14FromDiscord<Elegantbeef> Yes it points to that SymNode, it's our proc table
08:58:59FromDiscord<Elegantbeef> Actually this makes me wonder.... we might be able to use `sameType` on the sym instead of carrying the parameters around
08:59:18FromDiscord<Elegantbeef> Do you have the link to this on playground?
08:59:58FromDiscord<Elegantbeef> Ah nvm it's in my history
09:01:21*pro joined #nim
09:02:04*ltriant quit (Ping timeout: 252 seconds)
09:07:44FromDiscord<dizzyliam [they/them]> Just realised that what I'm making is basically isomorphic JS but with Karax
09:07:47FromDiscord<dizzyliam [they/them]> Isomorphic Nim?
09:08:32FromDiscord<Elegantbeef> @Phil\: https://play.nim-lang.org/#ix=4jR8 a more sensible approach for the setter
09:08:52FromDiscord<Elegantbeef> And also a bit more sensible for the `var sym = ...`
09:15:33FromDiscord<HitBlast> Why am I getting a type mismatch using options here? https://media.discordapp.net/attachments/371759389889003532/1057949985410404363/Screenshot_2022-12-29_at_3.14.57_PM.png
09:15:51FromDiscord<Elegantbeef> The first tuple is `(string, string, string)`
09:16:01FromDiscord<Elegantbeef> you want `some("test")` or `some"test"`
09:16:49FromDiscord<HitBlast> oh alright
09:32:11FromDiscord<HitBlast> sent a code paste, see https://play.nim-lang.org/#ix=4jRc
09:34:42FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jRd
09:34:48FromDiscord<Phil> Is this to generate partial types from larger overencompassing types?
09:35:03*ltriant joined #nim
09:35:34FromDiscord<Elegantbeef> Yes
09:35:47FromDiscord<Elegantbeef> `fields` can have multiple names cause of `a, b: int` being valid
09:35:50FromDiscord<Phil> (edit) "https://play.nim-lang.org/#ix=4jRd" => "https://paste.rs/MzV"
09:35:58FromDiscord<Elegantbeef> that's not converted by the compiler to multiple defs, it's a single def
09:36:09FromDiscord<Phil> No wait, the new type name is "PickedName" I forgot that that was the name of the node created in the beginning
09:36:47FromDiscord<Elegantbeef> https://github.com/beef331/micros/blob/master/tests/t_tsinspiredmacros.nim actualy code is here so you can see it's usage
09:37:16FromDiscord<Elegantbeef> `typedesc` can have a field iterator btw
09:37:19FromDiscord<Elegantbeef> It's not magic
09:37:50FromDiscord<Elegantbeef> It's just that it only makes sense for like `(int, int)` cause it requires compiler magic otherwise
09:37:53FromDiscord<Phil> Why doesn't it then? All this time I had to do `T().fields` or `T()[].fields` in my generics when wanting to iterate over the fields of a typedesc
09:38:21FromDiscord<Elegantbeef> Well it'd require magic to work the same there
09:38:30FromDiscord<Elegantbeef> But anyway that's my own `fields` iterator
09:39:07FromDiscord<Phil> I do agree its pretty readable
09:42:46*ltriant quit (Ping timeout: 272 seconds)
09:43:12FromDiscord<Phil> Can I access the name of a macro from within said macro?
09:43:28FromDiscord<Elegantbeef> `bindSym"MyMacroName"`
09:43:30FromDiscord<Elegantbeef> Otherwise no
09:43:58FromDiscord<Phil> Hmm mostly wanted to get rid of "myProc" in `symbol = gensym(nskVar, "myProc")`
09:44:26FromDiscord<Phil> I guess I could add the proc name as value of the `mockable` pragma
09:47:17FromDiscord<Elegantbeef> I mean mockable would generate this
09:47:17FromDiscord<Elegantbeef> So you'd have that proc's name
09:54:54FromDiscord<Phil> How do I access the generic proc I just replaced and its intended body etc.?
09:54:55*ltriant joined #nim
09:55:15FromDiscord<Phil> Wait, I can look at the first iteration of the mockable pragma
09:55:56FromDiscord<Elegantbeef> well `proc myProc(a: SomeInteger){.mock.} = echo a` should generate the above
10:01:08*ltriant quit (Ping timeout: 272 seconds)
10:03:32FromDiscord<Phil> sent a long message, see http://ix.io/4jRn
10:03:51FromDiscord<Elegantbeef> mock generates that macro
10:03:57FromDiscord<Elegantbeef> the when else was to show the input vs. output
10:05:41FromDiscord<Phil> I think you lost me
10:06:16FromDiscord<Elegantbeef> the branch that is `when false` in my code is to show the procedure that was annotated with `{.mock.}`
10:06:58FromDiscord<Elegantbeef> The else branch is code your macro generates when mock is enabled and you hit a generic procedure
10:07:05FromDiscord<Elegantbeef> Yes you're generating a macro from a macro
10:07:11FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jRo
10:07:24FromDiscord<Elegantbeef> Correct you need to change mock
10:07:30FromDiscord<Phil> Ah, check, so I need to replace the when-else inside, check
10:07:41FromDiscord<Elegantbeef> Indeed
10:07:44FromDiscord<Phil> The else branch stays the same I assume
10:08:03FromDiscord<Phil> As in, the else branch in mock should be `result = p` either way
10:08:07FromDiscord<Elegantbeef> Yes
10:08:13FromDiscord<Elegantbeef> Yep
10:08:22FromDiscord<Elegantbeef> In the case you arent mocking you dont change anything
10:09:40FromDiscord<Elegantbeef> This should make 1000 times more sense now 😛
10:11:01FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jRp
10:11:25FromDiscord<Elegantbeef> Look at my more recent link
10:11:30FromDiscord<Elegantbeef> I provide a more sensible solution
10:12:01FromDiscord<Phil> You mean the more recent play nim lang link, or the micros link?
10:12:08FromDiscord<Elegantbeef> nim lang
10:12:33FromDiscord<Phil> That piece of code stems from that link https://media.discordapp.net/attachments/371759389889003532/1057964331104485426/image.png
10:12:51FromDiscord<Elegantbeef> Yes look at line 8 and 21
10:13:09FromDiscord<Phil> Ohhhh wait, I see
10:13:21FromDiscord<Elegantbeef> We still emit a generic proc
10:14:50FromDiscord<Phil> I can save myself the assignment to MyProcBase because that's `p` I think
10:15:03FromDiscord<Elegantbeef> You still need to emit the procedure
10:15:06FromDiscord<Phil> So all I need should be line 21 with `p` for `MyProcBase`
10:15:09FromDiscord<Elegantbeef> Or want to
10:15:16FromDiscord<Elegantbeef> this way you can reset the procedure
10:15:17FromDiscord<Phil> Ah, hmm
10:15:45FromDiscord<Elegantbeef> The smarter thing to do now that i think about it is to just forward the parameters
10:16:13FromDiscord<Elegantbeef> So you generate `var sym = someMacroThatGetsTheProcType(myProcBase(a))`
10:16:49FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4jRq
10:16:49FromDiscord<Phil> I don't follow that fast, I'm still trying to wrap my head around how to do this expression `proc myProcBase(a: SomeInteger) = echo a` inside of the pragma without hard-coding the parameters, nor the body
10:18:34*ltriant joined #nim
10:18:54FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4jRs
10:19:16FromDiscord<Elegantbeef> All we're doing is copying the proc and changing the name
10:19:23*wallabra quit (Ping timeout: 264 seconds)
10:23:38FromDiscord<Elegantbeef> Anyway i'm off, so hopefully you can work through this
10:23:56*ltriant quit (Ping timeout: 272 seconds)
10:24:48FromDiscord<Phil> I'll need to take my time to digest this either way so I'll need the time ^^
10:26:14*PMunch joined #nim
10:54:32*ltriant joined #nim
10:59:44*ltriant quit (Ping timeout: 268 seconds)
11:08:47FromDiscord<luteva> how can i get the length (number of bytes in memory) of an object?
11:09:36PMunchsizeof?
11:10:30FromDiscord<luteva> i yes, thx! i tried "len" but not sizeof 😄
11:13:54PMunchLen is typically used for "count of items" and sizeof is "number of bytes"
11:14:12PMunchThose might be the same, e.g. for an array of uint8s
11:18:03Amun-Rais it possible to pass openarray as static to function and have compile time array length?
11:18:42PMunchNot 100% sure what you mean here
11:19:29Amun-RaI'd like to use array.len in when clause
11:19:34Amun-Raec
11:20:50prowhy only 4 days of aoc PMunch ?
11:21:42Amun-RaPMunch: something like this: https://play.nim-lang.org/#ix=4jRC
11:21:44PMunchI did 6, but Christmas was busy this year..
11:23:31proindeed it was
11:23:36PMunchDamn, those videos have more views than I imagined
11:24:08FromDiscord<Phil> How do I take a look again at the nim code that is generated?
11:24:15FromDiscord<Phil> Not the ast, the nim code
11:24:27PMunchI was thinking of doing a "Let's see how many days I can get through in one sitting" thing
11:25:07PMunchBut I've got a sore throat at the moment, so it'll have to wait a bit
11:25:35PMunch@Phil, repr?
11:26:54FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jRD
11:27:00FromDiscord<luteva> @Phil the ast is generated by the code. not the code from the ast. i am not sure if this is possible.
11:27:29FromDiscord<Phil> Argh, would've been nice to see, well time to get more used to reading AST then
11:29:39FromDiscord<Phil> TIL that the result symbol can also be straight up left out of a proc definition
11:29:45FromDiscord<Phil> (edit) "definition" => "definition's AST"
11:29:56FromDiscord<luteva> there's no single way to generate source code from the ast. it is ambiguous. so generating source code from the ast is not a common usage.
11:29:58FromDiscord<Phil> So a proc-AST can contain of 7 or 8 nodes
11:30:04FromDiscord<Phil> (edit) "contain" => "consist"
11:36:53FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jRH
11:37:09FromDiscord<Phil> (edit) "https://paste.rs/8vp" => "https://play.nim-lang.org/#ix=4jRI"
11:37:29PMunch@Phil, echo result.repr?
11:37:48PMunchOr of course --expandMacro:mock
11:39:04FromDiscord<Phil> sent a code paste, see https://paste.rs/ZrR
11:39:37PMunchThen that's the result of your macro..
11:40:26FromDiscord<Phil> Which means the macros that the macro should be generating and that should be called in place of the actual generic function, aren't being generated
11:41:36PMunchYeah if it's not in the result, it's not being returned
11:41:40FromDiscord<Phil> Because I shoooouuuld be getting the output of `proc myProc(a: int) = echo "Walumba"`
11:42:04PMunchIsn't that what you got?
11:42:17FromDiscord<Phil> That was a mistake on my end, copy pasted the wrong thing
11:42:22FromDiscord<Phil> Edited above, I get a: SomeInteger
11:42:39PMunchHmm, edits don't do well over the bridge either..
11:42:45PMunchThey've gotten better though
11:42:58FromDiscord<Phil> Correction here
11:42:59FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jRJ
11:43:17FromDiscord<Phil> So if I want to generate a macro from a macro
11:43:37FromDiscord<Phil> Do I have to... return that macro somehow?
11:43:47PMunchOf course
11:43:48FromDiscord<Phil> There is no way I can turn a macro into a node and add that to a statement list
11:43:50FromDiscord<Phil> That sounds insane
11:44:11PMunchHaha, you'd be surprised
11:44:32FromDiscord<Phil> ... I'll try then... errr is there a special thingy to convert a macro into a NimNode?
11:44:40PMunchquote do?
11:45:39FromDiscord<Phil> Okay the mystical ways of quote do are getting confusing, time to read up on it
11:48:22FromDiscord<Phil> Okay so it's basically another way of copy-pasting sort-of
11:48:29FromDiscord<Phil> Copy-pasting something and getting it turned into an ast
11:48:48PMunchWell not so much copy-pasting as a more convenient way to create an AST
11:52:48FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jRL
11:53:31FromDiscord<Phil> (edit) "https://paste.rs/jsa" => "https://paste.rs/Xoc"
11:55:08FromDiscord<Phil> Staring at this code I once more feel like that can't be possible.↵If I call this multiple times I'm generating multiple `var myProc` variables, just with different types... is that doable? Feels like it isn't
11:55:33FromDiscord<Phil> (edit) "variables," => "variables (as per the `var symbol = (proc(arg: typeof(a)))(copyProc)` statement) ,"
11:59:35PMunchNot sure what copyProc does..
11:59:40PMunchSo hard to tell
11:59:53FromDiscord<Phil> copyProc is just a copy of the initial proc you pass in
11:59:57PMunchYou shouldn't create multiple variables with the same name
12:00:06PMunchThat's a bad idea
12:00:26FromDiscord<Phil> the only difference is that it gets renamed to "mockedProc", so that the original definition no longer exists
12:00:57FromDiscord<Phil> `myProc` as a macro replaces it and shall be called implicitly instead of the original proc. The `copyProc` used in there is supposed to be a capture of the `copyProc` at the start
12:03:28PMunchNot entirely sure what you're trying to do here
12:03:53PMunchWhy are you going through a macro?
12:06:32FromDiscord<Phil> The ultimate problem I'm trying to solve:↵The original macro that I had (which replaces a proc declaration with a proc assignment along the lines of `var <ProcName> = (<procParams>) => <procBody>` so you can re-assign the proc-body in tests.↵↵Now naturally that fails for generics because generics aren't actual normal procs.
12:08:18FromDiscord<Phil> So the idea is to replace the proc definition with a macro of the same name (in this example the inner `MyProc` macro, that name I'll have to somehow generate or something later, not sure). When the "original" code thus calls the generic proc, they're instead calling the macro.↵↵That should generate the proc they are actually trying to call (and store the generated procs in a cache to avoid generating the same procs multiple times).
12:08:51FromDiscord<Phil> And at this point I feel like I'm halfway along the way of batshit insane solutions
12:09:50FromDiscord<Phil> Anyway, as far as I understand it (which is not fully understanding it at all), it still generates a kind of "var" assignment?
12:10:05FromDiscord<Phil> Though how that can possibly work I don't know
12:11:24PMunchHmm, it shouldn't generate a var assignment
12:12:04FromDiscord<Phil> isn't that what the genast at the end does?
12:12:13FromDiscord<Phil> As kind of the weirdest sort of macro-function-call thing I've seen today?
12:18:19PMunchAh I've never used genAst, but it appears to be a version of quote do
12:19:17PMunchOr rather it appears to do something similar, but in a slightly different way
12:46:46FromDiscord<Phil> sent a long message, see https://paste.rs/OPZ
12:47:05FromDiscord<Phil> It's not the fact that there are multiple identical symbols floating around that's illegal, it's having assignments being ambiguous that's illegal
12:48:00FromDiscord<Phil> I haven't even been awake 6 hours and my brain already feels semi-fried
12:48:43FromDiscord<voidwalker> you have mocked your brain
12:49:15FromDiscord<Phil> At some points, my mocks started mocking me
12:49:37FromDiscord<voidwalker> I've no idea what those are, so this whole dialogue is even more hilarious to watch : D
12:50:17FromDiscord<voidwalker> mock proc.. pretend proc ?
12:51:22FromDiscord<Phil> At least pretend proc hasn't been used yet
12:51:26FromDiscord<Phil> So I'm good on that one
12:51:31FromDiscord<Phil> Only copyProc and mockProc
12:51:57FromDiscord<Phil> the first of which is a modified copy of the initial Proc and the latter something used to replace the original proc for mocking purposes
12:53:19FromDiscord<untoreh> sent a code paste, see https://paste.rs/KLU
12:53:49FromDiscord<untoreh> (edit) "https://play.nim-lang.org/#ix=4jRY" => "https://paste.rs/125"
12:55:55*ltriant joined #nim
12:59:36FromDiscord<Phil> I'm not aware of that pragma, it's also not documented as far as I can see
13:00:17FromDiscord<Phil> Kind of wild and looks like the kind of thing I wouldn't recommend
13:00:32*ltriant quit (Ping timeout: 252 seconds)
13:18:02PMunchI think that's from a library you've imported
13:18:55PMunchAh, never mind
13:19:24FromDiscord<luteva> how can i get the byte(-sequence) representation of an object?
13:24:45PMunchDefine representation
13:29:12FromDiscord<untoreh> sent a code paste, see https://play.nim-lang.org/#ix=4jS2
13:30:21PMunchYou can just do: cast[array[sizeof(A), byte]](a)
13:30:35PMunchHmm, this partial thing is really strange..
13:31:47FromDiscord<untoreh> it doesn't work within macro and templates
13:32:05FromDiscord<luteva> castarray??
13:32:31FromDiscord<luteva> (edit) "castarray?? ... " added "does this exist?"
13:32:54FromDiscord<luteva> or is it cast(array[sizeof(A), byte])
13:33:00FromDiscord<untoreh> yes just avoid the pointer
13:33:23FromDiscord<luteva> ok thx folks!
13:33:29FromDiscord<luteva> gonna try this.
13:33:39PMunchWait, did the bridge strip my square brackets?
13:34:34FromDiscord<untoreh> this is what it forwarded "castarray[sizeof(A), byte]"
13:35:47PMunch...
13:38:49FromDiscord<Smarc> var x = {'a' .. 'z'} creates a set that contains a-z char's. is there a way to automatically create a seq the same way using the `..` operator?
13:39:23PMunchThe partial pragma seems to have been part of a feature Araq worked on back in 2017, which have since been laid by the wayside..
13:50:02FromDiscord<Phil> In reply to @Smarc "var x = {'a'": Best I can do you is the toSeq proc
13:51:20FromDiscord<Phil> Currently on phone so I can't write examples, but shouldn't be too hard. Either it works with the range directly (surrounded by round brackets) or on the set you're currently creating
13:52:54PMunchOkay these partial objects are seriously weird
13:54:39PMunchTake this code: http://ix.io/4jS9. The object that Nim outputs to the C file has a Foo object with both y and z fields. But curiously the dollar procedure for Foo only transforms y, because Nim generated that when Foo didn't yet have the z field.
13:58:41PMunchHmm, this is actually a pretty cool feature
14:00:26PMunchAaand I broke it :P
14:00:45PMunchApparently it didn't like to add a field in a proc..
14:01:38PMunchIt's pretty brittle
14:08:20NimEventerNew thread by sls1005: Extracting multiple base types on FFI, see https://forum.nim-lang.org/t/9776
14:16:09*jmdaemon quit (Ping timeout: 252 seconds)
14:19:46*ltriant joined #nim
14:24:34*ltriant quit (Ping timeout: 260 seconds)
14:30:17PMunchHmm, I'm trying to read and write to stdin and stdout of a process I've started, but at some point readLine just seem to hang..
14:36:22termerif it's not a ref or pointer, then it's on the stack
14:36:29termeroops I replied to an old message
14:42:14FromDiscord<HitBlast> sent a long message, see https://paste.rs/xhq
14:42:35FromDiscord<HitBlast> (edit) "http://ix.io/4jSo" => "https://paste.rs/g6k"
14:43:54PMunchWhy wouldn't it be able to be converted to UTF-8?
14:54:13*arkurious joined #nim
15:01:23FromDiscord<jtv> HitBlast, strings are always stored in UTF-8, so it's a matter of whether the string consists of valid UTF-8 or not
15:02:17FromDiscord<jtv> sent a code paste, see https://paste.rs/mg6
15:02:34FromDiscord<jtv> If it's invalid, it'll return you the first invalid byte position
15:08:05FromDiscord<jtv> In reply to @PMunch "Hmm, I'm trying to": It depends, but it's possible that stdin and stdout are buffered and the process has exited.
15:17:15adigitoleoQuick question: I'm trying to understand the `ord(getch())` mapping, what scancode numbering is being used by nim here?
15:28:01FromDiscord<jtv> In reply to @adigitoleo "Quick question: I'm trying": Do you mean, how does nim map characters to numbers?
15:28:26adigitoleoOh I see, it's ASCII printable
15:28:30FromDiscord<jtv> It's the international Unicode standard... the numbers are called 'codepoints' by Unicode
15:28:59FromDiscord<jtv> For the ascii characters, it's all the same
15:29:15FromDiscord<jtv> In Nim, when working with codepoints, the language uses the term 'Rune'
15:32:21adigitoleoah yeah no worries, got confused by a unicode table that was using hex numbering
15:32:41*russell_ joined #nim
15:36:41*junaid_ joined #nim
15:43:01adigitoleojust to clarify further, at the low level keyboard input goes: scancode -> keycode -> codepoint? Am I understanding the names right?
15:49:57FromDiscord<jtv> At the OS-level yes, but there's generally not going to be a context where you're going to get the scancode or keycode
15:56:14adigitoleoOK just checked, I get the same codes in the linux console as in my GUI terminal, nice. Was paranoid that it would't be portable.
16:11:00*azimut joined #nim
16:20:51FromDiscord<ShalokShalom> Google makes their own Nim
16:20:54FromDiscord<ShalokShalom> https://github.com/google/rune
16:24:54FromDiscord<⚶ Zeno> Hey people, what does it mean when i get "cannot evaluate at compile time" errors ?↵↵I am trying to make something akin of python's `struct` module https://media.discordapp.net/attachments/371759389889003532/1058058036977086594/image.png
16:38:56FromDiscord<albassort> In reply to @⚶ Zeno "Hey people, what does": You aren't sure that v has that proc
16:39:00FromDiscord<albassort> So you can't evaluate it at run time
16:39:09FromDiscord<albassort> You need to make sure that v has []
16:39:12FromDiscord<albassort> So you want to make a concept for it
16:39:26FromDiscord<⚶ Zeno> i see
16:40:13FromDiscord<⚶ Zeno> and how would i go doing that ? i want dynamic sized data structure that allows multiple types in it, which i know is tuple, but when i do `v: tuple[T]` it just gives expected : or = error and it gives "expected ..." for those https://media.discordapp.net/attachments/371759389889003532/1058061891588604054/image.png
16:40:54FromDiscord<⚶ Zeno> (i know they are invalid format and stuff, but i just wrote them quickly to make sure things are working)
16:41:26FromDiscord<albassort> Or something
16:41:27FromDiscord<albassort> sent a code paste, see https://play.nim-lang.org/#ix=4jSU
16:41:32FromDiscord<albassort> I'm not on my computer to actually get code for you
16:41:37FromDiscord<albassort> But that's the general path. I'm sure it doesn't file
16:41:44FromDiscord<albassort> (edit) "file" => "compile"
16:41:48FromDiscord<albassort> I believe in you
16:42:18FromDiscord<⚶ Zeno> yea i'll try to figure it out by those, thanks for leading me
16:42:38FromDiscord<albassort> However, I guarantee you this is an itertools
16:42:50FromDiscord<albassort> A nimble package which has a lot of pythons weird generators
16:43:20FromDiscord<⚶ Zeno> that is fine for me, i just care about stuffs working for now in order to increase my experience on nim as im new to it
16:43:32FromDiscord<⚶ Zeno> thanks m8
16:47:48FromDiscord<planetis> m8 you mean this https://github.com/OpenSystemsLab/struct.nim ?
16:48:28FromDiscord<⚶ Zeno> i know that one, but i was planning to make my own to increase experience on nim
16:49:31*rockcavera joined #nim
16:50:17FromDiscord<planetis> I see the error is typical, you can't iterate tuples with a runtime index
16:50:42FromDiscord<planetis> your best bet is to use something like fields/fiedPairs iterator
16:51:17FromDiscord<@thatrandomperson5-6310e3b26da03> i get type mistmatch for `int` when it only accepts `sink T`. Can someone please explain this?
16:52:56FromDiscord<planetis> it should work, share your code
16:55:39FromDiscord<@thatrandomperson5-6310e3b26da03> > it should work, share your code↵Gitter breaks code or whatever so here it is raw\:
16:55:50FromDiscord<@thatrandomperson5-6310e3b26da03> sent a code paste, see https://play.nim-lang.org/#ix=4jT1
16:56:59FromDiscord<planetis> In reply to @⚶ Zeno "i know that one,": btw I like where your going with it, the other one uses runtime strings and a struct node tree. It can be done with macros
16:59:03FromDiscord<mattrb> sent a code paste, see https://play.nim-lang.org/#ix=4jT3
16:59:30FromDiscord<planetis> In reply to @@thatrandomperson5-6310e3b26da03 "> it should work,": the answer should be in the encode function signature/body if that's where the error comes from
17:02:14FromDiscord<@thatrandomperson5-6310e3b26da03> The error is on the third line.↵(@planetis)
17:04:06FromDiscord<⚶ Zeno> In reply to @planetis "your best bet is": i see, thanks
17:04:13FromDiscord<planetis> then result is not a seq[int] ?
17:05:05FromDiscord<⚶ Zeno> In reply to @planetis "your best bet is": i guess that will suffice for time being
17:05:31FromDiscord<⚶ Zeno> thanks again, also thanks to albassort
17:05:58FromDiscord<albassort> I think the problem is you just need to think more statically
17:06:19FromDiscord<albassort> When you tell the compiler T, you're not telling it anything besides that, that perimeter has a type
17:06:41FromDiscord<albassort> And so since a type has no inherent properties, you can't do anything with it
17:07:06FromDiscord<⚶ Zeno> yeah, thats the problem, im more used to python, and i mostly think those codes in python-way
17:07:15FromDiscord<albassort> So, you need to specify so to compiler knows it has a certain attributes
17:07:25FromDiscord<albassort> In reply to @⚶ Zeno "yeah, thats the problem,": In Python, python doesn't care even if you type it
17:07:31FromDiscord<⚶ Zeno> yup
17:07:44FromDiscord<albassort> Even if you say this is X-Type which has no [] it'll still throw no error
17:07:58FromDiscord<albassort> So lol You got to get used to the more strict typing
17:08:11FromDiscord<⚶ Zeno> yessir
17:11:19FromDiscord<planetis> In reply to @mattrb "Any idea why https://github.com/mattrberry/gba": Is casting the issue though? In v2 a lot changed, for example threads:on by default. This is my config https://github.com/planetis-m/raylib-examples/blob/main/core/basic_window_web.nims that works but also check treeform's tutorial
17:13:26FromDiscord<mattrb> sent a code paste, see https://play.nim-lang.org/#ix=4jT9
17:15:30FromDiscord<planetis> since compilation fails at C step then better open an issue.
17:15:42FromDiscord<mattrb> I can work around it by updating `loop` to take a void pointer and just casting it to a `GBA` ref object, but I'm guessing I'm just misunderstanding something that's changed
17:16:38FromDiscord<mattrb> I tried to reproduce in a minimal example so that I could open an issue, but the minimal case wasn't able to reproduce it :/ I guess I'll just start deleting things until it works to try to create an example that way
17:23:02NimEventerNew thread by Araq: Roadmap 2023, see https://forum.nim-lang.org/t/9777
17:24:58FromDiscord<mattrb> Hmm, seems like it's actually an issue with emcc..
17:26:29FromDiscord<planetis> btw I don't even cast to that type, I have emscripten 3.1.26 installed in arch linux
17:26:29FromDiscord<Patitotective> In reply to @Elegantbeef "<@762008715162419261>\: did you make": it worked on my windows machine 🤷
17:26:33FromDiscord<mattrb> Not sure what's causing the problem though.. Guess I'll just do the workaround for now and let it be..
17:32:58FromDiscord<⚶ Zeno> even though i did it in worst way possible, i managed to do the I (although i cant do unsigned because of direct type moments, but that is fine)↵↵🥳 https://media.discordapp.net/attachments/371759389889003532/1058075166355247147/image.png
17:33:17FromDiscord<⚶ Zeno> (edit) "I" => "`I`"
17:41:57FromDiscord<Smarc> how do i check two seq's of integers for duplicates? is there a better way than for-looping every item?
17:45:30FromDiscord<Smarc> or use `contain` on every item. is there a cooler nim-way?
17:53:02*PMunch quit (Quit: leaving)
17:56:17systemdsucksuse a set?
18:01:58FromDiscord<Smarc> and then?
18:03:21FromDiscord<jtv> Sets will never keep more than one copy of an item
18:08:22*junaid_ quit (Remote host closed the connection)
18:11:43FromDiscord<⚶ Zeno> sent a long message, see http://ix.io/4jTr
18:12:14FromDiscord<⚶ Zeno> (edit) "http://ix.io/4jTr" => "https://paste.rs/dzD"
18:13:08FromDiscord<jtv> Note that there are two different kinds of sets, the default are bit fields, which are going to be limited in range. std/set is based on hashing, so if you don't have a fairly tight range of values is more flexible (but less efficient)
18:15:09FromDiscord<planetis> for ints there is std/packedsets
18:15:10FromDiscord<cow> I think I found a potential bug in the sequtils, (https://play.nim-lang.org/#ix=4jTt), I do not have a github account to open an issue though... could someone look at it?
18:15:21FromDiscord<cow> (edit) "it?" => "it please?"
18:17:46FromDiscord<planetis> works if I remove import sequtils
18:17:48FromDiscord<cow> from what I see, insert can't deduce the type of @[] (it is ambiguous technically), however I think it could be disambiguated the other way, because the current behavior is a noop
18:18:18FromDiscord<jtv> Agreed, it's something odd about sequtils, works w/o the import
18:18:18FromDiscord<cow> In reply to @planetis "works if I remove": yes, because sequtils implements insert(seq[T], seq[T], int), while system implements insert(T, seq[T], int)
18:18:22*krux02 joined #nim
18:18:38FromDiscord<cow> so if both inserts exist a @[] can be either T or seq[T]
18:18:44FromDiscord<cow> with nested seqs
18:19:16FromDiscord<jtv> Still I'd expect a static error if it can't infer the type.
18:20:11FromDiscord<cow> is there an official way of reporting bugs that doesn't require a github account
18:20:38FromDiscord<jtv> No :/
18:21:05FromDiscord<jtv> If I remember when I'm in front of a computer I'll report it if you like
18:21:18FromDiscord<cow> i would appreciate that, thanks
18:21:22*ltriant joined #nim
18:22:22FromDiscord<HitBlast> In reply to @jtv "If it's invalid, it'll": I'm working with strings of different languages and locales. Could you please explain a bit more about how I could check if a string is in valid UTF-8 in real-time?
18:23:23FromDiscord<jtv> All languages and locales will use Unicode to map characters. UTF-8 UTF-16 and UTF-32 are three different ENCODINGS
18:23:27FromDiscord<jtv> Of unicode
18:23:33FromDiscord<cow> In reply to @HitBlast "I'm working with strings": unicode has an isValidUTF8 proc
18:23:51FromDiscord<jtv> So, if you're not on Windows, UTF-8 is the most common encoding by far
18:24:05FromDiscord<cow> if you are getting the info byte by byte and you don't know if the text is over, I would suggest to look at its source code (it's 15 lines or so) and reimplement with streaming support
18:24:10FromDiscord<jtv> And any string that makes it into Nim would be UTF-8 encoded by default
18:24:36FromDiscord<jtv> Via any typical way to get data in (esp reading a file)
18:25:15FromDiscord<cow> i thought nim's strings were just a resizeable char array with length and encoding agnostic
18:25:22FromDiscord<jtv> UTF-16 is really only used on Windows, and UTF-32 is almost never used in user-exposed contexts
18:26:00FromDiscord<jtv> That is also true, but they can hold any encoding, and so if strings put into it were put in as utf-8 they are still utf-8
18:26:18FromDiscord<cow> i wonder if you do a file.readAll() on a UTF16, what happens
18:26:23FromDiscord<jtv> Which is why all you have to do is run that check to see if it's valid utf-9
18:26:27FromDiscord<cow> (edit) "UTF16," => "UTF16 file,"
18:26:32*ltriant quit (Ping timeout: 272 seconds)
18:26:43FromDiscord<jtv> I am pretty sure Nim converts it to utf-8 based on my reading of the docs
18:26:55FromDiscord<cow> that's sane indeed
18:26:56FromDiscord<jtv> But haven't looked at the implementation
18:27:02FromDiscord<cow> but it would be nice to know where
18:27:16FromDiscord<jtv> It's easy enough to test
18:27:36FromDiscord<cow> fair, i'll come back to it when i have time maybe
18:27:48FromDiscord<cow> i gtg unfortunately
18:39:07*rockcavera quit (Ping timeout: 260 seconds)
18:42:35*russell_ quit (Remote host closed the connection)
19:41:05*krux02 quit (Remote host closed the connection)
19:41:51*krux02 joined #nim
19:49:31FromDiscord<Guhnoo> i'm having some bother figuring out pointers, or the Nim equivalent. in go, you use `&varName` to assign the address, then `varName` to dereference. how is this done in Nim? i've looked at the reference and pointers section of the Nim manual but it's not clicking. i'm wanting to create an alias to a value in a sequence once i've read in a csv file so that i can use `pId` as a pointer to `p.row[0]`'s
19:49:38FromDiscord<Guhnoo> (edit) "`p.row[0]`'s" => "`p.row[0]`"
19:51:11*azimut quit (Ping timeout: 255 seconds)
19:51:31*jmdaemon joined #nim
19:51:37FromDiscord<ezquerra> I just saw Araq’s nim 2023 roadmap forum post. I’m very happy to see that the focus of nim 2.2 will be tooling and IC in particular!
19:52:25FromDiscord<ezquerra> A question about that though: is the —ic:stress just a way to (stress) test the IC feature?
19:52:56FromDiscord<ezquerra> That is, I understand that nim users will not normally need to use that flag and will just get IC by default?
19:53:59*derpydoo joined #nim
19:55:26NimEventerNew thread by yister: Downloading files with missing protocol in redirect url, see https://forum.nim-lang.org/t/9778
19:55:50FromDiscord<ShalokShalom> @ezquerra afaik, there are already improvments to the IC, who are merged and unreleased
19:56:01FromDiscord<ShalokShalom> Maybe I am wrong about this, Beef knows more
19:56:58FromDiscord<ezquerra> In reply to @ShalokShalom "<@974046326088163438> afaik, there are": In the 2.0 RC? If so, how do you enable IC? I didn’t o i.e. that IC was something that could already be enabled…
19:57:58FromDiscord<ShalokShalom> Ping Beef
19:58:05FromDiscord<ShalokShalom> If you are brave enough 😛
19:58:24FromDiscord<ShalokShalom> Or maybe ask in #internals
20:13:30FromDiscord<cow> In reply to @Guhnoo "i'm having some bother": you can dereference using `[]`, get the address of things using `addr`, or you also have pointer types for example `ptr int`...↵I'm not familiar with Go, could you maybe provide an example that I could write up for you?
20:14:09FromDiscord<jtv> ptr types are really about objects from the foreign function interface that the GC isn't managing
20:14:30FromDiscord<cow> it doesn't have to be FFI related
20:14:32FromDiscord<jtv> Getting refs via addr() and then getting back the value via [] is what you want
20:14:57FromDiscord<jtv> Sure, but it's the primary use case
20:17:02FromDiscord<cow> also, you don't need to do `[][x]` when indexing, if you index it already dereferences with `[x]`, same with accessing fields of objects, the `.` dereferences
20:17:40FromDiscord<cow> but if you are trying to call a function with the special `.` syntax sugar, you do need to dereference youself (unless the function takes the `ref` type as the argument)
20:17:56FromDiscord<cow> i think i am explaining stuff more confusing than it is
20:18:12FromDiscord<jtv> Yup. This is one of the many areas where the documentation is a bit too sparse though,
20:18:28FromDiscord<Guhnoo> thank you, my mistake was trying to do it with `ref`
20:19:00FromDiscord<Guhnoo> swapped with `ptr` and is working
20:19:05FromDiscord<cow> In reply to @jtv "Yup. This is": yeah definitely, I remember struggling with understanding ref syntax at first
20:19:34FromDiscord<cow> In reply to @Guhnoo "thank you, my mistake": can we look at the code? maybe we can give additional advice
20:19:39FromDiscord<jtv> I think the reason is that addr() actually gives you a pointer (can be dangled), not a ref
20:19:49FromDiscord<cow> yeah addr gives a ptr
20:20:13FromDiscord<jtv> You only get refs if you declare the type to be refs I do believe
20:21:08FromDiscord<cow> idk, if I use addr, it's in codebases where I use ptr, malloc, etc. rather than ref's 😅
20:21:51FromDiscord<cow> (edit) "😅" => "😅, so haven't encountered that corner yet"
20:22:05FromDiscord<jtv> But you can do things like `var s1, s2: ref string` and then you can alias between them
20:22:20FromDiscord<jtv> And the GC tracks it
20:24:15FromDiscord<Guhnoo> In reply to @cow "can we look at": it's incredibly basic stuff. i'm reading in a csv, mutating the sequence, and writing it out. i've been doing it with go, just wanted to try it with nim
20:24:20FromDiscord<cow> I just haven't found myself needing `addr` in code where i use `ref`s
20:25:29FromDiscord<Guhnoo> i just thought the pointers made sense for readability, rather than using `p.row[x]` everywhere
20:26:01FromDiscord<jtv> Well, you can do it that way for sure
20:26:20FromDiscord<jtv> Just not very idiomatic for Nim
20:27:28FromDiscord<cow> I usually do a template if I have this problem
20:27:55FromDiscord<cow> sent a code paste, see https://play.nim-lang.org/#ix=4jTW
20:28:06FromDiscord<jtv> Yeah same, templates (and macros) are awesome for factoring out code that's very repetitive to write
20:28:46FromDiscord<cow> but i guess a pointer works too
20:28:57FromDiscord<cow> as long as the pointer doesn't outlive the content
20:29:25FromDiscord<cow> (edit) "https://play.nim-lang.org/#ix=4jTW" => "https://play.nim-lang.org/#ix=4jTX"
20:29:36FromDiscord<cow> sent a code paste, see https://paste.rs/0TH
20:30:46FromDiscord<Guhnoo> i haven't gone as far as templates and macros yet. i'm not a software guy, i just script stuff for administration mostly
20:31:10FromDiscord<cow> you can also do it with a function
20:31:30FromDiscord<cow> sent a code paste, see https://play.nim-lang.org/#ix=4jU1
20:32:07FromDiscord<cow> it returns a value that can be assigned to
20:32:22FromDiscord<cow> (edit) "to" => "to, I believe"
20:35:55*pro quit (Quit: pro)
20:40:23FromDiscord<Guhnoo> wow, templates are really neat
20:40:55FromDiscord<Guhnoo> never used anything like that before
20:43:18FromDiscord<Guhnoo> it just knows what `p` is outside the scope
20:47:41FromDiscord<Guhnoo> cool stuff, thanks for that
20:59:30FromDiscord<cow> just beware, it doesn't work the other way by default
20:59:45FromDiscord<cow> this is not gonna work https://media.discordapp.net/attachments/371759389889003532/1058127203310784532/image.png
21:03:38FromDiscord<cow> (you can do this as a side note https://nim-lang.org/docs/manual.html#templates-symbol-binding-in-templates, good to know it exists, but tbh i've never used it) https://media.discordapp.net/attachments/371759389889003532/1058128183108583424/image.png
21:04:19FromDiscord<cow> templates are as if their own scope
21:05:16FromDiscord<cow> (edit) "scope" => "scope, but they have inject which can make them do stuff like that↵(inject only exists within templates)"
21:11:05*wallabra joined #nim
21:21:06*ltriant joined #nim
21:25:43*ltriant quit (Ping timeout: 260 seconds)
21:44:17*ltriant joined #nim
22:01:33*ltriant quit (Quit: leaving)
22:02:07*ltriant joined #nim
22:24:00FromDiscord<@thatrandomperson5-6310e3b26da03> I don’t think it’s where the error comes from, any more ideas?
22:25:23*rockcavera joined #nim
22:27:56FromDiscord<voidwalker> blah, I spent the whole day trying to debug one thing : (
22:28:21FromDiscord<voidwalker> ` if asocket.hasDataBuffered:` can anyone explain why this condition wouldn't pass, I am sure there is data to read
22:28:34FromDiscord<voidwalker> is it the same as "there is data received in socket" ?
22:39:05FromDiscord<Smarc> sent a code paste, see https://play.nim-lang.org/#ix=4jUt
22:39:09FromDiscord<Smarc> gives me 418, which is too low
22:39:14FromDiscord<Smarc> where is my thinking mistake?
22:39:44FromDiscord<Elegantbeef> Why are you using a set?
22:40:29FromDiscord<Smarc> so i can use intersection
22:40:37FromDiscord<Smarc> to easily spot overlaps
22:40:48FromDiscord<Elegantbeef> A set isnt needed for this problem a `Slice[int]` works
22:41:06FromDiscord<Smarc> hm, could you give me an example?
22:42:28FromDiscord<Elegantbeef> https://github.com/beef331/nimtrest/blob/master/aoc2022/day4/day4.nim for a spoiler
22:42:39FromDiscord<jtv> @voidwalker Sockets are a bit complicated, so some more context would be helpful
22:43:08FromDiscord<voidwalker> sent a code paste, see https://play.nim-lang.org/#ix=4jUx
22:43:30FromDiscord<Smarc> In reply to @Elegantbeef "https://github.com/beef331/nimtrest/blob/master/aoc": ye .. i really don't understand that example :s
22:43:32FromDiscord<voidwalker> (edit) "https://play.nim-lang.org/#ix=4jUx" => "https://play.nim-lang.org/#ix=4jUy"
22:43:59FromDiscord<voidwalker> sent a code paste, see https://play.nim-lang.org/#ix=4jUz
22:44:29FromDiscord<jtv> I assume the sockets are setup to be non-blocking? Are they AF_INET sockets?
22:44:40FromDiscord<voidwalker> I have this in a while true loop.. messages get parsed okay, except when I get a big data message, for some reason it does not get past the if socket.hasDataBuffered
22:45:06FromDiscord<Elegantbeef> A slice is a `start..end`
22:45:16FromDiscord<voidwalker> just default settings async socket
22:45:23FromDiscord<voidwalker> TCP
22:45:53NimEventerNew thread by Nlits: Type mistmatch for `int` and `sink T`, see https://forum.nim-lang.org/t/9779
22:46:12FromDiscord<Smarc> In reply to @Elegantbeef "A slice is a": but isnt that what i am doing? Just as a set so i can use the interlacing/ operator?
22:46:23FromDiscord<Elegantbeef> You just wan `in`
22:46:26FromDiscord<Elegantbeef> `a in start..end`
22:46:28FromDiscord<jtv> I only know the posix API, haven't done any nim async stuff yet, so I'd have to dig in to figure out what's going on under the hood. Generally if you might handle more than a connection or two at once, it's good to use at least select() and preferably epoll()
22:46:38FromDiscord<jtv> I do know Nim has a nice epoll wrapper I saw recently
22:47:24FromDiscord<voidwalker> I've no idea about select() and epoll(). why would I need them ?
22:47:25FromDiscord<Smarc> In reply to @Elegantbeef "`a in start..end`": hm i guess I still struggle to understand what you actually mean .. sorry :s
22:47:40FromDiscord<jtv> std/selectors
22:47:48FromDiscord<voidwalker> Yeah I will handle thousands of connections at once.. one day : )
22:48:04FromDiscord<jtv> The whole idea is, for the sake of scaling, you register which file descriptors might eventually have data to read,
22:48:32FromDiscord<jtv> And then the polling code tells you when there's something ready to read, far more efficiently than looping through all your fds
22:48:48FromDiscord<voidwalker> oh is that true.. I see
22:49:03FromDiscord<voidwalker> I thought this epoll/select thing was kinda old/deprecated with async sockets
22:49:04FromDiscord<jtv> And, honestly, once you master the APIs, it's far less error prone
22:49:27FromDiscord<Elegantbeef> Smarc the day doesnt require a set it just requires overlap ranges
22:49:48FromDiscord<Elegantbeef> You dont care whether it has 3, 4, 5
22:49:51FromDiscord<voidwalker> welp, atm it seems I am far from mastering even simple socket code :\
22:49:52FromDiscord<Elegantbeef> you know it's 3..5
22:49:52FromDiscord<jtv> Couldn't possibly be. While I haven't looked at the async implementation in Nim, it'd be foolhardy not to leverage the OS to tell you what's ready to read
22:50:30FromDiscord<jtv> Socket code has ALWAYS been complicated in any language, which is why so much of the world leverages high-level abstractions like HTTPS
22:52:03*ltriant quit (Ping timeout: 252 seconds)
22:52:16FromDiscord<Smarc> In reply to @Elegantbeef "you know it's 3..5": but then I'd had to check every number of 1 range for every other number of the other range, right?
22:52:31FromDiscord<voidwalker> so, back to my question: `asocket.hasDataBuffered` - I know for sure I received data, using wireshark. but this condition is not passed for some reason, and my program gets stuck there
22:52:35FromDiscord<Elegantbeef> It's a continous range
22:52:50FromDiscord<Elegantbeef> You only care where end/start
22:53:28*ltriant joined #nim
22:56:27FromDiscord<Elegantbeef> you know whether `2-4` is in `6-8` if `2 > 6` or `4 < 6`
22:57:06FromDiscord<Elegantbeef> You know whether a range is fully encapsulated if `2 > 6 and 4 < 8`
23:15:46FromDiscord<voidwalker> any idea how much data can be stored in socket without reading it, before it gets lots ?
23:21:02*ltriant quit (Ping timeout: 272 seconds)
23:25:00FromDiscord<voidwalker> well, fixed my bug.. got rid of the socket.peek logic
23:25:13FromDiscord<jtv> That's good, sorry I was afk
23:25:30FromDiscord<voidwalker> for some reason the data is gone at some point with the peek flag set on
23:25:41FromDiscord<voidwalker> doesn't read anything, although there should be data to read
23:25:47FromDiscord<voidwalker> I think there's a bug somewhere
23:26:12FromDiscord<jtv> Well, I don't know the API, but I suspect peek() removes it from the OS's buffer and buffers it in userland
23:26:42FromDiscord<voidwalker> it's all poorly documented : (
23:26:46FromDiscord<voidwalker> especially for a noob
23:27:16FromDiscord<jtv> That's currently true most of Nim right now, unfortunately :/
23:28:17FromDiscord<jtv> I've already seen people at work who on paper should love the language bounce quickly, and it's been a combo of docs and the tooling ecosystem
23:29:06FromDiscord<jtv> That's definitely a shame, as it's a truly awesome language in so many respects
23:29:59FromDiscord<voidwalker> Indeed, and what's the deal with the documentation generated from the source code file
23:30:40FromDiscord<jtv> I mean, I think that's the excuse for not documenting better. Too many people are too happy to just move on to the next feature, and I 100% get that
23:30:47FromDiscord<jtv> I'm kind of that way too, often
23:30:53FromDiscord<voidwalker> I am supposed to commit changes on github on the .nim core files to get better docs?
23:31:17FromDiscord<jtv> I was thinking if I get time I might produce some external HOWTOs basically
23:31:30FromDiscord<voidwalker> we need something like the arch wiki
23:31:38FromDiscord<voidwalker> cause nim is the archlinux of programming : P
23:31:45FromDiscord<jtv> Heh 🙂
23:32:10FromDiscord<Tony Rubak> if I have some framed data in a string that I've read through, for example, `body = socket.recv(content_length)`, and I know that bytes 2 and 3 are a `uint16`, how do I actually turn the slice `body[1..2]` into the data I want?
23:32:21FromDiscord<voidwalker> I am sure the community will produce a great documentation in no time, in wiki style
23:32:36FromDiscord<voidwalker> just like they producer many better alternative libs to stdlib
23:32:41FromDiscord<voidwalker> (edit) "producer" => "produced"
23:36:32FromDiscord<voidwalker> @Tony Rubak good question... you can use either copymem, a serialize/deserialize lib like binarylang (overkill for just this small use)
23:38:00FromDiscord<Tony Rubak> sent a code paste, see https://play.nim-lang.org/#ix=4jUP
23:38:19*wallabra quit (Ping timeout: 248 seconds)
23:38:43FromDiscord<voidwalker> yes it is hideous : )
23:39:02FromDiscord<voidwalker> I don't know a better way unfortunately, except using a lib that has this kind of stuff, or writing a proc for it, to hide the uglyness..
23:39:18FromDiscord<voidwalker> but then again, if it were into stdlib, it would be implemented like that probably
23:39:34FromDiscord<Tony Rubak> I want to do it without stack allocating a copy of the whole data
23:39:45FromDiscord<Tony Rubak> like... what if the data is a gigabyte lol
23:40:26FromDiscord<jtv> You can just cast if you don't have to worry about byte swapping, or you can cast and call the proper byte swap operation
23:40:56*wallabra joined #nim
23:41:11FromDiscord<Tony Rubak> I thought I tried that and got a "this thing lacks an address"... can you provide an example of what you're talking about?
23:41:43FromDiscord<jtv> Sure one second
23:42:49FromDiscord<jtv> What data type are you starting from?
23:42:56FromDiscord<jtv> array of char?
23:43:11FromDiscord<Tony Rubak> I'm pretty sure it's a string because that's what `recv` returns
23:44:42FromDiscord<jtv> Okay, sure. But std/endian definitely will do the job for you, without having to do your own casting
23:45:37FromDiscord<jtv> Though, the docs don't say what the assumptions are of the endianness of the source data, lol
23:46:06FromDiscord<Tony Rubak> yeah, which is... odd
23:46:31FromDiscord<jtv> Like I said, the docs suck all around
23:47:14FromDiscord<Tony Rubak> and all that does is change copyMem to like... `bigEndian16(len.addr, byte_seq[2].unsafeAddr)` which is... marginally better? I'm trying to get rid of having to do `let byte_seq = frame.toSeq`
23:47:40*ltriant joined #nim
23:49:52FromDiscord<Tony Rubak> I think I prefer `ntohs` in std/nativesockets for dealing with the endianness issue because at least I know its assumptions
23:51:08FromDiscord<jtv> Fair enough yes
23:54:16FromDiscord<jtv> sent a code paste, see https://play.nim-lang.org/#ix=4jUQ
23:54:52FromDiscord<jtv> You can obviously be more compact about it 🙂
23:57:19FromDiscord<Tony Rubak> ah, ok... `len_ptr = cast[ptr uint8](unsafeAddr(frame[2]))` thanks!
23:57:36FromDiscord<Tony Rubak> that's like... idk if it's more or less hideous, but it's certainly not copying data lol
23:58:52FromDiscord<jtv> I do think using array indexing to dereference is a C-ism that was confusing and bad in the first place, so it's not awesome that it got copied, but frankly ptrs don't often show up outside of C interop anyway
23:59:35FromDiscord<Tony Rubak> can we offset pointers in nim?
23:59:59FromDiscord<jtv> No, `echo cast[ptr int](addr(s[0]))[0]` doesn't work