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:12 | FromDiscord | <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:34 | FromDiscord | <djazz> use uint you say? 😅 |
00:17:28 | FromDiscord | <djazz> ah I see now |
00:25:13 | * | PMunch quit (Quit: leaving) |
00:35:59 | * | jmdaemon joined #nim |
00:49:06 | FromDiscord | <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:45 | FromDiscord | <jvsg> unrelated. But does anyone know of good chatroom/forum on canada based programmers or tech professionals? |
01:33:08 | FromDiscord | <jvsg> \<insert leaf joke here\> |
02:29:42 | FromDiscord | <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:28 | zkv | Hi * |
04:07:42 | * | rockcavera joined #nim |
04:10:19 | * | ltriant quit (Ping timeout: 260 seconds) |
04:16:47 | FromDiscord | <sOkam!> sent a code paste, see https://play.nim-lang.org/#ix=4jQa |
04:33:03 | FromDiscord | <Rika> Make the operators yourself |
04:33:18 | FromDiscord | <Rika> Personally I would rather and not over the symbols |
04:34:06 | * | arkurious quit (Quit: Leaving) |
04:34:09 | FromDiscord | <Rika> Maybe something in the bit ops module would be much better than either |
04:34:25 | FromDiscord | <Rika> Lots of “mask” “flip” kinds of procedures there |
04:34:27 | FromDiscord | <Rika> https://nim-lang.org/docs/bitops.html |
04:45:14 | * | zkv quit () |
04:52:31 | FromDiscord | <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:22 | FromDiscord | <sOkam!> sent a code paste, see https://paste.rs/562 |
05:05:38 | FromDiscord | <Elegantbeef> Yea though the C is faster |
05:09:22 | FromDiscord | <sOkam!> faster in which way? |
05:09:39 | FromDiscord | <sOkam!> data accessing, or just in the generation? |
05:10:19 | FromDiscord | <sOkam!> its only run once on loading... so if its faster just for generation, then the C version can go f itself |
05:11:07 | FromDiscord | <sOkam!> if its faster for data reading, then I might need a different approach, possibly? |
05:12:01 | FromDiscord | <Elegantbeef> Nim 0s the memory and then you add to a sequence which has checks and increments the len |
05:12:51 | FromDiscord | <sOkam!> i was thinking of setting the values with `result.data[cluster] = 255` |
05:13:27 | FromDiscord | <Elegantbeef> I mean it's minor and likely wont matter 😄 |
05:13:33 | FromDiscord | <Elegantbeef> `newSeqWith` might be faster |
05:14:26 | FromDiscord | <amadan> sent a code paste, see https://play.nim-lang.org/#ix=4jQl |
05:14:54 | FromDiscord | <Elegantbeef> Yea it would |
05:15:30 | * | ltriant quit (Ping timeout: 272 seconds) |
05:16:42 | FromDiscord | <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:19 | FromDiscord | <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:51 | FromDiscord | <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:50 | FromDiscord | <Elegantbeef> You cannot manually free GC types |
06:46:06 | FromDiscord | <Elegantbeef> You can do `GcRef` and `GcUnref` with a `GCFullCollect` but that's not really freeing it before the gc |
06:46:12 | FromDiscord | <Elegantbeef> That's just helping the GC along |
07:21:34 | FromDiscord | <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:43 | FromDiscord | <Phil> I know the first one is the proc's name |
07:24:05 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jQL |
07:24:12 | * | ltriant joined #nim |
07:25:13 | FromDiscord | <Phil> (edit) "https://play.nim-lang.org/#ix=4jQL" => "https://paste.rs/NHc" |
07:27:43 | FromDiscord | <Phil> Argh, that's actually defined in the docs, found it |
07:28:14 | FromDiscord | <Phil> Wait, that makes no sense |
07:28:27 | FromDiscord | <Elegantbeef> `name constraint, generic, args, pragma, body, result sym` |
07:29:06 | FromDiscord | <Elegantbeef> `proc a{t}[T](t: int): T {.cdecl.} = echo "Hello"` |
07:29:20 | FromDiscord | <Elegantbeef> that's basically the most loaded a procedure can be it should fill every slot |
07:31:07 | FromDiscord | <Elegantbeef> Think there are some reserved slot |
07:32:03 | FromDiscord | <Phil> The above proc has 8 nodes though, you described 7, is one of thw two emptyNodes still undescribed? |
07:32:13 | FromDiscord | <Phil> Because nnkAsgn I think is the body, so the newSymNode is the result sym I think |
07:32:22 | FromDiscord | <Elegantbeef> Correct |
07:32:30 | FromDiscord | <Elegantbeef> I think there is a reserved or deprecated position |
07:33:04 | FromDiscord | <Phil> That's index 5 then |
07:34:12 | FromDiscord | <Phil> sent a long message, see http://ix.io/4jQN |
07:34:41 | FromDiscord | <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:00 | FromDiscord | <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:36 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jQR |
07:55:51 | FromDiscord | <Elegantbeef> should check the params |
07:56:16 | FromDiscord | <Elegantbeef> `procs[1]` isnt a proc it's a stmtlist of `generatedPointerProc, ... argument type` |
07:56:31 | FromDiscord | <Elegantbeef> We arent using a proc we're using our own ast there |
08:00:42 | FromDiscord | <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:52 | FromDiscord | <Phil> (edit) "a" => "an explicit" |
08:03:02 | FromDiscord | <Elegantbeef> Correct |
08:06:16 | FromDiscord | <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:23 | FromDiscord | <Phil> sent a long message, see http://ix.io/4jQS |
08:06:48 | FromDiscord | <Elegantbeef> `myProc` is `testProc` in this case |
08:06:57 | FromDiscord | <Elegantbeef> or `genericOtherProc` |
08:07:04 | * | wallabra quit (Ping timeout: 268 seconds) |
08:07:15 | FromDiscord | <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:18 | FromDiscord | <Elegantbeef> Basically for generics we replace the procedure with a macro and a `set` macro |
08:08:03 | * | ltriant joined #nim |
08:08:05 | FromDiscord | <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:19 | FromDiscord | <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:42 | FromDiscord | <Elegantbeef> It's not somehow |
08:09:47 | FromDiscord | <Elegantbeef> You're literally replacing the proc for a macro |
08:10:14 | FromDiscord | <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:19 | FromDiscord | <Phil> I think I'll continue this when I understand more about the code, diving back into it |
08:14:50 | FromDiscord | <Elegantbeef> The idea is that the `mock` macro would generate the else branch of that code example |
08:15:07 | FromDiscord | <Phil> But the mock macro needs to be called first |
08:15:40 | FromDiscord | <Elegantbeef> Yes? |
08:15:52 | FromDiscord | <Phil> And `ModuleUnderTest.testProc` expects one of the procs that the generated `mock` macro will generate to be there |
08:16:23 | FromDiscord | <Elegantbeef> You annotate your generic proc with mock |
08:16:47 | FromDiscord | <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:13 | FromDiscord | <Phil> sent a code paste, see https://paste.rs/SBX |
08:21:34 | FromDiscord | <Elegantbeef> correct |
08:21:48 | FromDiscord | <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:49 | FromDiscord | <Elegantbeef> Though i dont think `macro toString[T](x: T)` compiles 😄 |
08:22:22 | FromDiscord | <Elegantbeef> The first call would instantiate and add a pointer proc to the cache table |
08:22:23 | FromDiscord | <Elegantbeef> Well cacheseq |
08:22:43 | FromDiscord | <Elegantbeef> That pointer proc then would be accessible across your project and interacted with using `setToString` |
08:26:15 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jQV |
08:26:38 | FromDiscord | <sOkam!> how do you check if a seq if currently empty, in comparison with it having just one item at index 0? |
08:27:08 | FromDiscord | <sOkam!> does len == 0 mean that? |
08:27:11 | FromDiscord | <Phil> Could you rephrase that? |
08:27:18 | FromDiscord | <Phil> len == 0 means no item in seq at all |
08:27:28 | FromDiscord | <sOkam!> its probably a stupid question, but i always get lost in the stupid dum things 😔 |
08:27:37 | FromDiscord | <Phil> if you have an item in a seq at index 0 it has len == 1 |
08:28:03 | FromDiscord | <sOkam!> kk, was probably confusing id0 with len0 being the same thing, but they arent. tyty |
08:28:17 | FromDiscord | <Phil> I am as confused as I was before, but happy to have helped |
08:30:43 | FromDiscord | <Elegantbeef> I guess it doesnt really matter↵(@Phil) |
08:31:09 | FromDiscord | <Elegantbeef> It could just be `result.add newCall(sym, ...args)` |
08:31:23 | FromDiscord | <Elegantbeef> Yes i'm using python syntax as pseudo code |
08:31:56 | FromDiscord | <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:53 | FromDiscord | <Phil> ` result.add newCall(sym, a)`↵Can not confirm that this works, the if else solution appears to be more correct |
08:33:20 | FromDiscord | <Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4jQW |
08:33:30 | FromDiscord | <Elegantbeef> Well do `result = newStmtList()` |
08:33:38 | FromDiscord | <Elegantbeef> and remove the present `result = newStmtList()` |
08:33:40 | FromDiscord | <Elegantbeef> it'll certainly work |
08:33:44 | * | ltriant joined #nim |
08:34:59 | FromDiscord | <Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4jQY |
08:36:50 | FromDiscord | <Elegantbeef> I assume you've looked at the generated AST for the code |
08:37:19 | FromDiscord | <Phil> Somewhat, mostly at the AST within generatedProcs |
08:37:36 | FromDiscord | <Phil> And noticed that the AST in there appears to just be the ways that the macro was invoked or sth |
08:38:02 | FromDiscord | <Elegantbeef> It's the ast we made |
08:38:28 | FromDiscord | <Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4jQZ |
08:38:41 | FromDiscord | <Elegantbeef> it should be `newStmtList(sym, args)` |
08:38:54 | FromDiscord | <Elegantbeef> where args is all of your procedure's arguments |
08:39:16 | FromDiscord | <Phil> Ohhhh we fill that seq as part of the proc that generates procs (or doesn't) |
08:39:25 | FromDiscord | <Elegantbeef> Correct |
08:39:30 | FromDiscord | <Elegantbeef> We're making our own instantiation table |
08:39:45 | FromDiscord | <Elegantbeef> the first node is the pointer proc's symbol |
08:39:56 | FromDiscord | <Elegantbeef> The following is each argument |
08:40:09 | FromDiscord | <Elegantbeef> This allows us to type check later when we invoke this and generate a pointer proc |
08:40:28 | FromDiscord | <Elegantbeef> We're practically doing generic instantiations |
08:40:45 | FromDiscord | <Elegantbeef> This will get more complicated of course |
08:40:58 | FromDiscord | <Elegantbeef> Since you will need to replace all symbols that are the parameters with new parameter symbols |
08:42:13 | FromDiscord | <Elegantbeef> In the new generated procedure |
08:42:13 | FromDiscord | <Elegantbeef> Though i think they're idents since it's generic so it might be fine |
08:42:17 | FromDiscord | <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:30 | FromDiscord | <Elegantbeef> Yep |
08:42:42 | FromDiscord | <Elegantbeef> Once you learn it's not completely arbitrary it makes life easier |
08:43:01 | FromDiscord | <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:20 | FromDiscord | <Elegantbeef> I mean to be fair you shouldnt need to know any of this |
08:43:24 | FromDiscord | <Elegantbeef> It's fucking inane that you do |
08:43:49 | FromDiscord | <Phil> And its also important that any node is either: EmptyNode or the actual node intended to be there |
08:43:58 | FromDiscord | <Phil> (edit) "And its also important that any node is either: EmptyNode or the actual node ... intended" added "with the kind" |
08:44:16 | FromDiscord | <Elegantbeef> This is why i really like the premise of micros, it doesnt labour you with the actual AST |
08:45:01 | FromDiscord | <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:35 | FromDiscord | <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:10 | FromDiscord | <Phil> In reply to @Elegantbeef "You have a `routineNode`": So basically you use the type-system to enshrine that static node pattern? |
08:46:19 | FromDiscord | <Elegantbeef> Yes |
08:46:35 | FromDiscord | <Phil> Comprehension has started to unfold |
08:47:53 | FromDiscord | <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:08 | FromDiscord | <Phil> Trying to wrap my head around `procs[1].sameType(a.getType())` |
08:51:50 | FromDiscord | <Phil> ... Can you use options in macros? |
08:52:02 | FromDiscord | <Phil> Nah, unlikely, nevermind |
08:56:22 | FromDiscord | <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:33 | FromDiscord | <Elegantbeef> For instance |
08:56:37 | FromDiscord | <Elegantbeef> I dont know i might be crazy |
08:56:39 | FromDiscord | <Elegantbeef> If you can guess what that does without any comments or me explaining i'll give you 10 imaginary points 😛 |
08:56:42 | FromDiscord | <Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4jR3 |
08:57:06 | FromDiscord | <Elegantbeef> it is the macro version of `typeOf` |
08:57:21 | FromDiscord | <Phil> Bridge may be dying unless you posted that actually 09:56 ETC |
08:57:26 | FromDiscord | <Elegantbeef> Oh jeez bridge moment 😄 |
08:57:34 | FromDiscord | <Phil> Check, ok lets see |
08:58:14 | FromDiscord | <Elegantbeef> Yes it points to that SymNode, it's our proc table |
08:58:59 | FromDiscord | <Elegantbeef> Actually this makes me wonder.... we might be able to use `sameType` on the sym instead of carrying the parameters around |
08:59:18 | FromDiscord | <Elegantbeef> Do you have the link to this on playground? |
08:59:58 | FromDiscord | <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:44 | FromDiscord | <dizzyliam [they/them]> Just realised that what I'm making is basically isomorphic JS but with Karax |
09:07:47 | FromDiscord | <dizzyliam [they/them]> Isomorphic Nim? |
09:08:32 | FromDiscord | <Elegantbeef> @Phil\: https://play.nim-lang.org/#ix=4jR8 a more sensible approach for the setter |
09:08:52 | FromDiscord | <Elegantbeef> And also a bit more sensible for the `var sym = ...` |
09:15:33 | FromDiscord | <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:51 | FromDiscord | <Elegantbeef> The first tuple is `(string, string, string)` |
09:16:01 | FromDiscord | <Elegantbeef> you want `some("test")` or `some"test"` |
09:16:49 | FromDiscord | <HitBlast> oh alright |
09:32:11 | FromDiscord | <HitBlast> sent a code paste, see https://play.nim-lang.org/#ix=4jRc |
09:34:42 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jRd |
09:34:48 | FromDiscord | <Phil> Is this to generate partial types from larger overencompassing types? |
09:35:03 | * | ltriant joined #nim |
09:35:34 | FromDiscord | <Elegantbeef> Yes |
09:35:47 | FromDiscord | <Elegantbeef> `fields` can have multiple names cause of `a, b: int` being valid |
09:35:50 | FromDiscord | <Phil> (edit) "https://play.nim-lang.org/#ix=4jRd" => "https://paste.rs/MzV" |
09:35:58 | FromDiscord | <Elegantbeef> that's not converted by the compiler to multiple defs, it's a single def |
09:36:09 | FromDiscord | <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:47 | FromDiscord | <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:16 | FromDiscord | <Elegantbeef> `typedesc` can have a field iterator btw |
09:37:19 | FromDiscord | <Elegantbeef> It's not magic |
09:37:50 | FromDiscord | <Elegantbeef> It's just that it only makes sense for like `(int, int)` cause it requires compiler magic otherwise |
09:37:53 | FromDiscord | <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:21 | FromDiscord | <Elegantbeef> Well it'd require magic to work the same there |
09:38:30 | FromDiscord | <Elegantbeef> But anyway that's my own `fields` iterator |
09:39:07 | FromDiscord | <Phil> I do agree its pretty readable |
09:42:46 | * | ltriant quit (Ping timeout: 272 seconds) |
09:43:12 | FromDiscord | <Phil> Can I access the name of a macro from within said macro? |
09:43:28 | FromDiscord | <Elegantbeef> `bindSym"MyMacroName"` |
09:43:30 | FromDiscord | <Elegantbeef> Otherwise no |
09:43:58 | FromDiscord | <Phil> Hmm mostly wanted to get rid of "myProc" in `symbol = gensym(nskVar, "myProc")` |
09:44:26 | FromDiscord | <Phil> I guess I could add the proc name as value of the `mockable` pragma |
09:47:17 | FromDiscord | <Elegantbeef> I mean mockable would generate this |
09:47:17 | FromDiscord | <Elegantbeef> So you'd have that proc's name |
09:54:54 | FromDiscord | <Phil> How do I access the generic proc I just replaced and its intended body etc.? |
09:54:55 | * | ltriant joined #nim |
09:55:15 | FromDiscord | <Phil> Wait, I can look at the first iteration of the mockable pragma |
09:55:56 | FromDiscord | <Elegantbeef> well `proc myProc(a: SomeInteger){.mock.} = echo a` should generate the above |
10:01:08 | * | ltriant quit (Ping timeout: 272 seconds) |
10:03:32 | FromDiscord | <Phil> sent a long message, see http://ix.io/4jRn |
10:03:51 | FromDiscord | <Elegantbeef> mock generates that macro |
10:03:57 | FromDiscord | <Elegantbeef> the when else was to show the input vs. output |
10:05:41 | FromDiscord | <Phil> I think you lost me |
10:06:16 | FromDiscord | <Elegantbeef> the branch that is `when false` in my code is to show the procedure that was annotated with `{.mock.}` |
10:06:58 | FromDiscord | <Elegantbeef> The else branch is code your macro generates when mock is enabled and you hit a generic procedure |
10:07:05 | FromDiscord | <Elegantbeef> Yes you're generating a macro from a macro |
10:07:11 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jRo |
10:07:24 | FromDiscord | <Elegantbeef> Correct you need to change mock |
10:07:30 | FromDiscord | <Phil> Ah, check, so I need to replace the when-else inside, check |
10:07:41 | FromDiscord | <Elegantbeef> Indeed |
10:07:44 | FromDiscord | <Phil> The else branch stays the same I assume |
10:08:03 | FromDiscord | <Phil> As in, the else branch in mock should be `result = p` either way |
10:08:07 | FromDiscord | <Elegantbeef> Yes |
10:08:13 | FromDiscord | <Elegantbeef> Yep |
10:08:22 | FromDiscord | <Elegantbeef> In the case you arent mocking you dont change anything |
10:09:40 | FromDiscord | <Elegantbeef> This should make 1000 times more sense now 😛 |
10:11:01 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jRp |
10:11:25 | FromDiscord | <Elegantbeef> Look at my more recent link |
10:11:30 | FromDiscord | <Elegantbeef> I provide a more sensible solution |
10:12:01 | FromDiscord | <Phil> You mean the more recent play nim lang link, or the micros link? |
10:12:08 | FromDiscord | <Elegantbeef> nim lang |
10:12:33 | FromDiscord | <Phil> That piece of code stems from that link https://media.discordapp.net/attachments/371759389889003532/1057964331104485426/image.png |
10:12:51 | FromDiscord | <Elegantbeef> Yes look at line 8 and 21 |
10:13:09 | FromDiscord | <Phil> Ohhhh wait, I see |
10:13:21 | FromDiscord | <Elegantbeef> We still emit a generic proc |
10:14:50 | FromDiscord | <Phil> I can save myself the assignment to MyProcBase because that's `p` I think |
10:15:03 | FromDiscord | <Elegantbeef> You still need to emit the procedure |
10:15:06 | FromDiscord | <Phil> So all I need should be line 21 with `p` for `MyProcBase` |
10:15:09 | FromDiscord | <Elegantbeef> Or want to |
10:15:16 | FromDiscord | <Elegantbeef> this way you can reset the procedure |
10:15:17 | FromDiscord | <Phil> Ah, hmm |
10:15:45 | FromDiscord | <Elegantbeef> The smarter thing to do now that i think about it is to just forward the parameters |
10:16:13 | FromDiscord | <Elegantbeef> So you generate `var sym = someMacroThatGetsTheProcType(myProcBase(a))` |
10:16:49 | FromDiscord | <Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4jRq |
10:16:49 | FromDiscord | <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:54 | FromDiscord | <Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4jRs |
10:19:16 | FromDiscord | <Elegantbeef> All we're doing is copying the proc and changing the name |
10:19:23 | * | wallabra quit (Ping timeout: 264 seconds) |
10:23:38 | FromDiscord | <Elegantbeef> Anyway i'm off, so hopefully you can work through this |
10:23:56 | * | ltriant quit (Ping timeout: 272 seconds) |
10:24:48 | FromDiscord | <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:47 | FromDiscord | <luteva> how can i get the length (number of bytes in memory) of an object? |
11:09:36 | PMunch | sizeof? |
11:10:30 | FromDiscord | <luteva> i yes, thx! i tried "len" but not sizeof 😄 |
11:13:54 | PMunch | Len is typically used for "count of items" and sizeof is "number of bytes" |
11:14:12 | PMunch | Those might be the same, e.g. for an array of uint8s |
11:18:03 | Amun-Ra | is it possible to pass openarray as static to function and have compile time array length? |
11:18:42 | PMunch | Not 100% sure what you mean here |
11:19:29 | Amun-Ra | I'd like to use array.len in when clause |
11:19:34 | Amun-Ra | ec |
11:20:50 | pro | why only 4 days of aoc PMunch ? |
11:21:42 | Amun-Ra | PMunch: something like this: https://play.nim-lang.org/#ix=4jRC |
11:21:44 | PMunch | I did 6, but Christmas was busy this year.. |
11:23:31 | pro | indeed it was |
11:23:36 | PMunch | Damn, those videos have more views than I imagined |
11:24:08 | FromDiscord | <Phil> How do I take a look again at the nim code that is generated? |
11:24:15 | FromDiscord | <Phil> Not the ast, the nim code |
11:24:27 | PMunch | I was thinking of doing a "Let's see how many days I can get through in one sitting" thing |
11:25:07 | PMunch | But I've got a sore throat at the moment, so it'll have to wait a bit |
11:25:35 | PMunch | @Phil, repr? |
11:26:54 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jRD |
11:27:00 | FromDiscord | <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:29 | FromDiscord | <Phil> Argh, would've been nice to see, well time to get more used to reading AST then |
11:29:39 | FromDiscord | <Phil> TIL that the result symbol can also be straight up left out of a proc definition |
11:29:45 | FromDiscord | <Phil> (edit) "definition" => "definition's AST" |
11:29:56 | FromDiscord | <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:58 | FromDiscord | <Phil> So a proc-AST can contain of 7 or 8 nodes |
11:30:04 | FromDiscord | <Phil> (edit) "contain" => "consist" |
11:36:53 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jRH |
11:37:09 | FromDiscord | <Phil> (edit) "https://paste.rs/8vp" => "https://play.nim-lang.org/#ix=4jRI" |
11:37:29 | PMunch | @Phil, echo result.repr? |
11:37:48 | PMunch | Or of course --expandMacro:mock |
11:39:04 | FromDiscord | <Phil> sent a code paste, see https://paste.rs/ZrR |
11:39:37 | PMunch | Then that's the result of your macro.. |
11:40:26 | FromDiscord | <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:36 | PMunch | Yeah if it's not in the result, it's not being returned |
11:41:40 | FromDiscord | <Phil> Because I shoooouuuld be getting the output of `proc myProc(a: int) = echo "Walumba"` |
11:42:04 | PMunch | Isn't that what you got? |
11:42:17 | FromDiscord | <Phil> That was a mistake on my end, copy pasted the wrong thing |
11:42:22 | FromDiscord | <Phil> Edited above, I get a: SomeInteger |
11:42:39 | PMunch | Hmm, edits don't do well over the bridge either.. |
11:42:45 | PMunch | They've gotten better though |
11:42:58 | FromDiscord | <Phil> Correction here |
11:42:59 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jRJ |
11:43:17 | FromDiscord | <Phil> So if I want to generate a macro from a macro |
11:43:37 | FromDiscord | <Phil> Do I have to... return that macro somehow? |
11:43:47 | PMunch | Of course |
11:43:48 | FromDiscord | <Phil> There is no way I can turn a macro into a node and add that to a statement list |
11:43:50 | FromDiscord | <Phil> That sounds insane |
11:44:11 | PMunch | Haha, you'd be surprised |
11:44:32 | FromDiscord | <Phil> ... I'll try then... errr is there a special thingy to convert a macro into a NimNode? |
11:44:40 | PMunch | quote do? |
11:45:39 | FromDiscord | <Phil> Okay the mystical ways of quote do are getting confusing, time to read up on it |
11:48:22 | FromDiscord | <Phil> Okay so it's basically another way of copy-pasting sort-of |
11:48:29 | FromDiscord | <Phil> Copy-pasting something and getting it turned into an ast |
11:48:48 | PMunch | Well not so much copy-pasting as a more convenient way to create an AST |
11:52:48 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4jRL |
11:53:31 | FromDiscord | <Phil> (edit) "https://paste.rs/jsa" => "https://paste.rs/Xoc" |
11:55:08 | FromDiscord | <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:33 | FromDiscord | <Phil> (edit) "variables," => "variables (as per the `var symbol = (proc(arg: typeof(a)))(copyProc)` statement) ," |
11:59:35 | PMunch | Not sure what copyProc does.. |
11:59:40 | PMunch | So hard to tell |
11:59:53 | FromDiscord | <Phil> copyProc is just a copy of the initial proc you pass in |
11:59:57 | PMunch | You shouldn't create multiple variables with the same name |
12:00:06 | PMunch | That's a bad idea |
12:00:26 | FromDiscord | <Phil> the only difference is that it gets renamed to "mockedProc", so that the original definition no longer exists |
12:00:57 | FromDiscord | <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:28 | PMunch | Not entirely sure what you're trying to do here |
12:03:53 | PMunch | Why are you going through a macro? |
12:06:32 | FromDiscord | <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:18 | FromDiscord | <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:51 | FromDiscord | <Phil> And at this point I feel like I'm halfway along the way of batshit insane solutions |
12:09:50 | FromDiscord | <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:05 | FromDiscord | <Phil> Though how that can possibly work I don't know |
12:11:24 | PMunch | Hmm, it shouldn't generate a var assignment |
12:12:04 | FromDiscord | <Phil> isn't that what the genast at the end does? |
12:12:13 | FromDiscord | <Phil> As kind of the weirdest sort of macro-function-call thing I've seen today? |
12:18:19 | PMunch | Ah I've never used genAst, but it appears to be a version of quote do |
12:19:17 | PMunch | Or rather it appears to do something similar, but in a slightly different way |
12:46:46 | FromDiscord | <Phil> sent a long message, see https://paste.rs/OPZ |
12:47:05 | FromDiscord | <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:00 | FromDiscord | <Phil> I haven't even been awake 6 hours and my brain already feels semi-fried |
12:48:43 | FromDiscord | <voidwalker> you have mocked your brain |
12:49:15 | FromDiscord | <Phil> At some points, my mocks started mocking me |
12:49:37 | FromDiscord | <voidwalker> I've no idea what those are, so this whole dialogue is even more hilarious to watch : D |
12:50:17 | FromDiscord | <voidwalker> mock proc.. pretend proc ? |
12:51:22 | FromDiscord | <Phil> At least pretend proc hasn't been used yet |
12:51:26 | FromDiscord | <Phil> So I'm good on that one |
12:51:31 | FromDiscord | <Phil> Only copyProc and mockProc |
12:51:57 | FromDiscord | <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:19 | FromDiscord | <untoreh> sent a code paste, see https://paste.rs/KLU |
12:53:49 | FromDiscord | <untoreh> (edit) "https://play.nim-lang.org/#ix=4jRY" => "https://paste.rs/125" |
12:55:55 | * | ltriant joined #nim |
12:59:36 | FromDiscord | <Phil> I'm not aware of that pragma, it's also not documented as far as I can see |
13:00:17 | FromDiscord | <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:02 | PMunch | I think that's from a library you've imported |
13:18:55 | PMunch | Ah, never mind |
13:19:24 | FromDiscord | <luteva> how can i get the byte(-sequence) representation of an object? |
13:24:45 | PMunch | Define representation |
13:29:12 | FromDiscord | <untoreh> sent a code paste, see https://play.nim-lang.org/#ix=4jS2 |
13:30:21 | PMunch | You can just do: cast[array[sizeof(A), byte]](a) |
13:30:35 | PMunch | Hmm, this partial thing is really strange.. |
13:31:47 | FromDiscord | <untoreh> it doesn't work within macro and templates |
13:32:05 | FromDiscord | <luteva> castarray?? |
13:32:31 | FromDiscord | <luteva> (edit) "castarray?? ... " added "does this exist?" |
13:32:54 | FromDiscord | <luteva> or is it cast(array[sizeof(A), byte]) |
13:33:00 | FromDiscord | <untoreh> yes just avoid the pointer |
13:33:23 | FromDiscord | <luteva> ok thx folks! |
13:33:29 | FromDiscord | <luteva> gonna try this. |
13:33:39 | PMunch | Wait, did the bridge strip my square brackets? |
13:34:34 | FromDiscord | <untoreh> this is what it forwarded "castarray[sizeof(A), byte]" |
13:35:47 | PMunch | ... |
13:38:49 | FromDiscord | <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:23 | PMunch | The 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:02 | FromDiscord | <Phil> In reply to @Smarc "var x = {'a'": Best I can do you is the toSeq proc |
13:51:20 | FromDiscord | <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:54 | PMunch | Okay these partial objects are seriously weird |
13:54:39 | PMunch | Take 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:41 | PMunch | Hmm, this is actually a pretty cool feature |
14:00:26 | PMunch | Aaand I broke it :P |
14:00:45 | PMunch | Apparently it didn't like to add a field in a proc.. |
14:01:38 | PMunch | It's pretty brittle |
14:08:20 | NimEventer | New 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:17 | PMunch | Hmm, 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:22 | termer | if it's not a ref or pointer, then it's on the stack |
14:36:29 | termer | oops I replied to an old message |
14:42:14 | FromDiscord | <HitBlast> sent a long message, see https://paste.rs/xhq |
14:42:35 | FromDiscord | <HitBlast> (edit) "http://ix.io/4jSo" => "https://paste.rs/g6k" |
14:43:54 | PMunch | Why wouldn't it be able to be converted to UTF-8? |
14:54:13 | * | arkurious joined #nim |
15:01:23 | FromDiscord | <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:17 | FromDiscord | <jtv> sent a code paste, see https://paste.rs/mg6 |
15:02:34 | FromDiscord | <jtv> If it's invalid, it'll return you the first invalid byte position |
15:08:05 | FromDiscord | <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:15 | adigitoleo | Quick question: I'm trying to understand the `ord(getch())` mapping, what scancode numbering is being used by nim here? |
15:28:01 | FromDiscord | <jtv> In reply to @adigitoleo "Quick question: I'm trying": Do you mean, how does nim map characters to numbers? |
15:28:26 | adigitoleo | Oh I see, it's ASCII printable |
15:28:30 | FromDiscord | <jtv> It's the international Unicode standard... the numbers are called 'codepoints' by Unicode |
15:28:59 | FromDiscord | <jtv> For the ascii characters, it's all the same |
15:29:15 | FromDiscord | <jtv> In Nim, when working with codepoints, the language uses the term 'Rune' |
15:32:21 | adigitoleo | ah 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:01 | adigitoleo | just to clarify further, at the low level keyboard input goes: scancode -> keycode -> codepoint? Am I understanding the names right? |
15:49:57 | FromDiscord | <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:14 | adigitoleo | OK 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:51 | FromDiscord | <ShalokShalom> Google makes their own Nim |
16:20:54 | FromDiscord | <ShalokShalom> https://github.com/google/rune |
16:24:54 | FromDiscord | <⚶ 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:56 | FromDiscord | <albassort> In reply to @⚶ Zeno "Hey people, what does": You aren't sure that v has that proc |
16:39:00 | FromDiscord | <albassort> So you can't evaluate it at run time |
16:39:09 | FromDiscord | <albassort> You need to make sure that v has [] |
16:39:12 | FromDiscord | <albassort> So you want to make a concept for it |
16:39:26 | FromDiscord | <⚶ Zeno> i see |
16:40:13 | FromDiscord | <⚶ 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:54 | FromDiscord | <⚶ Zeno> (i know they are invalid format and stuff, but i just wrote them quickly to make sure things are working) |
16:41:26 | FromDiscord | <albassort> Or something |
16:41:27 | FromDiscord | <albassort> sent a code paste, see https://play.nim-lang.org/#ix=4jSU |
16:41:32 | FromDiscord | <albassort> I'm not on my computer to actually get code for you |
16:41:37 | FromDiscord | <albassort> But that's the general path. I'm sure it doesn't file |
16:41:44 | FromDiscord | <albassort> (edit) "file" => "compile" |
16:41:48 | FromDiscord | <albassort> I believe in you |
16:42:18 | FromDiscord | <⚶ Zeno> yea i'll try to figure it out by those, thanks for leading me |
16:42:38 | FromDiscord | <albassort> However, I guarantee you this is an itertools |
16:42:50 | FromDiscord | <albassort> A nimble package which has a lot of pythons weird generators |
16:43:20 | FromDiscord | <⚶ 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:32 | FromDiscord | <⚶ Zeno> thanks m8 |
16:47:48 | FromDiscord | <planetis> m8 you mean this https://github.com/OpenSystemsLab/struct.nim ? |
16:48:28 | FromDiscord | <⚶ 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:17 | FromDiscord | <planetis> I see the error is typical, you can't iterate tuples with a runtime index |
16:50:42 | FromDiscord | <planetis> your best bet is to use something like fields/fiedPairs iterator |
16:51:17 | FromDiscord | <@thatrandomperson5-6310e3b26da03> i get type mistmatch for `int` when it only accepts `sink T`. Can someone please explain this? |
16:52:56 | FromDiscord | <planetis> it should work, share your code |
16:55:39 | FromDiscord | <@thatrandomperson5-6310e3b26da03> > it should work, share your code↵Gitter breaks code or whatever so here it is raw\: |
16:55:50 | FromDiscord | <@thatrandomperson5-6310e3b26da03> sent a code paste, see https://play.nim-lang.org/#ix=4jT1 |
16:56:59 | FromDiscord | <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:03 | FromDiscord | <mattrb> sent a code paste, see https://play.nim-lang.org/#ix=4jT3 |
16:59:30 | FromDiscord | <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:14 | FromDiscord | <@thatrandomperson5-6310e3b26da03> The error is on the third line.↵(@planetis) |
17:04:06 | FromDiscord | <⚶ Zeno> In reply to @planetis "your best bet is": i see, thanks |
17:04:13 | FromDiscord | <planetis> then result is not a seq[int] ? |
17:05:05 | FromDiscord | <⚶ Zeno> In reply to @planetis "your best bet is": i guess that will suffice for time being |
17:05:31 | FromDiscord | <⚶ Zeno> thanks again, also thanks to albassort |
17:05:58 | FromDiscord | <albassort> I think the problem is you just need to think more statically |
17:06:19 | FromDiscord | <albassort> When you tell the compiler T, you're not telling it anything besides that, that perimeter has a type |
17:06:41 | FromDiscord | <albassort> And so since a type has no inherent properties, you can't do anything with it |
17:07:06 | FromDiscord | <⚶ Zeno> yeah, thats the problem, im more used to python, and i mostly think those codes in python-way |
17:07:15 | FromDiscord | <albassort> So, you need to specify so to compiler knows it has a certain attributes |
17:07:25 | FromDiscord | <albassort> In reply to @⚶ Zeno "yeah, thats the problem,": In Python, python doesn't care even if you type it |
17:07:31 | FromDiscord | <⚶ Zeno> yup |
17:07:44 | FromDiscord | <albassort> Even if you say this is X-Type which has no [] it'll still throw no error |
17:07:58 | FromDiscord | <albassort> So lol You got to get used to the more strict typing |
17:08:11 | FromDiscord | <⚶ Zeno> yessir |
17:11:19 | FromDiscord | <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:26 | FromDiscord | <mattrb> sent a code paste, see https://play.nim-lang.org/#ix=4jT9 |
17:15:30 | FromDiscord | <planetis> since compilation fails at C step then better open an issue. |
17:15:42 | FromDiscord | <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:38 | FromDiscord | <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:02 | NimEventer | New thread by Araq: Roadmap 2023, see https://forum.nim-lang.org/t/9777 |
17:24:58 | FromDiscord | <mattrb> Hmm, seems like it's actually an issue with emcc.. |
17:26:29 | FromDiscord | <planetis> btw I don't even cast to that type, I have emscripten 3.1.26 installed in arch linux |
17:26:29 | FromDiscord | <Patitotective> In reply to @Elegantbeef "<@762008715162419261>\: did you make": it worked on my windows machine 🤷 |
17:26:33 | FromDiscord | <mattrb> Not sure what's causing the problem though.. Guess I'll just do the workaround for now and let it be.. |
17:32:58 | FromDiscord | <⚶ 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:17 | FromDiscord | <⚶ Zeno> (edit) "I" => "`I`" |
17:41:57 | FromDiscord | <Smarc> how do i check two seq's of integers for duplicates? is there a better way than for-looping every item? |
17:45:30 | FromDiscord | <Smarc> or use `contain` on every item. is there a cooler nim-way? |
17:53:02 | * | PMunch quit (Quit: leaving) |
17:56:17 | systemdsucks | use a set? |
18:01:58 | FromDiscord | <Smarc> and then? |
18:03:21 | FromDiscord | <jtv> Sets will never keep more than one copy of an item |
18:08:22 | * | junaid_ quit (Remote host closed the connection) |
18:11:43 | FromDiscord | <⚶ Zeno> sent a long message, see http://ix.io/4jTr |
18:12:14 | FromDiscord | <⚶ Zeno> (edit) "http://ix.io/4jTr" => "https://paste.rs/dzD" |
18:13:08 | FromDiscord | <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:09 | FromDiscord | <planetis> for ints there is std/packedsets |
18:15:10 | FromDiscord | <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:21 | FromDiscord | <cow> (edit) "it?" => "it please?" |
18:17:46 | FromDiscord | <planetis> works if I remove import sequtils |
18:17:48 | FromDiscord | <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:18 | FromDiscord | <jtv> Agreed, it's something odd about sequtils, works w/o the import |
18:18:18 | FromDiscord | <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:38 | FromDiscord | <cow> so if both inserts exist a @[] can be either T or seq[T] |
18:18:44 | FromDiscord | <cow> with nested seqs |
18:19:16 | FromDiscord | <jtv> Still I'd expect a static error if it can't infer the type. |
18:20:11 | FromDiscord | <cow> is there an official way of reporting bugs that doesn't require a github account |
18:20:38 | FromDiscord | <jtv> No :/ |
18:21:05 | FromDiscord | <jtv> If I remember when I'm in front of a computer I'll report it if you like |
18:21:18 | FromDiscord | <cow> i would appreciate that, thanks |
18:21:22 | * | ltriant joined #nim |
18:22:22 | FromDiscord | <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:23 | FromDiscord | <jtv> All languages and locales will use Unicode to map characters. UTF-8 UTF-16 and UTF-32 are three different ENCODINGS |
18:23:27 | FromDiscord | <jtv> Of unicode |
18:23:33 | FromDiscord | <cow> In reply to @HitBlast "I'm working with strings": unicode has an isValidUTF8 proc |
18:23:51 | FromDiscord | <jtv> So, if you're not on Windows, UTF-8 is the most common encoding by far |
18:24:05 | FromDiscord | <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:10 | FromDiscord | <jtv> And any string that makes it into Nim would be UTF-8 encoded by default |
18:24:36 | FromDiscord | <jtv> Via any typical way to get data in (esp reading a file) |
18:25:15 | FromDiscord | <cow> i thought nim's strings were just a resizeable char array with length and encoding agnostic |
18:25:22 | FromDiscord | <jtv> UTF-16 is really only used on Windows, and UTF-32 is almost never used in user-exposed contexts |
18:26:00 | FromDiscord | <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:18 | FromDiscord | <cow> i wonder if you do a file.readAll() on a UTF16, what happens |
18:26:23 | FromDiscord | <jtv> Which is why all you have to do is run that check to see if it's valid utf-9 |
18:26:27 | FromDiscord | <cow> (edit) "UTF16," => "UTF16 file," |
18:26:32 | * | ltriant quit (Ping timeout: 272 seconds) |
18:26:43 | FromDiscord | <jtv> I am pretty sure Nim converts it to utf-8 based on my reading of the docs |
18:26:55 | FromDiscord | <cow> that's sane indeed |
18:26:56 | FromDiscord | <jtv> But haven't looked at the implementation |
18:27:02 | FromDiscord | <cow> but it would be nice to know where |
18:27:16 | FromDiscord | <jtv> It's easy enough to test |
18:27:36 | FromDiscord | <cow> fair, i'll come back to it when i have time maybe |
18:27:48 | FromDiscord | <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:31 | FromDiscord | <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:38 | FromDiscord | <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:37 | FromDiscord | <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:25 | FromDiscord | <ezquerra> A question about that though: is the —ic:stress just a way to (stress) test the IC feature? |
19:52:56 | FromDiscord | <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:26 | NimEventer | New thread by yister: Downloading files with missing protocol in redirect url, see https://forum.nim-lang.org/t/9778 |
19:55:50 | FromDiscord | <ShalokShalom> @ezquerra afaik, there are already improvments to the IC, who are merged and unreleased |
19:56:01 | FromDiscord | <ShalokShalom> Maybe I am wrong about this, Beef knows more |
19:56:58 | FromDiscord | <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:58 | FromDiscord | <ShalokShalom> Ping Beef |
19:58:05 | FromDiscord | <ShalokShalom> If you are brave enough 😛 |
19:58:24 | FromDiscord | <ShalokShalom> Or maybe ask in #internals |
20:13:30 | FromDiscord | <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:09 | FromDiscord | <jtv> ptr types are really about objects from the foreign function interface that the GC isn't managing |
20:14:30 | FromDiscord | <cow> it doesn't have to be FFI related |
20:14:32 | FromDiscord | <jtv> Getting refs via addr() and then getting back the value via [] is what you want |
20:14:57 | FromDiscord | <jtv> Sure, but it's the primary use case |
20:17:02 | FromDiscord | <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:40 | FromDiscord | <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:56 | FromDiscord | <cow> i think i am explaining stuff more confusing than it is |
20:18:12 | FromDiscord | <jtv> Yup. This is one of the many areas where the documentation is a bit too sparse though, |
20:18:28 | FromDiscord | <Guhnoo> thank you, my mistake was trying to do it with `ref` |
20:19:00 | FromDiscord | <Guhnoo> swapped with `ptr` and is working |
20:19:05 | FromDiscord | <cow> In reply to @jtv "Yup. This is": yeah definitely, I remember struggling with understanding ref syntax at first |
20:19:34 | FromDiscord | <cow> In reply to @Guhnoo "thank you, my mistake": can we look at the code? maybe we can give additional advice |
20:19:39 | FromDiscord | <jtv> I think the reason is that addr() actually gives you a pointer (can be dangled), not a ref |
20:19:49 | FromDiscord | <cow> yeah addr gives a ptr |
20:20:13 | FromDiscord | <jtv> You only get refs if you declare the type to be refs I do believe |
20:21:08 | FromDiscord | <cow> idk, if I use addr, it's in codebases where I use ptr, malloc, etc. rather than ref's 😅 |
20:21:51 | FromDiscord | <cow> (edit) "😅" => "😅, so haven't encountered that corner yet" |
20:22:05 | FromDiscord | <jtv> But you can do things like `var s1, s2: ref string` and then you can alias between them |
20:22:20 | FromDiscord | <jtv> And the GC tracks it |
20:24:15 | FromDiscord | <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:20 | FromDiscord | <cow> I just haven't found myself needing `addr` in code where i use `ref`s |
20:25:29 | FromDiscord | <Guhnoo> i just thought the pointers made sense for readability, rather than using `p.row[x]` everywhere |
20:26:01 | FromDiscord | <jtv> Well, you can do it that way for sure |
20:26:20 | FromDiscord | <jtv> Just not very idiomatic for Nim |
20:27:28 | FromDiscord | <cow> I usually do a template if I have this problem |
20:27:55 | FromDiscord | <cow> sent a code paste, see https://play.nim-lang.org/#ix=4jTW |
20:28:06 | FromDiscord | <jtv> Yeah same, templates (and macros) are awesome for factoring out code that's very repetitive to write |
20:28:46 | FromDiscord | <cow> but i guess a pointer works too |
20:28:57 | FromDiscord | <cow> as long as the pointer doesn't outlive the content |
20:29:25 | FromDiscord | <cow> (edit) "https://play.nim-lang.org/#ix=4jTW" => "https://play.nim-lang.org/#ix=4jTX" |
20:29:36 | FromDiscord | <cow> sent a code paste, see https://paste.rs/0TH |
20:30:46 | FromDiscord | <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:10 | FromDiscord | <cow> you can also do it with a function |
20:31:30 | FromDiscord | <cow> sent a code paste, see https://play.nim-lang.org/#ix=4jU1 |
20:32:07 | FromDiscord | <cow> it returns a value that can be assigned to |
20:32:22 | FromDiscord | <cow> (edit) "to" => "to, I believe" |
20:35:55 | * | pro quit (Quit: pro) |
20:40:23 | FromDiscord | <Guhnoo> wow, templates are really neat |
20:40:55 | FromDiscord | <Guhnoo> never used anything like that before |
20:43:18 | FromDiscord | <Guhnoo> it just knows what `p` is outside the scope |
20:47:41 | FromDiscord | <Guhnoo> cool stuff, thanks for that |
20:59:30 | FromDiscord | <cow> just beware, it doesn't work the other way by default |
20:59:45 | FromDiscord | <cow> this is not gonna work https://media.discordapp.net/attachments/371759389889003532/1058127203310784532/image.png |
21:03:38 | FromDiscord | <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:19 | FromDiscord | <cow> templates are as if their own scope |
21:05:16 | FromDiscord | <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:00 | FromDiscord | <@thatrandomperson5-6310e3b26da03> I don’t think it’s where the error comes from, any more ideas? |
22:25:23 | * | rockcavera joined #nim |
22:27:56 | FromDiscord | <voidwalker> blah, I spent the whole day trying to debug one thing : ( |
22:28:21 | FromDiscord | <voidwalker> ` if asocket.hasDataBuffered:` can anyone explain why this condition wouldn't pass, I am sure there is data to read |
22:28:34 | FromDiscord | <voidwalker> is it the same as "there is data received in socket" ? |
22:39:05 | FromDiscord | <Smarc> sent a code paste, see https://play.nim-lang.org/#ix=4jUt |
22:39:09 | FromDiscord | <Smarc> gives me 418, which is too low |
22:39:14 | FromDiscord | <Smarc> where is my thinking mistake? |
22:39:44 | FromDiscord | <Elegantbeef> Why are you using a set? |
22:40:29 | FromDiscord | <Smarc> so i can use intersection |
22:40:37 | FromDiscord | <Smarc> to easily spot overlaps |
22:40:48 | FromDiscord | <Elegantbeef> A set isnt needed for this problem a `Slice[int]` works |
22:41:06 | FromDiscord | <Smarc> hm, could you give me an example? |
22:42:28 | FromDiscord | <Elegantbeef> https://github.com/beef331/nimtrest/blob/master/aoc2022/day4/day4.nim for a spoiler |
22:42:39 | FromDiscord | <jtv> @voidwalker Sockets are a bit complicated, so some more context would be helpful |
22:43:08 | FromDiscord | <voidwalker> sent a code paste, see https://play.nim-lang.org/#ix=4jUx |
22:43:30 | FromDiscord | <Smarc> In reply to @Elegantbeef "https://github.com/beef331/nimtrest/blob/master/aoc": ye .. i really don't understand that example :s |
22:43:32 | FromDiscord | <voidwalker> (edit) "https://play.nim-lang.org/#ix=4jUx" => "https://play.nim-lang.org/#ix=4jUy" |
22:43:59 | FromDiscord | <voidwalker> sent a code paste, see https://play.nim-lang.org/#ix=4jUz |
22:44:29 | FromDiscord | <jtv> I assume the sockets are setup to be non-blocking? Are they AF_INET sockets? |
22:44:40 | FromDiscord | <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:06 | FromDiscord | <Elegantbeef> A slice is a `start..end` |
22:45:16 | FromDiscord | <voidwalker> just default settings async socket |
22:45:23 | FromDiscord | <voidwalker> TCP |
22:45:53 | NimEventer | New thread by Nlits: Type mistmatch for `int` and `sink T`, see https://forum.nim-lang.org/t/9779 |
22:46:12 | FromDiscord | <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:23 | FromDiscord | <Elegantbeef> You just wan `in` |
22:46:26 | FromDiscord | <Elegantbeef> `a in start..end` |
22:46:28 | FromDiscord | <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:38 | FromDiscord | <jtv> I do know Nim has a nice epoll wrapper I saw recently |
22:47:24 | FromDiscord | <voidwalker> I've no idea about select() and epoll(). why would I need them ? |
22:47:25 | FromDiscord | <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:40 | FromDiscord | <jtv> std/selectors |
22:47:48 | FromDiscord | <voidwalker> Yeah I will handle thousands of connections at once.. one day : ) |
22:48:04 | FromDiscord | <jtv> The whole idea is, for the sake of scaling, you register which file descriptors might eventually have data to read, |
22:48:32 | FromDiscord | <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:48 | FromDiscord | <voidwalker> oh is that true.. I see |
22:49:03 | FromDiscord | <voidwalker> I thought this epoll/select thing was kinda old/deprecated with async sockets |
22:49:04 | FromDiscord | <jtv> And, honestly, once you master the APIs, it's far less error prone |
22:49:27 | FromDiscord | <Elegantbeef> Smarc the day doesnt require a set it just requires overlap ranges |
22:49:48 | FromDiscord | <Elegantbeef> You dont care whether it has 3, 4, 5 |
22:49:51 | FromDiscord | <voidwalker> welp, atm it seems I am far from mastering even simple socket code :\ |
22:49:52 | FromDiscord | <Elegantbeef> you know it's 3..5 |
22:49:52 | FromDiscord | <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:30 | FromDiscord | <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:16 | FromDiscord | <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:31 | FromDiscord | <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:35 | FromDiscord | <Elegantbeef> It's a continous range |
22:52:50 | FromDiscord | <Elegantbeef> You only care where end/start |
22:53:28 | * | ltriant joined #nim |
22:56:27 | FromDiscord | <Elegantbeef> you know whether `2-4` is in `6-8` if `2 > 6` or `4 < 6` |
22:57:06 | FromDiscord | <Elegantbeef> You know whether a range is fully encapsulated if `2 > 6 and 4 < 8` |
23:15:46 | FromDiscord | <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:00 | FromDiscord | <voidwalker> well, fixed my bug.. got rid of the socket.peek logic |
23:25:13 | FromDiscord | <jtv> That's good, sorry I was afk |
23:25:30 | FromDiscord | <voidwalker> for some reason the data is gone at some point with the peek flag set on |
23:25:41 | FromDiscord | <voidwalker> doesn't read anything, although there should be data to read |
23:25:47 | FromDiscord | <voidwalker> I think there's a bug somewhere |
23:26:12 | FromDiscord | <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:42 | FromDiscord | <voidwalker> it's all poorly documented : ( |
23:26:46 | FromDiscord | <voidwalker> especially for a noob |
23:27:16 | FromDiscord | <jtv> That's currently true most of Nim right now, unfortunately :/ |
23:28:17 | FromDiscord | <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:06 | FromDiscord | <jtv> That's definitely a shame, as it's a truly awesome language in so many respects |
23:29:59 | FromDiscord | <voidwalker> Indeed, and what's the deal with the documentation generated from the source code file |
23:30:40 | FromDiscord | <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:47 | FromDiscord | <jtv> I'm kind of that way too, often |
23:30:53 | FromDiscord | <voidwalker> I am supposed to commit changes on github on the .nim core files to get better docs? |
23:31:17 | FromDiscord | <jtv> I was thinking if I get time I might produce some external HOWTOs basically |
23:31:30 | FromDiscord | <voidwalker> we need something like the arch wiki |
23:31:38 | FromDiscord | <voidwalker> cause nim is the archlinux of programming : P |
23:31:45 | FromDiscord | <jtv> Heh 🙂 |
23:32:10 | FromDiscord | <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:21 | FromDiscord | <voidwalker> I am sure the community will produce a great documentation in no time, in wiki style |
23:32:36 | FromDiscord | <voidwalker> just like they producer many better alternative libs to stdlib |
23:32:41 | FromDiscord | <voidwalker> (edit) "producer" => "produced" |
23:36:32 | FromDiscord | <voidwalker> @Tony Rubak good question... you can use either copymem, a serialize/deserialize lib like binarylang (overkill for just this small use) |
23:38:00 | FromDiscord | <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:43 | FromDiscord | <voidwalker> yes it is hideous : ) |
23:39:02 | FromDiscord | <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:18 | FromDiscord | <voidwalker> but then again, if it were into stdlib, it would be implemented like that probably |
23:39:34 | FromDiscord | <Tony Rubak> I want to do it without stack allocating a copy of the whole data |
23:39:45 | FromDiscord | <Tony Rubak> like... what if the data is a gigabyte lol |
23:40:26 | FromDiscord | <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:11 | FromDiscord | <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:43 | FromDiscord | <jtv> Sure one second |
23:42:49 | FromDiscord | <jtv> What data type are you starting from? |
23:42:56 | FromDiscord | <jtv> array of char? |
23:43:11 | FromDiscord | <Tony Rubak> I'm pretty sure it's a string because that's what `recv` returns |
23:44:42 | FromDiscord | <jtv> Okay, sure. But std/endian definitely will do the job for you, without having to do your own casting |
23:45:37 | FromDiscord | <jtv> Though, the docs don't say what the assumptions are of the endianness of the source data, lol |
23:46:06 | FromDiscord | <Tony Rubak> yeah, which is... odd |
23:46:31 | FromDiscord | <jtv> Like I said, the docs suck all around |
23:47:14 | FromDiscord | <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:52 | FromDiscord | <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:08 | FromDiscord | <jtv> Fair enough yes |
23:54:16 | FromDiscord | <jtv> sent a code paste, see https://play.nim-lang.org/#ix=4jUQ |
23:54:52 | FromDiscord | <jtv> You can obviously be more compact about it 🙂 |
23:57:19 | FromDiscord | <Tony Rubak> ah, ok... `len_ptr = cast[ptr uint8](unsafeAddr(frame[2]))` thanks! |
23:57:36 | FromDiscord | <Tony Rubak> that's like... idk if it's more or less hideous, but it's certainly not copying data lol |
23:58:52 | FromDiscord | <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:35 | FromDiscord | <Tony Rubak> can we offset pointers in nim? |
23:59:59 | FromDiscord | <jtv> No, `echo cast[ptr int](addr(s[0]))[0]` doesn't work |