<postmodern>
why is Bytes a Slice of UInt8, but Char#ord returns Int32? I assume Int32 is used for UTF8 and UInt8 for 8bit ASCII?
<FromGitter>
<tenebrousedge> bytes is the literal bytes that make up the string. Strings don't have to be in any particular byte format
<postmodern>
like i want to return substrings from a String, but also have an index embedded into the object. So I thought I could use String#to_slice, but it appears I'd have to search through Bytes (UInt8), which seems to be lower level than a Slice(Int32) or Slice(Char)?
<postmodern>
could i do bytes.as_unsafe(Slice(Int32)) ?
<FromGitter>
<tenebrousedge> don't use `as_unsafe` unless you have no alternative
<FromGitter>
<tenebrousedge> what substrings do you need?
<FromGitter>
<tenebrousedge> and an index of what, each byte? or each character?
<postmodern>
i'm porting this ruby code that finds all non-overlapping strings, whos characters belong to a character set (alpha, alpha-num, etc)
<postmodern>
one of the options of this function is to not just return an Array of Strings, but an Array of (index, String)
<postmodern>
porting that too crystal is a bit tricky, because method overloading does not recognize different return types
<postmodern>
so i thought, what if i just returned Slices instead of Strings, then ran into Bytes vs. Int32s
<FromGitter>
<tenebrousedge> why not return `Array(Tuple(Index, String))` and let the call site discard the index if it wants?
<FromGitter>
<tenebrousedge> you can do `map(&.last)` to get just the strings
<postmodern>
could do that, but that changes the API a bit
<FromGitter>
<tenebrousedge> yes
<postmodern>
my other option was to come up with a different method name that returns the Tuple(Int32, String)
<FromGitter>
<tenebrousedge> also valid
<FromGitter>
<tenebrousedge> `each_char_with_index` is probably a good iterator
<FromGitter>
<Blacksmoke16> so we're back to that "how to figure out the width of a char problem"
<FromGitter>
<tenebrousedge> plz no 😢
<FromGitter>
<Blacksmoke16> `.size` doesn't cut it if i want to support Chinese and other full width chars
<FromGitter>
<Blacksmoke16> but think imma take the easy path and just not support this use case for now :P
<FromGitter>
<tenebrousedge> :plus1:
<postmodern>
let the shards implement it, then maybe pull in the top 0.1% of popular core-ext functions to stdlib
<postmodern>
crystal could totally add: alias Byte = UInnt8 | Int32
_ht has joined #crystal-lang
aquijoule_ has quit [Remote host closed the connection]
aquijoule_ has joined #crystal-lang
hendursaga has quit [Ping timeout: 240 seconds]
hendursaga has joined #crystal-lang
bougyman has quit [Ping timeout: 260 seconds]
bougyman has joined #crystal-lang
lanodan has quit [Ping timeout: 258 seconds]
sorcus has quit [Quit: WeeChat 3.1]
lanodan has joined #crystal-lang
sorcus has joined #crystal-lang
oddp has joined #crystal-lang
<FromGitter>
<emanzx> Hi guys.. been a while.. today I try to compile one simple apps, it works ok if i just crystal my_app.cr ⏎ but when I try crystal build my_app.cr it failed with this error ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60940909c651cb6a0016adb6]
<FromGitter>
<Blacksmoke16> how did you install crystal?
<FromGitter>
<Blacksmoke16> and where are you running this? Probably alpine image?
<FromGitter>
<emanzx> using FreeBSD pkg
<FromGitter>
<emanzx> on FreeBSD 13
<FromGitter>
<Blacksmoke16> pretty sure the problem is libgc doesnt have the patch, should work fine without `-Dpreview_mt`
<straight-shoota>
yeah, that's it
<straight-shoota>
multithreading requires a patched libgc and you're like lusing the system package which misses the patch
<FromGitter>
<naqvis> Just published Unicode Text Segmentation (https://github.com/naqvis/uni_text_seg) shard to determine the *grapheme clusters* boundaries of unicode text.
<FromGitter>
<riffraff169> if i have an array of hashes with a key of value : Int32, what would be the easiest way to find the first entry where X >= value?
<FromGitter>
<naqvis> looking into `data.cr` file. This is generated via script, don't know why the script didn't generate the Array of values? why code is doing that runtime?
<FromGitter>
<naqvis> any specific reasoning behind that?
<straight-shoota>
big array literals are bad on compiler performance
<FromGitter>
<naqvis> i mean, if i would have done this, i would have script generate the array like `arr = [0xBBAA, 0XFFAA......]` or something like
<FromGitter>
<naqvis> aahh
<FromGitter>
<naqvis> thanks straight-shoota
<FromGitter>
<naqvis> how big is considered as big?
<FromGitter>
<oprypin:matrix.org> you'll see that directly from compilation times
<FromGitter>
<oprypin:matrix.org> i think people dont have that answer off-hand, but the growth has to be either linear or exponential. might as well try adding more and more items in your code and seeing when it becomes unbearable
<FromGitter>
<kingsleyh> evening - the crystal 0.36.1 docker image is having problems now that bintray has gone
<straight-shoota>
should be fixed
<FromGitter>
<Blacksmoke16> do another pull, should be fixed now
<FromGitter>
<naqvis> updated code to replace array literal with dynamic population of values to avoid compilation time issue
<FromGitter>
<naqvis> TIL `alloca`should be avoided in LLVM
_ht has quit [Remote host closed the connection]
<FromGitter>
<mattrberry> Is there ever a reason to use `Proc(Void)` rather than `Proc(Nil)`? Completely out of the context of C bindings
<FromGitter>
<mattrberry> My understanding is no
<FromGitter>
<will> Does anyone know of any examples of someone packaging a crystal program as a homebrew cask? I've never made a homebrew thing before, so that's a whole thing, but then also curious about what to do with the dylibs that might not be there if someone doesn't have crystal itself installed. Do you just list like bdw-gc and libpcre as dependencies?
<FromGitter>
<watzon> I don't believe so @mattrberry. I use to have issues with `Proc(Nil)` if the proc actually ended up returning something and I just wanted to ignore it, but I don't think that happens anymore
<FromGitter>
<tenebrousedge> @mattrberry yeah unless you are using C stuff, `Void` isn't a thing
<FromGitter>
<mattrberry> Cool that was my understanding. I've had issues with in the past with `Proc(Void)` as well too. I just figured out where I got it lol https://crystal-lang.org/reference/syntax_and_semantics/literals/proc.html. I'm going to submit a PR to the reference to change that after work today
<FromGitter>
<mattrberry> Looks like the stdlib was updated at some point to account for that, but it's still in the reference which could be a bit confusing
Nekka has quit [Ping timeout: 246 seconds]
<FromGitter>
<mattrberry> This is kind of an odd question, but is there any way to overload which method of a class is called depending on which module it's calling from? I doubt it and it's probably not a good design choice anyway, but I'm just curious :p
<FromGitter>
<tenebrousedge> maybe with abuse of `included` ?
<FromGitter>
<tenebrousedge> I think the answer is probably, but I would also question why that was necessary
<FromGitter>
<mattrberry> Heh, yeah I guess there probably would be a way to do it then
<FromGitter>
<tenebrousedge> Probably the way I would approach that sort of polymorphism would be like, say you had a module `A`, and some sort of defined interface `B` shared by classes `Foo` and `Bar`, you could have the module call `do_stuff` that is implemented differently on the `Foo` and `Bar` types. The only thing that I can really think of to do otherwise would be if you really needed to do something dynamically based on the
<FromGitter>
... name of the class including your module, maybe defining a class method or something?
<FromGitter>
<tenebrousedge> idk. I could see a little more need for that kind of metaprogramming in a shard
<FromGitter>
<tenebrousedge> still probably worth avoiding if possible
<FromGitter>
<mattrberry> Yeah I really don't need this, I was more just curious if it would be possible
<FromGitter>
<mattrberry> Seems like a bad design pattern even if I did "need" it haah
<FromGitter>
<mattrberry> Is there a way to make `crystal spec` run other commands? Or would it be better to have a makefile where I can add a target to run `crystal spec` *and* something else?
<FromGitter>
<Blacksmoke16> Use make
<FromGitter>
<mattrberry> I guess I can have a spec in `spec/` that execs something lol
<FromGitter>
<Blacksmoke16> Shards isn't intended to be a build tool. E.e like npm or composer scripts
<FromGitter>
<Blacksmoke16> What are you wanting to execute?
<FromGitter>
<mattrberry> It's just a script that executes my emulator and dumps screenshots at various points as a form of integration test :p
<FromGitter>
<Blacksmoke16> Yea id just define make spec
<FromGitter>
<Blacksmoke16> Or ofc could make them separate then have another command that does both