ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Read error: No route to host]
oddp has quit [Quit: quit]
Nekka has quit [*.net *.split]
markmarkmark has quit [*.net *.split]
markmarkmark has joined #crystal-lang
Nekka has joined #crystal-lang
<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> <tenebrousedge> this table looks useful: https://github.com/janlelis/unicode-display_width
<postmodern> yeah `strings_in_with_index(str)`. although `strings_at(str)` sounds promising?
<postmodern> well if you had a Int32, you could do some checks for how many 0xff it contains to determine byte width
<FromGitter> <Blacksmoke16> yea think i just need to like `self.chars.sum ...` where sum checks the fullwidth chars and sums by proper width..
<FromGitter> <tenebrousedge> `substrings_with_index`
<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> <emanzx> oh..
<FromGitter> <emanzx> Im trying to use this shards https://github.com/makisu/faktory.cr
<FromGitter> <emanzx> it seem it need the -Dpreview_mt
<FromGitter> <emanzx> wow.. works now
<FromGitter> <emanzx> I think I just stay with single concurrency
<straight-shoota> For a job processor, that's really a better solution anyway. Just run multiple processes.
<straight-shoota> multithreading has an overhead
<FromGitter> <Blacksmoke16> https://github.com/mosquito-cr/mosquito is also pretty good
postmodern has quit [Quit: Leaving]
<FromGitter> <riffraff169> that looks cool
DTZUZU_ has quit [Ping timeout: 252 seconds]
<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> <riffraff169> maybe `.select() {} [0]` ?
<FromGitter> <Blacksmoke16> `.find` prob
<FromGitter> <riffraff169> ah yes, exactly, thanks
<FromGitter> <RespiteSage> @naqvis Did you just write that today?
<FromGitter> <naqvis> yeah @RespiteSage
<FromGitter> <RespiteSage> Nice work. It looks really simple to use, and it obviously fills a clear need.
<FromGitter> <RespiteSage> Also, impressive that you wrote it in such little time.
<FromGitter> <naqvis> Thanks. I just did a port from golang module https://github.com/rivo/uniseg
DTZUZU has joined #crystal-lang
<FromGitter> <Blacksmoke16> is that related to the string width problem i was the having the other day?
<FromGitter> <Blacksmoke16> would be cool if `Char` had like `.full_width?` and such
<FromGitter> <naqvis> yeah, its related to that problem
<FromGitter> <naqvis> and this is first step in writing another shard to calculate the unicode string width
<FromGitter> <naqvis> so stay tuned :P
<FromGitter> <Blacksmoke16> ❤️
<FromGitter> <naqvis> I'll work on missing piece of puzzle
<FromGitter> <Blacksmoke16> there's also a unicode module in the stdlib, could possibly include some of this in there and `Char` type
<FromGitter> <naqvis> yeah, for project use can do monkey patching
<FromGitter> <naqvis> like add `graphemes` method to `String` and invoke this shard
<FromGitter> <Blacksmoke16> `require "ext/string"`
<FromGitter> <naqvis> but I avoided adding the extension to shard, as there are many who don't like monkey-patches 😄
<FromGitter> <Blacksmoke16> yea, i kinda meant including some/all of the shards feature in the stdlib fwiw
<FromGitter> <naqvis> true, current stdlib still have whole lot of areas for improvement
<FromGitter> <Blacksmoke16> based on the forum thread it seems others are on board with that too :p
<FromGitter> <Blacksmoke16> https://github.com/crystal-lang/crystal/blob/master/src/unicode/data.cr might be able to leverage this in some way?
<FromGitter> <naqvis> yeah, seems good
<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> <kingsleyh> ok thanks will try
<FromGitter> <naqvis> i just did a simple test with 1602 tuple entries inside an array and didn't see any big difference ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60943302963923553ae96d65]
<FromGitter> <Blacksmoke16> try with `--release`
<FromGitter> <naqvis> sure
<FromGitter> <naqvis> i'm sold :P
<FromGitter> <naqvis> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=609434dad5e2793379f71e15]
<FromGitter> <Blacksmoke16> :)
<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
<FromGitter> <mattrberry> 👍