00:00:08 | FromDiscord | <jtv> You have to index into s and then use [] |
00:00:26 | FromDiscord | <Elegantbeef> There are libraries like ptr\_math |
00:00:28 | FromDiscord | <jtv> That makes it worse to steal the [] for deref imho π |
00:00:37 | FromDiscord | <Elegantbeef> But yes pointer arithmetic doesnt exist in Nim |
00:00:54 | FromDiscord | <Tony Rubak> gotcha, I can work with this. thanks. |
00:01:13 | FromDiscord | <Elegantbeef> The conventional thing to do is `cast[ptr UncheckedArray[T]](myPtr)` |
00:01:18 | FromDiscord | <jtv> But frankly, my view is, the day-to-day bits in Nim are so much better choices than other languages, that I don't mind some of the things like this... other languages are worse |
00:01:59 | FromDiscord | <jtv> So just cast it to an int array, then you can index it, makes sense |
00:03:28 | * | ltriant quit (Ping timeout: 272 seconds) |
00:03:55 | FromDiscord | <Tony Rubak> I'm liking parts of nim and disliking others just like everything else; trying to see how far I get on this thing before I get too annoyed and go do something else lol |
00:05:02 | * | ltriant joined #nim |
00:05:24 | FromDiscord | <Tony Rubak> the unit testing stuff annoyed me enough that I kinda gave up, but that's kinda π€· |
00:06:46 | FromDiscord | <jtv> The stuff that nimble does by default? |
00:07:35 | FromDiscord | <Tony Rubak> I couldn't figure out how to make `nimble test` do anything other than say "there are no tests" or something like that lol |
00:07:49 | FromDiscord | <leorize> https://github.com/disruptek/balls \<- this project is my favorite unittest tool |
00:07:55 | FromDiscord | <Elegantbeef> It searches `tests` for files that start with `t.nim` |
00:08:12 | FromDiscord | <jtv> Yeah, and if you use nimble init to set up your project, it gives you examples |
00:08:22 | FromDiscord | <jtv> I'll check that out, leorize, thanks. |
00:08:25 | FromDiscord | <Tony Rubak> In reply to @jtv "Yeah, and if you": I did this and it did not |
00:08:46 | FromDiscord | <jtv> Nim also ships w/ Testament, which I haven't used yet, but seems decent (if underdocumented) |
00:08:56 | FromDiscord | <jtv> Odd, it's done it for me and I've set up a few projects already |
00:09:08 | FromDiscord | <Tony Rubak> the documentation for testament was so bad that I just immediately gave up on that one |
00:09:11 | FromDiscord | <jtv> But the nimble documentation has made me actively angry |
00:09:45 | FromDiscord | <Tony Rubak> In reply to @Elegantbeef "It searches `tests` for": I did not realize the filenames needed to begin with t. Thank you. |
00:09:46 | FromDiscord | <jtv> TBH, if the language itself weren't such a good fit for what I want in a language, the tooling and docs would have caused me to bounce pretty quickly |
00:10:17 | FromDiscord | <jtv> I've spent way too much time rtfc'ing instead of rtfm'ing |
00:10:28 | FromDiscord | <Tony Rubak> I'm a masochist; I was using the first public release of F# and as long as I can work around the tools it usually doesn't bother me too much |
00:11:37 | * | ltriant quit (Ping timeout: 252 seconds) |
00:17:26 | * | ltriant joined #nim |
00:18:58 | FromDiscord | <Smarc> sent a code paste, see https://play.nim-lang.org/#ix=4jUW |
00:23:14 | FromDiscord | <Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4jUZ |
00:23:26 | FromDiscord | <Elegantbeef> Obviously should use variables |
00:25:16 | FromDiscord | <Smarc> Also results in 418 |
00:27:41 | FromDiscord | <Elegantbeef> Oh you also need the inverse |
00:27:44 | FromDiscord | <Elegantbeef> You need to check if a in b or b in a |
00:29:09 | FromDiscord | <Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4jV2 |
00:29:14 | FromDiscord | <Elegantbeef> But that's identical to my code π |
00:31:24 | FromDiscord | <Smarc> what are a and b in this case? |
00:31:46 | FromDiscord | <Elegantbeef> `fstNumber[0].parseInt` and `fstNumber[1].parseInt` respectively |
00:36:02 | * | azimut joined #nim |
00:36:49 | * | ltriant quit (Ping timeout: 268 seconds) |
00:37:38 | FromDiscord | <Smarc> 418 all the way :D |
00:46:33 | NimEventer | New thread by void09: Is flags={SocketFlag.Peek} buggy or am I missing something ?, see https://forum.nim-lang.org/t/9780 |
00:48:11 | * | azimut quit (Ping timeout: 255 seconds) |
00:48:35 | * | azimut joined #nim |
00:56:48 | * | ltriant joined #nim |
01:15:10 | * | wallabra_ joined #nim |
01:16:56 | * | wallabra quit (Ping timeout: 272 seconds) |
01:16:56 | * | wallabra_ is now known as wallabra |
01:23:39 | * | ltriant quit (Quit: leaving) |
01:26:03 | * | krux02 quit (Remote host closed the connection) |
01:36:38 | * | derpydoo quit (Ping timeout: 268 seconds) |
02:05:02 | FromDiscord | <jtv> @voidwalker From the asyncnet docs: "Warning: The Peek flag is not yet implemented." |
02:30:23 | * | wallabra_ joined #nim |
02:30:30 | FromDiscord | <sOkam!> How would you avoid using `while true:` with a bunch of `if condition: return` in its body? |
02:31:38 | * | wallabra quit (Ping timeout: 260 seconds) |
02:31:39 | * | wallabra_ is now known as wallabra |
02:34:33 | FromDiscord | <jtv> What's the context? |
02:35:44 | FromDiscord | <jtv> If you can't refactor the logic to have all of the conditions execute at the beginning or end of the loop, you might not be able to |
02:37:21 | FromDiscord | <sOkam!> context:β΅https://youtu.be/ajv46BSqcK4?t=1655 |
02:38:18 | FromDiscord | <sOkam!> Probably doesn't help much, since the algo is fairly complex π€·ββοΈ |
02:39:40 | FromDiscord | <jtv> Yeah, it's fine. In general, you may not be able to remove all if/break statements from a loop, it just depends. |
02:46:35 | FromDiscord | <sOkam!> is it possible to limit the size of sequence to X items?β΅i was thinking of using arrays, since the size is known, but don't know how to get the non-init length of the array when first adding values |
02:47:38 | FromDiscord | <sOkam!> something like `seq[2,int]` |
02:47:59 | FromDiscord | <jtv> You mean you know what the eventual size will be but want to prealloc the right size? |
02:48:24 | FromDiscord | <sOkam!> i know the eventual size, but the values might not be init yet, and i would need to get the size of the currently init values |
02:48:35 | FromDiscord | <jtv> var s:seq[x] = newSeqOfCap(n) |
02:48:44 | FromDiscord | <jtv> Where x is the type of the sequence |
02:48:51 | FromDiscord | <jtv> And n is the number of items |
02:48:55 | FromDiscord | <sOkam!> yeah, but it doesn't allow that to be used in the type |
02:49:10 | FromDiscord | <Rika> You need to specify the generic type in the new procedure too no? |
02:49:12 | FromDiscord | <jtv> The size isn't part of the type |
02:49:14 | FromDiscord | <sOkam!> the max size is know at compile time, which is why i thought arrays are better... but |
02:49:30 | FromDiscord | <jtv> Even if it's generic, |
02:49:55 | FromDiscord | <sOkam!> how do i do `arrayVar.len`, without always getting `4` if i said `array[4, int]`? |
02:50:03 | FromDiscord | <jtv> proc doIt[T]() = ... s = newSeqOfCap[T](n) should do the right thing |
02:50:28 | FromDiscord | <Rika> In reply to @sOkam! "how do i do": You donβt. |
02:50:33 | FromDiscord | <jtv> I thought you said you know the number of elements up front?? |
02:50:52 | FromDiscord | <sOkam!> i know the max number |
02:51:12 | FromDiscord | <jtv> If the size of the item varies by type, and you know the max number, then just newSeqOfCap[T](max) |
02:51:15 | FromDiscord | <sOkam!> (edit) "i know the max ... number" added "potential" |
02:51:39 | FromDiscord | <jtv> You can truncate later if you vastly overestimated |
02:51:41 | FromDiscord | <Rika> In reply to @jtv "If the size of": Really just do this |
02:51:56 | FromDiscord | <sOkam!> k |
02:52:24 | FromDiscord | <jtv> Generally doesn't cost you... even if you've overestimated by a lot, the memory you're not using is going to mainly sit on pages that are just forever swapped out b/c they're unused |
02:56:06 | * | xet7 joined #nim |
02:57:14 | * | azimut quit (Quit: ZNC - https://znc.in) |
02:57:24 | * | azimut_ joined #nim |
03:00:09 | FromDiscord | <sOkam!> i was "worried" more about the allocation, or access cost, since the max size is known at compile timeβ΅but I guess its avoided by creating a constructor that allocates once, and the size is not changed anywhere else, maybe π€·ββοΈ |
03:04:20 | FromDiscord | <Elegantbeef> Someone really needs to make a fixed size seq π |
03:08:39 | FromDiscord | <jtv> LOL |
03:09:15 | FromDiscord | <jtv> Yeah, you could just use an array π But pre-allocating the seq is not going to cost you anything |
03:29:57 | * | tiorock joined #nim |
03:29:57 | * | tiorock quit (Changing host) |
03:29:57 | * | tiorock joined #nim |
03:29:57 | * | rockcavera is now known as Guest4840 |
03:29:57 | * | Guest4840 quit (Killed (copper.libera.chat (Nickname regained by services))) |
03:29:57 | * | tiorock is now known as rockcavera |
04:02:07 | FromDiscord | <jtv> There's not a more flexible code formatting tool than nimpretty in the ecosystem, is there? |
04:04:27 | FromDiscord | <sOkam!> morepretty is slightly better |
04:05:01 | FromDiscord | <sOkam!> could argue its close to being tie, though, when used to clang-format |
04:05:14 | FromDiscord | <sOkam!> (edit) "could argue its close to being tie, though, when used to clang-format ... " added "instead π" |
04:06:04 | FromDiscord | <sOkam!> (edit) "could argue its close to being tie, though, when used to ... clang-format" added "the customization of" | removed "instead" |
04:06:04 | FromDiscord | <jtv> Yeah, that's the problem. Every time I run nimpretty I cringe when I can't get the exact style I want, including aligning stuff into columns, etc :). I might be a little too ocd |
04:06:15 | FromDiscord | <sOkam!> ye same π |
04:06:48 | FromDiscord | <jtv> Thanks for the recommendation, checking it out now |
04:08:59 | FromDiscord | <jtv> BTW, I did also find this one that seems SLIGHTLY more configurable: https://github.com/FedericoCeratto/nimfmt |
04:15:01 | FromDiscord | <jtv> Tho, that one doesn't seem to build anymore, not sure I can be bothered to fix it. Ugh. |
04:19:38 | * | rockcavera quit (Remote host closed the connection) |
04:20:06 | FromDiscord | <m4ul3r> In reply to @jtv "BTW, I did also": yo thanks for recommending this, i really like black python module and this seems similar |
04:21:41 | * | xet7 quit (Remote host closed the connection) |
04:22:10 | FromDiscord | <jtv> Yeah, it's closer to what I would want, though it's clearly unmaintained and needs a bit of love I don't have time to give it |
04:23:06 | * | xet7 joined #nim |
04:23:08 | FromDiscord | <jtv> morepretty has changed the semantics of a repo I forked from someone else to the point of breaking the code pretty badly. Mangled a bunch of import statements. |
04:24:21 | FromDiscord | <sOkam!> ouch |
04:28:42 | FromDiscord | <jtv> It wasn't bad, but that's not good either π |
04:37:58 | * | arkurious quit (Quit: Leaving) |
05:34:45 | * | rockcavera joined #nim |
07:06:16 | * | rockcavera quit (Remote host closed the connection) |
07:29:22 | * | pro joined #nim |
08:01:10 | FromDiscord | <_ π> hi, how do i do a constant hashmap in nim? |
08:14:33 | FromDiscord | <voidwalker> What is your favourite bit array lib ? I found https://github.com/treeform/bitty/ , https://github.com/MarcAzar/BitVector , https://github.com/adokitkat/bitseqs , https://github.com/onecodex/nim-bitarray , https://github.com/YesDrX/bitarray |
08:17:48 | FromDiscord | <voidwalker> awesome nim has BitVector listed. Then again, treeform's code should be good. Too many options π¦ |
08:19:55 | * | jmdaemon quit (Ping timeout: 248 seconds) |
08:23:29 | FromDiscord | <voidwalker> sent a code paste, see https://play.nim-lang.org/#ix=4jVV |
08:23:32 | FromDiscord | <Phil> sent a long message, see http://ix.io/4jVW |
08:23:36 | FromDiscord | <Phil> (edit) "http://ix.io/4jVW" => "https://paste.rs/HTX" |
08:24:07 | FromDiscord | <Phil> (edit) "http://ix.io/4jVX" => "https://paste.rs/UVu" |
08:25:33 | FromDiscord | <Phil> (edit) "http://ix.io/4jVZ" => "http://ix.io/4jVY" |
08:31:41 | FromDiscord | <voidwalker> well, BitVector seems like the better (faster) choice. I can probably swap between them seamlessly |
08:31:49 | FromDiscord | <voidwalker> (edit) "well, BitVector seems like the better (faster) choice. I can probably swap between them seamlessly ... " added "later if needed" |
08:34:26 | FromDiscord | <_ π> In reply to @Isofruit "constant as in immutable?": > constant as in immutable?β΅this one |
08:34:46 | FromDiscord | <_ π> whats const vs let tho? |
08:35:36 | FromDiscord | <luteva> In reply to @leorize "https://github.com/disruptek/balls \<- this project": Hi! This seems to be pretty cool! I just can't find it in nimble packages. Is there a reason to not publish it as a nimble package? Or maybe, my nimble config is broken...??? |
08:50:44 | FromDiscord | <planetis> Computed at compile time for example https://hookrace.net/blog/what-is-special-about-nim/#run-regular-code-at-compile-time |
08:58:49 | FromDiscord | <voidwalker> well, it's from one of nimskull's - the nim fork, main devs, maybe that's why. There's a few good libs not in nimble, not sure exactly what reason people have not to publish it there |
09:24:35 | FromDiscord | <Phil> In reply to @_ π "whats const vs let": I assume you came over from python? |
09:27:51 | FromDiscord | <Phil> sent a long message, see http://ix.io/4jW8 |
09:28:22 | FromDiscord | <Phil> If you need a set from g to a user defined letter, that must happen at runtime because you can't know what letter the user will give you |
09:28:32 | FromDiscord | <voidwalker> hey Phil, don't mislanguage them by mistake : P |
09:33:09 | FromDiscord | <_ π> In reply to @Isofruit "I assume you came": no, from other languages but I'm not aware of the difference |
09:37:23 | * | wallabra quit (Ping timeout: 264 seconds) |
09:37:42 | FromDiscord | <voidwalker> sent a code paste, see https://play.nim-lang.org/#ix= |
09:41:04 | FromDiscord | <luteva> or in other words: the value of a const is set at compile time. so you cannot use it, if the value can only be calculated/set at runtime. |
09:42:24 | FromDiscord | <luteva> if you want an immutable value to be calculated/set the first time the program is running the code section, you have to use let. |
09:43:23 | * | PMunch joined #nim |
09:55:46 | FromDiscord | <voidwalker> https://github.com/MarcAzar/BitVector/blob/master/src/bitvector.nim#L44 - do you think it's possible to initialize this bit vector doing memcopy from a string ? |
09:56:53 | FromDiscord | <voidwalker> I tried ` copyMem(aPeer.bitField.addr, bitField[0].unsafeAddr, bitField.len)` but this fails, I get a negative value for the length |
09:57:01 | FromDiscord | <luteva> is there a container/isolation tool writen in nim? something like podman, docker (or jib, for the java world) or something like this? |
10:03:50 | FromDiscord | <voidwalker> Is there any benefit to passing a string to a proc as "var string" for the purpose of being able to use .addr instead of .unsafeaddr ? |
10:04:35 | FromDiscord | <voidwalker> without needing for the string to be mutable in that proc |
10:06:16 | FromDiscord | <voidwalker> Welp, beef-less hours : D |
10:17:15 | FromDiscord | <luteva> In reply to @voidwalker "Is there any benefit": good question! I am also unsure what .unsafeaddr is used for. As I understand .unsafeaddr is a hint, that you are doing something "unsafe". So you could change an immutable (let). But if this is correct, making an immutable mutable just to use a "safe" method is absolutely stupid. |
10:18:46 | FromDiscord | <enthus1ast> i think there was a discussion lately that combines addr and unsafeaddr |
10:19:07 | FromDiscord | <planetis> UnsafeAddr is deprecated in v2 |
10:19:41 | FromDiscord | <enthus1ast> ^ this, but addr will be upgraded accordingly |
10:20:12 | FromDiscord | <amadan> In reply to @luteva "is there a container/isolation": https://github.com/fox0430/nicoru not too sure if its still being worked on though |
10:21:49 | FromDiscord | <planetis> In reply to @_ π "whats const vs let": There is a const example at the Nim website as well |
10:25:12 | FromDiscord | <voidwalker> Are there any data structures in a lib somewhere, optimized to hold filesystem dir/file structure ? |
10:26:04 | FromDiscord | <voidwalker> I can't decide if a tree or a flat sequence would be better (assume they are already sorted by path) |
10:26:56 | PMunch | Depends on what you want to do and whether logic or speed is more important to you |
10:30:26 | FromDiscord | <luteva> In reply to @voidwalker "Are there any data": maybe brianshannan/nim-trees |
10:31:25 | FromDiscord | <voidwalker> well, I am supposed to parse a .torrent file, which has them as a seq of @["path","to","file"] format. Torrent v2 specs though have them stored as a tree structure. Of course, I'd like to use only 1 implementation for both source. Then, I'd need fastest possible lookup. From a range of bytes, I need to determine the files/paths they belong to, very frequently. |
10:31:39 | FromDiscord | <voidwalker> (edit) "source." => "versions." |
10:31:50 | FromDiscord | <voidwalker> (edit) "1" => "one data structure" |
10:32:01 | FromDiscord | <voidwalker> (edit) "From" => "For" |
10:32:28 | FromDiscord | <luteva> i would try using a tree. |
10:33:02 | FromDiscord | <voidwalker> That is a distinct problem. Given len1,len2, ... lenN of distinct files, return the files of a given range |
10:33:48 | FromDiscord | <luteva> it should be easier to flatten a tree than to build the tree from a flat structre. imho |
10:34:11 | FromDiscord | <voidwalker> building time is not that important.. it's only done once. While retrieving data from it is done millions of times |
10:35:11 | FromDiscord | <luteva> that's why i would try using the tree. πβ΅build it once, then flatten to compare. not the otehr way around. |
10:36:57 | FromDiscord | <voidwalker> It also needs to be memory space efficient. File paths are very repetitive. Trees solve that problem by having the file stucture embedded in its own structure |
10:37:18 | FromDiscord | <voidwalker> For flat sequence, I need to use a dictionary to deduplicate values |
10:40:02 | PMunch | @voidwalker, I'd use essentially a finger table |
10:40:03 | FromDiscord | <luteva> .... and this can even lead to name clashes (unless you effectively implement a tree). so one more reason to use a tree π |
10:40:46 | PMunch | So you get paths and the length of each file as I understand it. When you get a packet of data you need to know which file it belongs to based on the lengths of the various files, correct? |
10:41:11 | FromDiscord | <voidwalker> yes. it is all counted as one continous byte range, made up of individual files |
10:41:54 | FromDiscord | <voidwalker> unfortunately, a byte range can span multiple files.. which adds some complexity. shitty protoco : ) well ,was good enough 20 years ago |
10:42:08 | PMunch | So what you do is store a sequence of tuples with the range of bytes it accepts and the path. Then you use a binary lookup on this sequence to determine which file a chunk goes into |
10:43:01 | FromDiscord | <voidwalker> Do I really need tuples though ? |
10:43:09 | PMunch | Pretty much |
10:43:18 | PMunch | But why wouldn't you use tuples? |
10:43:23 | PMunch | I mean they could be objects |
10:43:33 | FromDiscord | <voidwalker> Since file[n].end + 1 == file[n+1].start |
10:43:44 | PMunch | Yes, but you still need the path |
10:44:28 | FromDiscord | <voidwalker> binary lookup as in binary search ? |
10:44:40 | PMunch | You wouldn't have to store the start and the end, but it makes the searching algorithm slightly easier (although potentially slower because of caching..) |
10:44:43 | PMunch | Yes |
10:44:57 | FromDiscord | <voidwalker> blah I just realised this will not be O(1) time |
10:45:27 | FromDiscord | <voidwalker> but no other way around it unless I make a big array where a[n] = index_of_the_file |
10:45:28 | FromDiscord | <voidwalker> no ? |
10:45:43 | FromDiscord | <voidwalker> (edit) "but no other way around it unless I make a big array ... where" added "the size of the byte range," |
10:45:52 | PMunch | Well.. |
10:46:15 | PMunch | There's probably some fuckery you can do to get O(1) |
10:46:26 | FromDiscord | <luteva> if you want 0(1) you will probably need to index/key-value |
10:47:10 | FromDiscord | <voidwalker> let's see. 4GB torrent, 4.3 billion bytes |
10:47:39 | PMunch | But how many files do you expect in a torrent? |
10:47:40 | FromDiscord | <voidwalker> nope, that won't fly : ) |
10:47:53 | FromDiscord | <voidwalker> can be 1 to tens of thousands or even millions |
10:48:09 | PMunch | Binary search is pretty good though |
10:48:18 | PMunch | I mean you could make a tree structure as well |
10:48:32 | PMunch | If you want even faster lookups |
10:48:49 | FromDiscord | <voidwalker> I guess I should look at the established torrent libs and see what they did. This is basic enough that they probably got it right |
10:49:19 | FromDiscord | <voidwalker> bot not basic enough to be obvious for me : ) |
10:50:57 | PMunch | Say you have a split factor of 32, the first node splits your 4GB range into 32 125Mb chunks. These are equally split so you just need to divide your index by 32 to figure out which branch to take |
10:51:32 | FromDiscord | <luteva> maybe a Btree (or a B+ tree)? |
10:51:34 | PMunch | Of course you need to add files which end up on a boundry to more than one leaf node |
10:51:45 | PMunch | So it's a bit more complex |
10:52:02 | PMunch | How big are your chunks by the way? |
10:52:08 | FromDiscord | <voidwalker> Yeah I am probably going to write it as one big binary chunk, and split at the end |
10:52:40 | PMunch | That's not great if you download something big and don't have a lot of room left on your device though |
10:52:54 | FromDiscord | <voidwalker> https://media.discordapp.net/attachments/371759389889003532/1058336875963756584/slide_13.png |
10:53:26 | FromDiscord | <voidwalker> there's also this complication called blocks.. you cannot request a whole piece, but subblocks of it. Blocks are <=16kB in size |
10:53:40 | FromDiscord | <voidwalker> pieces can be 128kB to 64MB or more |
10:53:41 | PMunch | Wait, what's the difference between pieces and blocks? |
10:54:33 | FromDiscord | <voidwalker> well blocks are the thing you can actually ask for a client to give you, not pieces. You ask for piece index, offset, and length. you get that, and have to assemble those into a whole piece, which you can hash check for integrity |
10:54:41 | PMunch | Right, but you know the indices will be incrementing by 16kB. So already there you have saved yourself quite a bit of possibilities |
10:55:10 | FromDiscord | <voidwalker> well, the last bit won't end up in a whole 16kB, so you have to cut it : ) |
10:55:32 | FromDiscord | <voidwalker> it's also possible the torrent was not created in a sane way and pieces are not divisible by 16kB. But that's very unlikely |
10:55:44 | * | deadmarshal quit (Remote host closed the connection) |
10:55:51 | PMunch | Sure, but you went get an index of 10*16kB+1 |
10:56:19 | PMunch | It will always be some multiple of 16k |
10:57:48 | FromDiscord | <voidwalker> yo could technically expand this into just block logic, so you only keep track of blocks have/needed/active.. and handle hashing at the end |
10:57:53 | FromDiscord | <voidwalker> (edit) "yo" => "you" |
11:00:43 | FromDiscord | <voidwalker> https://github.com/arvidn/libtorrent/blob/RC_2_0/src/torrent.cpp - how on earth can they maintain this, this single file is 12k lines |
11:01:09 | * | pro quit (Quit: pro) |
11:17:06 | FromDiscord | <haxscramper> and disruptek does not see any reason to add packages to nimble list anyway |
11:17:07 | FromDiscord | <haxscramper> since you can use git URLs |
11:17:07 | FromDiscord | <haxscramper> because there is no real reason to do this TBH |
11:17:10 | FromDiscord | <haxscramper> it was written before nimskullβ΅(@luteva) |
11:17:47 | * | deadmarshal_ joined #nim |
11:28:43 | FromDiscord | <luteva> ok i see. well it is nice to get/search a list of nim packages, search for tags etc. ... but if you always already know in advance, what you would like to install, then ok, you can use the url. |
11:29:01 | FromDiscord | <luteva> thx |
11:31:24 | FromDiscord | <haxscramper> you can search on github |
11:31:25 | FromDiscord | <haxscramper> https://github.com/search?q=language%3Anim+parser |
11:31:42 | FromDiscord | <haxscramper> nimph package manager just searches on github as well, there is an API to do this |
11:32:44 | NimEventer | New Nimble package! bossy - Makes supporting command line arguments easier, see https://github.com/guzba/bossy |
11:32:44 | NimEventer | New Nimble package! engineio - An Engine.IO client library for Nim, see https://github.com/samc0de/engineio |
11:33:04 | FromDiscord | <luteva> In reply to @haxscramper "https://github.com/search?q=language%3Anim+parser": oh yes of course... |
11:50:10 | NimEventer | New thread by yister: Can I create a unique hash of a proc and all its dependencies?, see https://forum.nim-lang.org/t/9781 |
12:00:37 | FromDiscord | <luteva> sent a code paste, see https://paste.rs/JsK |
12:02:59 | PMunch | @luteva, because you're not casting a person, but a pointer to a person |
12:03:05 | PMunch | And vice-versa when converting back |
12:03:18 | PMunch | Your repr(byte) is actually not correct. |
12:04:08 | PMunch | If you remove the two `unsafeAddr` everything works fine |
12:04:36 | PMunch | (And you can see the 15 from the age in the byte representation of the object) |
12:05:10 | FromDiscord | <luteva> oh yes. i see! π |
12:05:16 | FromDiscord | <luteva> thx! |
12:05:26 | PMunch | The first eight bytes is a pointer to the string object, and the next 8 bytes is the integer |
12:08:53 | FromDiscord | <luteva> ok so, if Person is a 'ref object' the person.unsafeAddr would be correct? |
12:09:33 | FromDiscord | <luteva> oh, no... |
12:11:26 | PMunch | Well then you'd need to cast to a `ptr array` and not just an array |
12:11:29 | PMunch | But yes |
12:11:43 | PMunch | You could of course also then dereference that array by `[]` |
12:13:28 | * | pro joined #nim |
12:21:01 | FromDiscord | <cow> can't you directly cast a ref object to a ptr, without .unsafeAddr |
12:23:30 | FromDiscord | <cow> also, if you do sizeof(Person) when Person is a ref object, it will return the size of the pointer |
12:24:01 | FromDiscord | <enthus1ast> we should add a "readPasswordFromStdin" like proc to eg terminal that just prompts without hiding, for yes no question etc |
12:25:12 | FromDiscord | <cow> works https://media.discordapp.net/attachments/371759389889003532/1058360100391235664/image.png |
12:25:23 | FromDiscord | <cow> https://play.nim-lang.org/#ix=4jWP |
12:26:39 | FromDiscord | <cow> (repr also printed some pointers which I cut off from the comments) |
12:27:38 | FromDiscord | <cow> @luteva |
12:29:15 | FromDiscord | <cow> you can technically also cast back to `Person` but someone more experienced will have to tell us if it's okay to cast pointers to `ref` types (does it work with the GC?) |
12:29:49 | FromDiscord | <luteva> ahhhh thx a lot @cow |
12:30:03 | FromDiscord | <cow> np π |
12:30:51 | * | deadmarshal_ quit (Quit: IRCNow and Forever!) |
12:32:39 | FromDiscord | <cow> uh oh this threw a C compilation error https://play.nim-lang.org/#ix=4jWR |
12:32:53 | FromDiscord | <cow> i tried to show an example with unsafeAddr |
12:35:51 | FromDiscord | <cow> In reply to @cow "uh oh this threw": https://media.discordapp.net/attachments/371759389889003532/1058362780752814080/image.png |
12:35:55 | FromDiscord | <cow> um help? |
12:38:22 | FromDiscord | <enthus1ast> @luteva\: @cow this will not contain the content of the string |
12:38:23 | FromDiscord | <enthus1ast> why not just use json/msgpack/stream ? |
12:38:24 | FromDiscord | <enthus1ast> or any other serializer libs |
12:38:24 | FromDiscord | <enthus1ast> flatty |
12:38:25 | FromDiscord | <enthus1ast> why not just use json/msgpack/streams ? |
12:39:00 | FromDiscord | <cow> I thought this was an educational example |
12:39:09 | FromDiscord | <cow> but you are right, it just contains the pointer to the string |
12:39:09 | FromDiscord | <luteva> yes. for learning! |
12:39:14 | FromDiscord | <enthus1ast> when you plan to receive such stuff from a untrusted source, i would never cast, but parse |
12:39:55 | FromDiscord | <cow> in fact, the string would probably be GC'd if person escapes the scope |
12:42:14 | FromDiscord | <cow> i think nim playground is currently not doing well btw |
12:43:02 | FromDiscord | <cow> if you do this, the string gets lost https://media.discordapp.net/attachments/371759389889003532/1058364592130097213/image.png |
12:44:27 | FromDiscord | <cow> it somehow still works? https://media.discordapp.net/attachments/371759389889003532/1058364945726713916/image.png |
12:46:15 | FromDiscord | <enthus1ast> if name would be an array, it would work i guess. But the whole concept of this is flawed and i would not do it like this (for most usecases i could thing of at least) but just use a serializer |
12:54:00 | FromDiscord | <enthus1ast> sent a code paste, see https://play.nim-lang.org/#ix=4jWY |
14:17:07 | FromDiscord | <luteva> sent a code paste, see https://paste.rs/fIQ |
14:17:55 | FromDiscord | <ambient> afaik all Nim types are compile time |
14:18:17 | FromDiscord | <luteva> so a const string should work? |
14:21:20 | FromDiscord | <luteva> .... ok no... but, this would be possible using a macro, right? |
14:25:21 | FromDiscord | <luteva> so i would have to search for the type given as a string by the caller. is that possible? |
14:25:36 | FromDiscord | <luteva> (edit) "so i would have to search for the type given as a string by the caller. is that possible? ... " added "Using a macro?" |
14:25:50 | FromDiscord | <luteva> (edit) "possible? Using a macro?" => "possible, with macros?" |
14:28:10 | FromDiscord | <cow> `proc` is a runtime procedure |
14:38:15 | FromDiscord | <jtv> @luteva https://play.nim-lang.org/#ix=4jXl |
14:42:11 | FromDiscord | <luteva> In reply to @jtv "<@954521401073754212> https://play.nim-lang.org/#ix": thx, but i need the other way around: I have the type given as a string. and i want to get the type. |
14:45:18 | FromDiscord | <jtv> At compile time? Type isn't available at runtime |
14:46:27 | FromDiscord | <luteva> In reply to @jtv "At compile time? ": yes at compiletime. that was my wish π |
14:47:19 | FromDiscord | <jtv> You can do it from a macro, just by creating a Ident node w/ that string |
14:47:26 | FromDiscord | <jtv> There's probably a better way |
14:47:34 | * | rockcavera joined #nim |
14:49:08 | NimEventer | New post on r/nim by llhd: Windows defender recognizes nim 1.6.10 x64 as a Virus, see https://reddit.com/r/nim/comments/zz2aic/windows_defender_recognizes_nim_1610_x64_as_a/ |
14:52:37 | FromDiscord | <jtv> @luteva https://play.nim-lang.org/#ix=4jXs |
14:54:15 | FromDiscord | <jtv> Probably better to type those: https://play.nim-lang.org/#ix=4jXt |
14:55:09 | NimEventer | New post on r/nim by lf_araujo: Did someone recreate Nim with Zig? /s, see https://reddit.com/r/nim/comments/zz2eiq/did_someone_recreate_nim_with_zig_s/ |
14:57:07 | FromDiscord | <jtv> If you might want to have more general type declarations, you have to create the tree of nodes, which is also easy: https://play.nim-lang.org/#ix=4jXv |
15:02:56 | * | arkurious joined #nim |
15:03:12 | FromDiscord | <jtv> LMK if that meets your needs, @luteva. That last one should do it under any circumstance I'd think, but if not, I'm happy to help. |
15:14:49 | * | azimut joined #nim |
15:15:47 | * | azimut_ quit (Ping timeout: 255 seconds) |
15:24:22 | FromDiscord | <cow> In reply to @NimEventer "New post on r/nim": except what the poster of this reddit post is missing that cyber is an interpreted language |
15:24:30 | FromDiscord | <cow> and apparently it beats JITs in performance? |
15:25:56 | FromDiscord | <jtv> @luteva Occurs to me that you might have your type sitting in some compile-time variable, so one last go at it for you: https://play.nim-lang.org/#ix=4jXG |
15:30:51 | NimEventer | New thread by lf_araujo: Did someone recreated Nim with Zig? \s, see https://forum.nim-lang.org/t/9782 |
15:37:21 | NimEventer | New post on r/nim by Familiar_Ad_8919: how would you convert a seq[string] to a cstringarray?, see https://reddit.com/r/nim/comments/zz3ddv/how_would_you_convert_a_seqstring_to_a/ |
15:38:38 | * | arkurious quit (Ping timeout: 255 seconds) |
15:39:08 | * | xet7 quit (Ping timeout: 260 seconds) |
15:39:15 | FromDiscord | <cow> In reply to @NimEventer "New thread by lf_araujo:": it smells like advertising now lmao |
15:40:05 | FromDiscord | <cow> although the reddit user has a non suspicious history so i take it back |
15:47:15 | FromDiscord | <Smarc> coulf anyone give me some buzzwords for day5 part1? (AoC) |
15:51:18 | * | xet7 joined #nim |
15:52:09 | * | arkurious joined #nim |
16:08:17 | * | derpydoo joined #nim |
16:10:00 | PMunch | Buzzwords? |
16:10:17 | FromDiscord | <cow> what library is `pixels` in the new nim book? (https://nim-lang.org/assets/img/nim_book_excerpt.pdf) |
16:11:05 | FromDiscord | <catnowblue> sent a code paste, see https://paste.rs/Isz |
16:13:03 | PMunch | @cow, I think it's just an imaginary library |
16:13:23 | FromDiscord | <cow> oh okay, thanks |
16:13:37 | PMunch | @catnowblue, not really |
16:14:44 | FromDiscord | <cow> it wouldn't be that hard to define it yourself |
16:15:53 | PMunch | Would look a bit like this: https://play.nim-lang.org/#ix=4jXX |
16:16:27 | FromDiscord | <cow> you beat me to it π¦ |
16:17:33 | PMunch | Fastest keyboard in the west |
16:18:10 | PMunch | You can get some bonus points if you explain why my solution properly handles the scenario of 0 and 1 element sequences as well :) |
16:19:04 | FromDiscord | <cow> nim auto initializes result to the default value right |
16:20:47 | FromDiscord | <cow> it doesn't have the right behavior imo |
16:20:51 | PMunch | Correct :) |
16:20:54 | FromDiscord | <cow> it returns the same for @[] and @[""] |
16:21:06 | PMunch | Well, that's how Nim strings behave |
16:21:13 | PMunch | An empty string is the same as no string |
16:21:29 | PMunch | The string type will always hold something you can pass to string functions |
16:21:32 | FromDiscord | <cow> still, I would throw an exception if the sequence is empty for correctness |
16:22:01 | om3ga | why some dylibs os cannot find for ompiled binary, and some not? |
16:22:07 | PMunch | Eh, depends on whether you consider that to be exceptional or not |
16:22:21 | om3ga | s*some can |
16:23:21 | FromDiscord | <cow> sent a code paste, see https://play.nim-lang.org/#ix=4jXZ |
16:23:47 | om3ga | is there any chance to tell the os to find the lib from the location relative from binary? |
16:24:49 | om3ga | I will get angry and compile that stuff statically |
16:24:54 | om3ga | :) |
16:25:24 | FromDiscord | <cow> i am happy that stuff just works on linux |
16:25:36 | FromDiscord | <cow> on windows i was suffering from having to manage my DLLs |
16:25:44 | FromDiscord | <hotdog> In reply to @cow "what library is `pixels`": Itβs this one https://nimble.directory/pkg/pixels |
16:25:49 | * | derpydoo quit (Ping timeout: 252 seconds) |
16:25:50 | FromDiscord | <cow> thanks! |
16:25:53 | om3ga | I need to cross compile to windows and mac |
16:25:54 | FromDiscord | <hotdog> No prob |
16:26:03 | FromDiscord | <hotdog> You need sdl I think for it to work |
16:28:02 | om3ga | I can compile without no prob |
16:28:28 | om3ga | but dylib for each os, is too painfull |
16:30:07 | om3ga | in mac I also created app bundle, using manual, that was so unpleasant |
16:36:03 | FromDiscord | <hotdog> om3ga have you tried something like https://github.com/chrisheller/docker-nim-cross |
16:36:58 | Amun-Ra | /usr/lib/nim/system/sets.nim:21:25: runtime error: load of misaligned address 0x7ffc146a11e2 for type 'NU64', which requires 8 byte alignment |
16:37:08 | Amun-Ra | has anyone else tested nim with asan and ubsan? |
16:37:38 | om3ga | hotdog, no. I cross compiled for windows from linux. Works fine |
16:37:58 | om3ga | on mac I compiled natively |
16:38:36 | om3ga | Amun-ra, I use all the time that tools |
16:38:55 | om3ga | what you mean test the nim |
16:39:28 | PMunch | Hmm, asynctools seems to be broken on Windows devel: https://github.com/PMunch/nimlsp/actions/runs/3807847256/jobs/6477921305#step:7:438 |
16:39:30 | Amun-Ra | hmm, that error is pretty hard to debug as it's the only line *san prints |
16:41:12 | om3ga | what it says |
16:41:20 | Amun-Ra | just that line |
16:41:44 | om3ga | aah, I see |
16:43:00 | Amun-Ra | hmm, it's somewhere in function I use getopt in |
16:43:25 | om3ga | -fsanitize=alignment |
16:44:02 | Amun-Ra | found the culprit |
16:44:28 | Amun-Ra | "prog -v -v arg" works fine, "prog -vv arg" triggers asan |
16:44:29 | om3ga | Amun-Ra: compile with -O0 -fsanitize=alignment -g3 and --lineDir:on --debuginfo |
16:44:57 | om3ga | it should result with more info |
16:46:02 | Amun-Ra | no, just the line |
16:46:33 | Amun-Ra | it's something inside getops, I'll make a shorter example and file bug report eventually |
16:46:40 | om3ga | yeah, not for this case, but for other stuff that options will add more text |
16:46:41 | Amun-Ra | getopt* |
16:47:04 | om3ga | looks like there is misallinged pointer somewhere |
16:47:18 | Amun-Ra | mhm |
16:47:41 | PMunch | Finally have a debug/testing utility for NimLSP https://github.com/PMunch/nimlsp/issues/31 |
16:49:04 | * | PMunch quit (Quit: leaving) |
16:53:19 | * | derpydoo joined #nim |
16:59:45 | Amun-Ra | om3ga: submitted: https://github.com/nim-lang/Nim/issues/21206 |
17:31:16 | om3ga | Amun-Ra: it not does the same here |
17:31:45 | Amun-Ra | om3ga: I edited the post, I had local config.nims when I tested that |
17:33:02 | om3ga | yes. with UBSAN it catched |
17:33:12 | Amun-Ra | mac? |
17:35:38 | om3ga | Amun-Ra: yeah |
17:35:51 | om3ga | sparseopt.nim.c:541:23: |
17:36:07 | Amun-Ra | thanks |
17:36:12 | om3ga | np |
17:38:24 | om3ga | Amun-Ra: If cmdline == "", the real command line as provided by the os module is retrieved instead if it is available. If the command line is not available, a ValueError will be raised. |
17:38:35 | om3ga | maybe this is the case? |
17:39:09 | om3ga | there is no err, but should it not have input parameters? |
17:42:33 | om3ga | seems the bug is somewhere there, where it tries to parse argv[] |
17:56:28 | Amun-Ra | hmm |
17:57:04 | Amun-Ra | tbh I plan to write my own getopt for nim one doesn't support ususal -o value format |
18:17:40 | FromDiscord | <Piqueiras> so I started a couple days ago with nim, does anyone know maybe some way in which this could be rewritten better? https://media.discordapp.net/attachments/371759389889003532/1058448799137284226/image.png |
18:18:38 | FromDiscord | <Piqueiras> i havent looked at barely any example code |
18:22:52 | FromDiscord | <Elegantbeef> Could remove `return` inside `collatz` |
18:24:54 | FromDiscord | <Piqueiras> cool |
18:25:22 | FromDiscord | <Piqueiras> are the loop and seq of seqs alright? |
18:25:28 | FromDiscord | <Piqueiras> its what looked a bit weird to me |
18:25:58 | FromDiscord | <Elegantbeef> Seems fine |
18:26:02 | FromDiscord | <Elegantbeef> Conventionally there are some issues, but that's up to you |
18:26:37 | FromDiscord | <Piqueiras> yea thats what i kinda meant, how would it be usually done |
18:26:41 | FromDiscord | <Elegantbeef> like it's conventionally `n != 0` and `res =` and `var n: int` |
18:27:11 | FromDiscord | <Elegantbeef> also `register[^1]`.add res\` |
18:27:28 | FromDiscord | <Elegantbeef> Whoops |
18:27:35 | FromDiscord | <Elegantbeef> `register[^1].add res` |
18:28:14 | FromDiscord | <Elegantbeef> actually is `i -1` == `^1` |
18:28:15 | FromDiscord | <Elegantbeef> Hmmm |
18:28:28 | FromDiscord | <Piqueiras> but in the beginning isnt register just @[] so register[^1] does not exist? |
18:28:39 | FromDiscord | <Elegantbeef> You add the element |
18:28:50 | FromDiscord | <Elegantbeef> You add before you index |
18:29:24 | FromDiscord | <Piqueiras> register is a seq which can hold seqs but its empty at the moment, so I shold add a new seq to it, right? |
18:29:38 | FromDiscord | <Elegantbeef> Which you do before you index, yes |
18:30:10 | FromDiscord | <Elegantbeef> When you add a new element you do `i - 1` which is the same as the last value which `^1` gives you |
18:30:37 | FromDiscord | <Piqueiras> yeah guess thats true |
18:30:39 | FromDiscord | <Piqueiras> nice one |
18:31:29 | FromDiscord | <Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4jYt |
18:32:43 | FromDiscord | <Piqueiras> yeah i had my mind on another fortran code I was doing before for sth else lmao |
18:35:40 | FromDiscord | <Piqueiras> also I should kinda work on my prints, which was a cool way lol https://media.discordapp.net/attachments/371759389889003532/1058453329941901433/image.png |
18:35:45 | FromDiscord | <Piqueiras> cuz it looks kinda ugly |
18:40:59 | Amun-Ra | Piqueiras: if register is a list or single values you do: for i, num in pairs register: β¦ |
18:41:45 | FromDiscord | <Piqueiras> Do I have to specify pairs? |
18:42:02 | Amun-Ra | no, pairs is an iterator |
18:42:25 | Amun-Ra | it returns tuple of (index, iterable[index]) |
18:42:49 | * | pro left #nim (#nim) |
18:42:53 | Amun-Ra | and mitems if you need to modify such item |
18:43:17 | FromDiscord | <Piqueiras> Hmm |
18:43:28 | FromDiscord | <Piqueiras> In reply to @Piqueiras "also I should kinda": But this does work tho? |
18:43:42 | FromDiscord | <Piqueiras> I meant, how to make a "prettier" echo |
18:43:52 | Amun-Ra | #define prettier |
18:44:05 | Amun-Ra | a, I think I know |
18:44:12 | Amun-Ra | check std/stformat |
18:44:28 | FromDiscord | <Piqueiras> sent a code paste, see https://play.nim-lang.org/#ix=4jYw |
18:44:32 | Amun-Ra | it allows you to write echo fmt"{i+1} {num.len}" |
18:44:38 | Amun-Ra | or &"β¦" |
18:44:54 | FromDiscord | <Piqueiras> Yea I need to get into that |
18:45:16 | FromDiscord | <Piqueiras> Just asking if echo had some weird sugar for those cases lol |
18:46:54 | Amun-Ra | Piqueiras: https://play.nim-lang.org/#ix=4jYy |
18:46:57 | Amun-Ra | sth like that? |
18:47:29 | FromDiscord | <Piqueiras> Seems cool enough, ty |
18:47:35 | Amun-Ra | no worries |
18:48:04 | Amun-Ra | fmt and & differs as seen in example |
18:48:54 | * | azimut quit (Remote host closed the connection) |
18:49:33 | * | azimut joined #nim |
18:51:00 | FromDiscord | <scruz> still don't understand why nim didn't go with `f" "` instead |
18:51:17 | FromDiscord | <scruz> like `&` is so random for strformat |
18:51:35 | FromDiscord | <Elegantbeef> Nim uses `&` for collection concatenation |
18:51:39 | * | Amun-Ra remembers \c and \L instead of \r and \n |
18:51:48 | FromDiscord | <scruz> hmn |
18:51:53 | FromDiscord | <scruz> (edit) "hmn" => "hmm" |
18:52:14 | FromDiscord | <Elegantbeef> It uses `fmt`, but due to how Nim works you need something that doesnt escape characters |
18:52:35 | FromDiscord | <Elegantbeef> cause `fmt"\t\t\t"` will print `\t\t\t` |
18:53:09 | Amun-Ra | Elegantbeef: I was wondering what was the rationale for fmt and & to exist |
19:01:37 | FromDiscord | <Solitude> In reply to @scruz "still don't understand why": why `f`? if anything it should be `i`. |
19:02:10 | FromDiscord | <scruz> python |
19:02:21 | FromDiscord | <Solitude> who? |
19:02:54 | FromDiscord | <scruz> https://media.discordapp.net/attachments/371759389889003532/1058460184638402580/unknown.jpeg |
19:02:55 | FromDiscord | <Elegantbeef> And not the actual unescaped characters |
19:02:56 | FromDiscord | <Elegantbeef> `fmt "\t\t\t"` prints the tabulator character of course |
19:02:56 | FromDiscord | <Elegantbeef> but that's why `&` mostly exists |
19:02:57 | FromDiscord | <Elegantbeef> Whether `&` should be `fmt` is a discussion |
19:02:58 | FromDiscord | <Elegantbeef> But luckily it's all in userspace so any variation can exist |
19:03:24 | FromDiscord | <scruz> In reply to @scruz "": https://media.discordapp.net/attachments/371759389889003532/1058460313760043079/unknown.jpeg |
19:03:39 | FromDiscord | <Solitude> crazy stuff, man, keep me updated |
19:04:01 | FromDiscord | <scruz> I don't know if you're exaggerating or not |
19:05:02 | FromDiscord | <Solitude> sorry, if i stop pretending i will get banned |
19:07:55 | FromDiscord | <Elegantbeef> Lol |
19:22:37 | * | jmdaemon joined #nim |
19:41:26 | * | wallabra joined #nim |
20:08:08 | * | neceve joined #nim |
20:21:49 | * | jmdaemon quit (Quit: ZNC 1.8.2 - https://znc.in) |
20:23:30 | * | jmdaemon joined #nim |
20:24:08 | * | derpydoo quit (Quit: derpydoo) |
20:40:14 | FromDiscord | <_ π> sent a code paste, see https://play.nim-lang.org/#ix=4jYY |
20:41:01 | FromDiscord | <yar> how to put arbitrary data on the stack then retrieval at the later date using a pair key value of a string type? |
20:42:14 | FromDiscord | <_ π> sent a code paste, see https://play.nim-lang.org/#ix=4jZ0 |
20:42:55 | FromDiscord | <_ π> oh u mean variables |
20:42:57 | FromDiscord | <yar> sent a code paste, see https://play.nim-lang.org/#ix=4jZ1 |
20:43:07 | FromDiscord | <yar> no arbitrary data on the stack then retrieval at the later date using a pair key value |
20:43:21 | FromDiscord | <huantian> what in the world are you talking about lmao |
20:43:37 | FromDiscord | <_ π> sent a code paste, see https://play.nim-lang.org/#ix=4jZ2 |
20:43:42 | FromDiscord | <yar> sent a code paste, see https://play.nim-lang.org/#ix=4jZ3 |
20:48:44 | FromDiscord | <yar> sent a code paste, see https://play.nim-lang.org/#ix=4jZ6 |
20:50:59 | FromDiscord | <huantian> how do you store data that only has its size known at runtime? |
20:51:05 | FromDiscord | <huantian> (edit) "runtime?" => "runtime on the stack?" |
20:51:19 | FromDiscord | <_ π> @huantian sorry to @ you, but could i get help w/ my visitor thing? |
20:51:24 | FromDiscord | <_ π> In reply to @_ π "how do i implement": ^^ |
20:52:29 | FromDiscord | <huantian> sorry I have no idea what a vistor pattern is lol |
20:52:52 | FromDiscord | <yar> In reply to @huantian "how do you store": good point |
20:52:55 | FromDiscord | <yar> i'll use the heap |
20:53:03 | FromDiscord | <yar> (edit) removed "the" |
20:53:03 | FromDiscord | <_ π> https://refactoring.guru/design-patterns/visitor |
21:00:03 | * | neceve quit (Quit: ZNC - https://znc.in) |
21:02:41 | * | neceve joined #nim |
21:03:02 | * | neceve quit (Remote host closed the connection) |
21:04:39 | * | deadmarshal_ joined #nim |
21:04:51 | FromDiscord | <huantian> https://play.nim-lang.org/#ix=4jZd |
21:04:54 | FromDiscord | <huantian> here's a generic example |
21:04:58 | FromDiscord | <huantian> so much dynamic dispatch lmao |
21:05:44 | * | neceve joined #nim |
21:06:02 | * | neceve quit (Remote host closed the connection) |
21:06:33 | * | deadmarshal_ quit (Remote host closed the connection) |
21:06:34 | FromDiscord | <Boston> If I have a for loop iterating over a seq of strings can get the current index I'm at, the "ordinal" of the current string? |
21:06:39 | FromDiscord | <huantian> Do note Nim isnβt really built focusing on this kinda stuff, you might find more success using other patterns |
21:06:56 | FromDiscord | <huantian> In reply to @Boston "If I have a": Use std/enumerate |
21:07:41 | FromDiscord | <huantian> Or the pairs iterator with `for str, i in someSeq:` |
21:09:01 | FromDiscord | <huantian> Or is it `i, str` I canβt remember the rider |
21:09:06 | FromDiscord | <huantian> (edit) "rider" => "order" |
21:10:44 | * | wallabra quit (Ping timeout: 255 seconds) |
21:13:58 | FromDiscord | <Boston> Thanks |
21:17:53 | * | wallabra joined #nim |
21:25:07 | FromDiscord | <_ π> alright, thank you @huantian |
21:32:39 | * | neceve joined #nim |
21:33:02 | * | neceve quit (Remote host closed the connection) |
21:39:38 | * | neceve joined #nim |
21:40:01 | * | neceve quit (Remote host closed the connection) |
21:42:34 | * | deadmarshal_ joined #nim |
21:44:43 | * | wallabra_ joined #nim |
21:45:39 | * | neceve joined #nim |
21:45:55 | * | wallabra quit (Ping timeout: 260 seconds) |
21:45:56 | * | wallabra_ is now known as wallabra |
21:46:01 | * | neceve quit (Remote host closed the connection) |
21:58:33 | FromDiscord | <alex.boisvert> I'm using VSCode to build a simple HTML + javascript page using Karax .... problem I'm having is that the Nim extension (nimsaem) doesn't lint the code properly. It seems to assume the standard C backend insteand of the js backend, so I'm getting tons of error, e.g. when importing the std/dom package, it reports "This module only works on the JavaScript platform". Is there a trick to tell the extension that I want to use the js b |
21:59:30 | FromDiscord | <alex.boisvert> I do have `"nim.buildCommand": "js"` in my `settings.json` but that's only used for actually building files (versus linting that happens on-the-fly) |
22:00:34 | FromDiscord | <alex.boisvert> I've tried forcing `-define:js` in nim.cfg but that doesn't work either (for obvious reasons but I figured it might get me farther) |
22:01:39 | * | neceve joined #nim |
22:05:10 | FromDiscord | <Solitude> i think `--backend:js` should do it |
22:06:20 | FromDiscord | <Smarc> how do i read a file starting from a specific line? |
22:07:47 | FromDiscord | <jtv> The easiest way is to read the whole thing and find the nth line. Otherwise, you have to scan it for newlines and stop after you've found n - 1 newlines |
22:08:43 | FromDiscord | <alex.boisvert> @Solitude Unfortunately, that doesn't seem to work. π (Unless I'm doing it wrong) |
22:10:50 | FromDiscord | <alex.boisvert> I put ``-backend:js` in my nim.cfg and also tried in $file.nim.cfg |
22:10:56 | FromDiscord | <alex.boisvert> (edit) "``-backend:js`" => "`-backend:js`" |
22:11:04 | FromDiscord | <alex.boisvert> (edit) "`-backend:js`" => "`--backend:js`" |
22:12:01 | FromDiscord | <jtv> I think the place that kind of stuff actually works is in config.nims |
22:12:21 | FromDiscord | <Solitude> it doesnt matter |
22:14:03 | FromDiscord | <alex.boisvert> Oh, actually, it does work! |
22:14:13 | FromDiscord | <Solitude> In reply to @alex.boisvert "Oh, actually, it does": you had to restart nimsuggest? |
22:14:45 | FromDiscord | <alex.boisvert> In reply to @Solitude "you had to restart": Yes, I guess. I restarted VSCode and it started working. |
22:15:02 | FromDiscord | <alex.boisvert> Thanks much! |
22:18:56 | FromDiscord | <Piqueiras> which would be a neat way to remove all these quotes from a csv? https://media.discordapp.net/attachments/371759389889003532/1058509522429280406/image.png |
22:19:17 | FromDiscord | <cow> removing all quotes? |
22:20:21 | FromDiscord | <cow> https://nim-lang.org/docs/strutils.html#replace%2Cstring%2Cstring%2Cstring |
22:22:22 | * | Jjp137 quit (Quit: Leaving) |
22:22:49 | FromDiscord | <cow> if the csv isn't too long, something like β΅`"/path/to/file.csv".readFile().replace("` |
22:23:09 | FromDiscord | <cow> (edit) "β΅`"/path/to/file.csv".readFile().replace("`" => "β΅`"/path/to/file.csv".readFile().replace("\"", "").writeFile("/path/to/newFile.csv")`" |
22:23:15 | FromDiscord | <Piqueiras> oh yeah idk why I tried sth weird and didnt work |
22:23:22 | FromDiscord | <Piqueiras> it was replace yea |
22:23:32 | FromDiscord | <cow> (edit) "β΅`"/path/to/file.csv".readFile().replace("\"", "").writeFile("/path/to/newFile.csv")`" => "β΅`writeFile("/path/to/newFile.csv", "/path/to/file.csv".readFile().replace("\"", ""))`" |
22:23:43 | FromDiscord | <cow> how did you try it |
22:23:47 | FromDiscord | <cow> can you send the snippet |
22:23:55 | FromDiscord | <cow> did you import strutils |
22:24:14 | FromDiscord | <Piqueiras> maybe cause I was trying some weird thing with map() |
22:24:17 | FromDiscord | <Piqueiras> but now it works |
22:25:51 | FromDiscord | <Piqueiras> sent a code paste, see https://paste.rs/ahh |
22:26:23 | FromDiscord | <Solitude> whats the point of splitting lines there? |
22:26:32 | FromDiscord | <cow> you can replace before splitting lines |
22:26:49 | FromDiscord | <cow> and no, I don't think that will work with map like that |
22:27:03 | FromDiscord | <cow> I would use `mapIt` for this |
22:27:11 | FromDiscord | <cow> (edit) "this" => "this, if you couldn't replace before splitting" |
22:27:32 | FromDiscord | <Piqueiras> hm, mapIt? ill look onto that |
22:27:36 | FromDiscord | <cow> `.mapIt(replace(it, "\"", ""))` |
22:27:45 | FromDiscord | <cow> map needs a function as an argument |
22:27:56 | FromDiscord | <cow> mapIt is a macro |
22:28:03 | FromDiscord | <cow> (edit) "mapIt is a macro ... " added "that lets you easily construct this function" |
22:30:55 | FromDiscord | <jos> are there any interfaces in nim that are dynamically dispatched |
22:31:06 | FromDiscord | <jos> i see concepts but that looks like static dispatch to me |
22:31:25 | FromDiscord | <jtv> Yes |
22:31:45 | FromDiscord | <jtv> You can declare a method instead of a proc |
22:32:18 | FromDiscord | <jtv> And set an inheritance hierarchy by declaring the type: type subtype = ref object of basetype |
22:32:30 | FromDiscord | <cow> that's not an interface |
22:32:34 | FromDiscord | <jtv> There's also RootObj and RootRef |
22:32:52 | FromDiscord | <jtv> Oh, I see what you're asking |
22:34:41 | FromDiscord | <jtv> Concepts are just statically checking that the objects will have the proper interface. They don't have to be part of an inheritance hierarchy. I haven't tried it, but I am pretty sure if the procs you require in a concept are actually methods, it should all just work and dynamically dispatch |
22:35:04 | FromDiscord | <jtv> But I don't think you can require a method; I haven't seen the syntax for it if so |
22:35:17 | FromDiscord | <jos> mm lemee try |
22:35:30 | FromDiscord | <cow> I thought concepts worked more like generics |
22:35:54 | FromDiscord | <jos> i mostly interested in holding references of a concept that point to different implementations |
22:36:06 | FromDiscord | <jtv> Well, concepts don't exist at runtime |
22:36:31 | FromDiscord | <jtv> Like cow said, they are used to typecheck and then create instances of code specific to types that match |
22:37:40 | FromDiscord | <jtv> But since you can or types together, you can still do what you want to do |
22:38:00 | * | Jjp137 joined #nim |
22:38:36 | FromDiscord | <jos> https://media.discordapp.net/attachments/371759389889003532/1058514467119448144/image.png |
22:38:39 | FromDiscord | <jtv> Esp if you just cast up from a rootref |
22:38:50 | FromDiscord | <jos> the last line is invalid |
22:39:10 | FromDiscord | <jos> i think that's the part that i can't really do |
22:39:15 | FromDiscord | <jos> like it won't create a vtable for my concept |
22:39:25 | FromDiscord | <Elegantbeef> Jtv you're correct there is no method of using concepts at runtime with Nim you need to use something like iface |
22:39:35 | FromDiscord | <Elegantbeef> Of course it's invalid they both derive from `RootObj` and dont share parent |
22:39:50 | FromDiscord | <Elegantbeef> You need to use macros for runtime dispatch of concepts |
22:39:56 | FromDiscord | <Elegantbeef> https://github.com/beef331/traitor exists for instance, no clue if it is |
22:40:00 | FromDiscord | <Elegantbeef> usable |
22:40:25 | FromDiscord | <jos> interesting |
22:40:40 | FromDiscord | <cow> you could also dispatch yourself π€‘ |
22:40:53 | FromDiscord | <cow> a type enum and a case statement at every proc |
22:41:51 | FromDiscord | <cow> and casts |
22:41:56 | FromDiscord | <jtv> Beef, that's a really cool idea |
22:42:29 | FromDiscord | <cow> (edit) "and casts ... " added "(depending on the details)" |
22:42:59 | FromDiscord | <cow> there's the nim equivalent tagged enums, which helps a lot when making seqs of different types |
22:43:13 | FromDiscord | <cow> (edit) "enums," => "unions," |
22:44:35 | FromDiscord | <cow> sent a code paste, see https://play.nim-lang.org/#ix=4jZQ |
22:44:52 | FromDiscord | <jos> i really do need the dynamic dispatch |
22:45:04 | FromDiscord | <jos> because i want users to be able to extend it without having source access |
22:45:10 | FromDiscord | <Elegantbeef> Look at iface |
22:46:00 | FromDiscord | <jos> i mean its cool but having 2 year old libraries as a foundation of your project is always a weird feeling |
22:46:27 | FromDiscord | <jos> it is kind of small tohugh |
22:46:28 | FromDiscord | <jos> (edit) "tohugh" => "though" |
22:46:35 | FromDiscord | <jos> only 250 lines, i could fix that |
22:46:39 | FromDiscord | <jos> if anything did go wrong |
22:46:56 | FromDiscord | <Elegantbeef> Otherwise use oop |
22:46:59 | FromDiscord | <cow> In reply to @jos "because i want users": also, are you gonna statically compile their extensions into the binary? |
22:47:57 | FromDiscord | <cow> i would be also interested in learning how to load extensions from a folder |
22:48:21 | FromDiscord | <cow> (edit) "i would be also interested in learning how to load extensions from a folder ... " added "while your main program has been compiled without knowing what extensions there are" |
22:51:40 | FromDiscord | <jos> i planned on loading them during runtime but haven't crossed that bridge yet |
22:54:19 | FromDiscord | <Schelz> Hi! Is there any way to list all the displays connected to the computer ? |
22:56:37 | FromDiscord | <sOkam!> What's the best way to learn good practices for using the different builtin error types for exceptions? |
22:56:44 | FromDiscord | <cow> In reply to @Schelz "Hi! Is there any": that sounds something very platform specific |
22:56:55 | FromDiscord | <Elegantbeef> Never use builtin error types for exceptions |
22:56:59 | FromDiscord | <Elegantbeef> That's the good practice |
22:57:11 | FromDiscord | <sOkam!> not even inheriting from them? |
22:57:20 | FromDiscord | <Schelz> In reply to @cow "that sounds something very": On windows mostly |
22:57:34 | FromDiscord | <Elegantbeef> You can inherit from them i guess but i dont see much benefit myself |
22:58:29 | FromDiscord | <sOkam!> I've never used them, so I thought it would be good to start from the base errorsβ΅But if not, what's a better approach? |
23:00:01 | FromDiscord | <cow> In reply to @Schelz "On windows mostly": If there's no nim library to do it, you can look into how to do it through C |
23:00:07 | FromDiscord | <jtv> @jos That library is pretty widely used, and doesn't need to do much, so I wouldn't stress about that anyway |
23:00:29 | FromDiscord | <cow> on linux I think you could use `xrandr` commands to do it |
23:05:18 | FromDiscord | <cow> maybe there's a command line program to do it on windows, which you could easily wrap |
23:05:19 | FromDiscord | <jtv> Generally people will downplay exceptions, especially since you can return Option types which are easy to use to indicate error (or, I guess, tuples if you don't want to force checking) |
23:05:48 | FromDiscord | <cow> i just do both π |
23:06:08 | FromDiscord | <cow> my functions throw exceptions AND have a tuple indicating if there was an error |
23:06:15 | FromDiscord | <cow> half the errors will do one, other half the other half |
23:06:16 | FromDiscord | <jtv> But generally you can just inherit from ValueError, OSError or IOError, as appropriate |
23:06:21 | FromDiscord | <cow> (edit) removed "half" |
23:07:10 | FromDiscord | <cow> i can never decide if crashing the program if something bad happened, or chaining together a bunch of checks if something bad happened is better |
23:07:31 | FromDiscord | <jtv> I generally save throwing my own exceptions for when I really do need a longjmp()... for instance, bailing from some deeply nested parsing or compilation. |
23:07:56 | FromDiscord | <cow> I usually tend to use exceptions if I don't intend for them to be handled |
23:08:09 | FromDiscord | <cow> as in, it's so bad I want the program to end |
23:08:50 | FromDiscord | <jtv> Yeah, though that gives me nightmares of Java programs |
23:08:59 | FromDiscord | <huantian> there's probablysomething in https://github.com/khchen/winim for the display thing |
23:09:42 | FromDiscord | <jtv> Esp in a multi-threaded program you're going to end up having people write a while true: loop and never deal w/ issues π |
23:10:44 | FromDiscord | <cow> but if something goes wrong internally, there is a bug, and the best way to get a bug fixed is to crash the program if it ever happens |
23:11:01 | FromDiscord | <cow> no, i never got anything into production |
23:11:06 | FromDiscord | <jtv> Sure yes. |
23:11:31 | FromDiscord | <jtv> Depends on the environment, but generally expect when you have threads, only the current thread will exit |
23:11:42 | FromDiscord | <cow> good to know |
23:12:00 | FromDiscord | <! Nilts> sent a code paste, see https://play.nim-lang.org/#ix=4jZY |
23:12:26 | FromDiscord | <jtv> IDK, I'd assume x1,y1, x2,y2 for opposite corners of the rectangle?? |
23:12:36 | FromDiscord | <Schelz> In reply to @cow "If there's no nim": I got the audio tho working so I can change it through C++, but for video thats a bit tricky so thats way I asked if in nim could be done. π |
23:12:55 | FromDiscord | <! Nilts> In reply to @jtv "IDK, I'd assume x1,y1,": oh, i thought it was shape not location based |
23:13:22 | FromDiscord | <cow> In reply to @Schelz "I got the audio": maybe winim can help?, but you can pretty easily call C(++) functions from nim |
23:13:22 | FromDiscord | <! Nilts> guess i was wrong |
23:13:46 | FromDiscord | <jtv> Well, I assume it's specifying a rectangle, and that's usually done by giving the two opposite corners |
23:14:05 | FromDiscord | <cow> or x, y, width, height |
23:14:16 | FromDiscord | <jtv> Yeah, could be. |
23:15:23 | FromDiscord | <! Nilts> In reply to @cow "or x, y, width,": but which is it, i can't even find the file that defines newRect |
23:16:37 | FromDiscord | <cow> type Rect = tuple[origin: Point, size: Size] |
23:16:47 | FromDiscord | <cow> proc newRect(x, y, w, h: Coord): Rect = |
23:16:50 | FromDiscord | <cow> https://github.com/yglukhov/nimx/blob/master/nimx/types.nim |
23:17:04 | FromDiscord | <cow> it's x, y and width, height |
23:18:03 | FromDiscord | <! Nilts> thanks! |
23:26:29 | FromDiscord | <! Nilts> Arrgh, nimx does not even work on the latest version of nim. I can't even run the tests |
23:28:24 | FromDiscord | <cow> the readme says they use the latest devel |
23:28:43 | FromDiscord | <cow> (edit) "the readme says they use the latest devel ... " added "version, not latest stable" |
23:29:04 | FromDiscord | <! Nilts> In reply to @cow "the readme says they": which is? |
23:29:47 | FromDiscord | <! Nilts> sent a code paste, see https://paste.rs/BFZ |
23:29:54 | FromDiscord | <cow> yeah that's the latest stable release |
23:30:25 | FromDiscord | <cow> I'm not a nimx user (i don't do GUI stuff) but I think they mean unreleased new |
23:30:44 | FromDiscord | <! Nilts> I don't have enough storage on my machine for another release. |
23:31:23 | FromDiscord | <! Nilts> or the time to compile it |
23:31:48 | FromDiscord | <! Nilts> why does nim take up so much space? Anyone know which files i can delete? |
23:31:54 | FromDiscord | <cow> you can `choosenim devel` |
23:32:12 | FromDiscord | <cow> how much space does it take up for you? |
23:32:21 | FromDiscord | <cow> (edit) "devel`" => "devel`, I don't think you need to compile it" |
23:32:27 | FromDiscord | <! Nilts> In reply to @cow "you can `choosenim devel`,": choosnim does not work on my machine (linux arm) |
23:34:46 | FromDiscord | <! Nilts> In reply to @cow "how much space does": 47M |
23:34:47 | FromDiscord | <cow> a nim install seems to be around 70 MB on my PC |
23:34:55 | FromDiscord | <! Nilts> (edit) "47M" => "47MB" |
23:40:15 | FromDiscord | <! Nilts> can i delete `nim/compiler`? |
23:42:39 | FromDiscord | <cow> i just did, and nim seems to work |
23:42:56 | FromDiscord | <cow> my intuition says that everything besides `bin/` is just source code not needed after you have compiled nim |
23:57:08 | FromDiscord | <Elegantbeef> You also need the `lib` folder |
23:57:12 | FromDiscord | <Elegantbeef> Cause nim ships the stdlib as source |