<< 06-05-2025 >>

01:12:18*fedorafan quit (Ping timeout: 244 seconds)
01:35:07*xet7 joined #nim
02:50:17*rockcavera quit (Remote host closed the connection)
03:57:13*SchweinDeBurg joined #nim
04:21:23*fedorafan joined #nim
04:34:27*alexdaguy joined #nim
04:41:37*ntat joined #nim
05:24:13*nils` quit (Ping timeout: 276 seconds)
05:56:59*xet7 quit (Remote host closed the connection)
05:58:52FromDiscord<heysokam> Is it possible to switch on typedesc?↵`case T of int: ... of float: ...` etc
05:59:55Amun-Raiirc no, but you can use if
06:00:00Amun-Raor when
06:00:13Amun-Rawhen is even better
06:00:54FromDiscord<heysokam> `when T == int` or `when T is int`? which is the correct one?
06:01:07Amun-RaI prefer is
06:01:10FromDiscord<heysokam> assuming `T` is `typedesc`
06:14:02FromDiscord<heysokam> sent a code paste, see https://play.nim-lang.org/#pasty=WrDmTDdC
06:15:02FromDiscord<heysokam> answer to my own question: `T is int` is the correct one. `==` just errors
06:18:29*alexdaguy quit (Quit: WeeChat 4.6.2)
06:49:37*xet7 joined #nim
06:52:54*xet7 quit (Remote host closed the connection)
06:56:58*xet7 joined #nim
07:35:14*fedorafan quit (Ping timeout: 252 seconds)
08:02:20*redj quit (Quit: No Ping reply in 180 seconds.)
08:03:52*redj joined #nim
08:06:33*xet7 quit (Remote host closed the connection)
08:11:52*nils` joined #nim
08:27:18*fedorafan joined #nim
08:35:02*fedorafan quit (Remote host closed the connection)
08:35:25*fedorafan joined #nim
08:52:57FromDiscord<mkadd.sh> In reply to @heysokam "answer to my own": Typedesc, only works in particular cases. You cannot assign a typedesc to a case, case expects you to pass some already defined value.
08:54:25FromDiscord<mkadd.sh> If you want to practice typedesc it is much better to use it in generic procs or templates.
08:54:29FromDiscord<mkadd.sh> https://tenor.com/view/hello-gif-13062150862685254762
09:40:38*SchweinDeBurg quit (Ping timeout: 252 seconds)
09:42:32*SchweinDeBurg joined #nim
09:42:39*fedorafan quit (Read error: Connection reset by peer)
09:42:57*fedorafan joined #nim
10:20:54*skippy8 joined #nim
11:05:38*xet7 joined #nim
11:18:14*andy-turner joined #nim
11:25:23FromDiscord<mratsim> sent a long message, see https://pasty.ee/BIKRLARA
11:45:38FromDiscord<riku5543> sent a code paste, see https://play.nim-lang.org/#pasty=FXunKNtX
12:10:20FromDiscord<mratsim> In reply to @riku5543 "Hi there, I was": use object variants or inheritance with `type Animal = ref object of RootObj`
12:11:02FromDiscord<mratsim> or `State[T]`
12:11:50FromDiscord<riku5543> In reply to @mratsim "or `State[T]`": Ooh yeah I didn't fully understand object variants in the docs, how does State[T] work, please?
12:12:36FromDiscord<mratsim> sent a code paste, see https://play.nim-lang.org/#pasty=xKuRFeOi
12:12:59FromDiscord<mratsim> you'll have multiple state objects though
12:13:10FromDiscord<mratsim> it's compile-time polymorphism
12:13:50FromDiscord<mratsim> sent a code paste, see https://play.nim-lang.org/#pasty=bteHhPgi
12:14:24FromDiscord<mratsim> and each objects has an associated enter proc and you replace the State.enter proc with it.
12:14:38FromDiscord<mratsim> That's what is done in C to emulate polymorphism / inheritance
12:14:46FromDiscord<mratsim> (edit) "objects" => "object"
12:15:23FromDiscord<riku5543> I think that would work for what I was trying to do, thank you very much! I'll try it out soon. I was using variants for other procs but couldn't wrap my head around getting it to work with the State definition. I thought about using a raw pointer as well but it felt dirty in this language lol
12:16:01FromDiscord<mratsim> inheritance + method are the simplest then.
12:16:14FromDiscord<mratsim> the example is even with cat and dog
12:16:32FromDiscord<riku5543> Ah okay
12:18:19FromDiscord<mratsim> mmh, I lost the tutorial that has the Cat / Dog thing
12:19:07FromDiscord<mratsim> ah it's there: https://nim-by-example.github.io/oop/
12:19:34FromDiscord<mratsim> sent a code paste, see https://play.nim-lang.org/#pasty=KUvjKotW
14:02:50*Guest7666 joined #nim
14:04:13*Guest7666 quit (Client Quit)
14:11:15*fedorafan quit (Read error: Connection reset by peer)
14:11:35*fedorafan joined #nim
15:40:56*fedorafan quit (Remote host closed the connection)
15:41:21*fedorafan joined #nim
15:54:48*skippy8 quit (Quit: WeeChat 4.5.2)
16:12:57FromDiscord<gyatsoyt> sent a code paste, see https://play.nim-lang.org/#pasty=GvMNdUSm
16:15:27*skippy8 joined #nim
16:16:23FromDiscord<nnsee> In reply to @gyatsoyt "How do I compile": honestly just wsl it
16:17:46FromDiscord<gyatsoyt> sent a code paste, see https://play.nim-lang.org/#pasty=kfMQsJOk
16:17:55FromDiscord<gyatsoyt> This happens on wsl
16:38:05*andy-turner quit (Quit: Leaving)
16:42:06*SchweinDeBurg quit (Quit: WeeChat 4.7.0-dev)
16:42:36*beholders_eye joined #nim
17:03:09FromDiscord<mr_rowboto> How is using `method` for polymorphism in `nim` seen?
17:03:34FromDiscord<mr_rowboto> sent a code paste, see https://play.nim-lang.org/#pasty=FrKbTBoQ
17:03:51FromDiscord<Elegantbeef> Avoid inheritance and use a tagged union
17:03:59FromDiscord<Elegantbeef> Is the general consensus
17:04:05FromDiscord<mr_rowboto> nice
17:04:07FromDiscord<mr_rowboto> no vtables
17:04:10Amun-RaI've never used 'method' in nim
17:04:17FromDiscord<mr_rowboto> how are tagged unions implemented?
17:04:30FromDiscord<Elegantbeef> Like C tagged unions
17:04:41FromDiscord<mr_rowboto> oh, ok, manually?
17:04:43FromDiscord<Elegantbeef> Each branch creates a anonymous struct inside of a union with a tag
17:04:55FromDiscord<Elegantbeef> No there are object variants
17:05:00FromDiscord<Elegantbeef> But you said how are they implemented and I told you 😄
17:05:09FromDiscord<Elegantbeef> How does one declare one? Using an object variant
17:05:19FromDiscord<mr_rowboto> In reply to @Elegantbeef "But you said how": of course
17:05:20Amun-Ramr_rowboto: https://nim-lang.org/docs/manual.html#types-object-variants
17:05:50FromDiscord<mr_rowboto> Thanks.
17:12:32*fedorafan_ joined #nim
17:14:11*fedorafan quit (Read error: Connection reset by peer)
17:14:48Amun-Rathere's one restriction: fields of different kinds and type can't share the same name
17:16:21*amadaluzia joined #nim
17:18:00FromDiscord<mr_rowboto> good enough
17:20:10Amun-Rahttps://play.nim-lang.org/#pasty=fXwzEAqB
17:20:21FromDiscord<mr_rowboto> What I need is that code `A` couples to `B`, while `C`, `D`, etc. implementors interface through `B`.↵I have no need for anything dynamic truly, as long as I can recompile, and link with `C` or `D`, without changing `A`.
17:21:16FromDiscord<mr_rowboto> In reply to @Amun-Ra "https://play.nim-lang.org/#pasty=fXwzEAqB": nice
17:21:53FromDiscord<mr_rowboto> In reply to @mr_rowboto "What I need is": I think that with variants I'd have to change `I` right?
17:22:01FromDiscord<mr_rowboto> (edit) "variants" => ""Object variants""
17:22:39FromDiscord<mr_rowboto> (edit) "`I`" => "`B`"
17:34:34*beholders_eye quit (Ping timeout: 245 seconds)
17:48:02FromDiscord<entropydev> Is it possible to cast a string as an `array[48, byte]`
17:48:08FromDiscord<entropydev> (edit) "byte]`" => "byte]`?"
17:48:49FromDiscord<entropydev> or is it possible that strings are not formated the same way a cstring would be?
17:49:55Amun-Rastrings are cstring compatible
17:50:57FromDiscord<entropydev> It seems like when I do this I am getting a lot of empty space
17:51:57Amun-Rahttps://play.nim-lang.org/#pasty=ZzrSzswE
17:53:09FromDiscord<entropydev> sent a code paste, see https://play.nim-lang.org/#pasty=XMKNdSqC
17:53:30FromDiscord<entropydev> this is not returning what I am expecting
17:54:19Amun-Rait's not compileable
17:54:32Amun-Radoes it have to be array?
17:54:39FromDiscord<entropydev> yes
17:54:55FromDiscord<entropydev> it does compile, what should be breaking?
17:55:25Amun-RaI mean the test case
17:55:43Amun-Rahere's openArray: https://play.nim-lang.org/#pasty=rCwIKkKc
17:56:13FromDiscord<entropydev> yeah, it would be better for it to be a fixed array size
17:57:32Amun-Rayou can create an array and copyMem
17:57:47FromDiscord<entropydev> https://play.nim-lang.org/#pasty=rCwIKkKc
17:58:04FromDiscord<entropydev> why are there all these 0s in the array?
17:58:54Amun-RaI don't see any zeros
17:59:22FromDiscord<entropydev> when I run this code it prints to the console
17:59:31FromDiscord<entropydev> and the byte array is mostly 0s
17:59:50Amun-Rathat's my code at the link :>
17:59:59FromDiscord<entropydev> no I sent a link
18:00:05Amun-Rayes
18:00:11Amun-Raclick on the link
18:00:19FromDiscord<entropydev> https://play.nim-lang.org/#pasty=rCwIKkKc
18:00:37FromDiscord<entropydev> https://play.nim-lang.org/#pasty=AIxNQgGZ
18:00:42Amun-Ra^ let decoded = "foobar"; echo repr decoded.toOpenArrayByte(0, decoded.high)
18:00:52FromDiscord<entropydev> ok, how about that?
18:02:01Amun-Rait's looks like physical representation of string is different from an array one
18:03:11FromDiscord<entropydev> now, I thought cstrings would be essentially an array with a \0 termination at the end?
18:03:23Amun-Rabut not "array" per se
18:03:46Amun-Racstrings are more like UncheckedArray
18:04:04FromDiscord<entropydev> ok, so how do I make the string into that?
18:04:34FromDiscord<entropydev> I would prefer fixed length if it's possible
18:04:38Amun-Rause openArray / create array and copy data
18:05:13Amun-Ravar bytes {.noinit.}: array[48, byte]; copyMem bytes[0].addr, decoded[0].addr, 48
18:05:36Amun-Ra48 → bytes.len
18:08:01FromDiscord<entropydev> huh, well that did it, this ; operator is interesting, is it like a pipe?
18:09:01Amun-Rait's just two separate lines written into single one for IRC: line1 ; line2
18:09:17Amun-Ravar bytes {.noinit.}: array[48, byte]
18:09:25Amun-RacopyMem bytes[0].addr, decoded[0].addr, bytes.len
18:09:58Amun-Rathat works exactly like in C or Python
18:12:04FromDiscord<entropydev> Well thanks, that was very helopful
18:12:12FromDiscord<entropydev> (edit) "helopful" => "helpful"
18:12:14Amun-Rano worries
18:41:30*fedorafan_ quit (Remote host closed the connection)
18:41:52*fedorafan_ joined #nim
19:09:39*fedorafan_ quit (Remote host closed the connection)
19:10:04*fedorafan_ joined #nim
19:20:46*amadaluzia_ joined #nim
19:25:22*amadaluzia_ quit (Ping timeout: 272 seconds)
19:25:39FromDiscord<treeform> In reply to @albassort "hello treeform": hello
20:34:55*ntat quit (Quit: leaving)
20:59:05*amadaluzia quit (Ping timeout: 244 seconds)
20:59:33*amadaluzia joined #nim
21:14:29*amadaluzia quit (Ping timeout: 248 seconds)
21:38:30*amadaluzia joined #nim
22:20:35*amadaluzia quit (Read error: Connection reset by peer)
22:20:55*amadaluzia joined #nim
22:26:59*skippy8 quit (Quit: WeeChat 4.5.2)
22:50:21*drewr quit (Ping timeout: 252 seconds)
23:48:19FromDiscord<schelz_> im working on a wrap for directx9 in nim, if anyone is interested in giving me a feedback im glad: https://github.com/SchelZ/d9Nim
23:48:38FromDiscord<schelz_> (edit) "glad:" => "glad to hear:"