<FromGitter>
<asterite> Or, remember that time when you wanted an object to hold "any object that responds to X and Y" but didn't want to include a module in every type? There's a way to do it. It's probably not ideal, I'm not sure about its performance... but it works!
<FromGitter>
<wyhaines> @asterite Nice. In my limited scope implementation it seems to work more than well enough.
<FromGitter>
<wyhaines> Does anyone know if Crystal can be used to write shared libraries that one can link to & call from C?
<FromGitter>
<didactic-drunk> Not that I'm aware partially because of the GC.
<FromGitter>
<wyhaines> Ah yeah. What about straight up embedding? There are other GC'd languages that can be embedded. Once upon a time I embedded both PHP into Ruby, and Ruby into PHP, for example.
<FromGitter>
<wyhaines> @naqvis Oh, that's an interesting little bit of reading. Thanks.
<FromGitter>
<naqvis> ywc
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 272 seconds]
alexherbo2 has joined #crystal-lang
deavmi has quit [Quit: Eish! Load shedding.]
<raz>
Blacksmoke16: when you're done with your n fibers do n concurrent requests please submit it as a PR to the shards shard :p
postmodern has quit [Remote host closed the connection]
<f1reflyylmao>
Can I tell gdb to pretty print the contents of crystal arrays/objects in general? It doesn't really help when it shows me that my array var is, indeed, an array
f1reflyylmao has quit [Quit: bye fags]
f1refly has joined #crystal-lang
oddp has joined #crystal-lang
livcd has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 265 seconds]
rocx_ has joined #crystal-lang
rocx has quit [Read error: Connection reset by peer]
alexherbo2 has joined #crystal-lang
<FromGitter>
<guglielmocg_gitlab> So after reading documentation am I correct in assuming there's no Array.count method in Crystal? Or anything that returns length of an Enumerable or a String?
<yxhuvud>
guglielmocg_gitlab: To get the length of an array, use the `#size` method. There is also a `#count` method, but it is used to count the true values, or if passed a block, the amount of items the block returns a true value for.
<FromGitter>
<guglielmocg_gitlab> Thank you a lot. I don't know how I didn't spot the size method
<FromGitter>
<Blacksmoke16> π
<FromGitter>
<j8r> any reasons why `Set#delete` always returns self?
<FromGitter>
<j8r> That's not the same as `Hash#delete`, which return nil if the element is not found
<FromGitter>
<asterite> I guess we could `true` if the element was there, `false` if not. It's a small breaking change but I think it's worth it
<FromGitter>
<asterite> I think we should also make `Set#add` just return `true` if the element was added, `false` otherwise, and remove `Set#add?` (it feels a bit redundant)
deavmi has joined #crystal-lang
Human_G33k has quit [Ping timeout: 264 seconds]
Human_G33k has joined #crystal-lang
Human_G33k has quit [Remote host closed the connection]
Human_G33k has joined #crystal-lang
rocx_ is now known as rocx
<yxhuvud>
my guess is that is that Set#add and #delete follows ruby there. Possibly for chaining reasons but it probably doens't make sense for mutating methods.
<jhass>
actually it sometimes can be useful to pass an object to `add` or especially `delete` that's `eql?` to some object in the collection, but not the same object, yet you need the original after
<jhass>
so returning the deleted object gives access to the original
<jhass>
Java does the same
<jhass>
(object or null)
<FromGitter>
<j8r> yep, but no need for `Set`
<FromGitter>
<j8r> because the hash is supposed to be the same
<FromGitter>
<j8r> It is possible someone is doing wrong by having two different objects having the same hash...
Human_G33k has quit [Ping timeout: 256 seconds]
<FromGitter>
<j8r> returning `T?` instead of `Bool` looks more promising
Human_G33k has joined #crystal-lang
Human_G33k has quit [Max SendQ exceeded]
Human_G33k has joined #crystal-lang
gangstacat has quit [Quit: Δis!]
gangstacat has joined #crystal-lang
<FromGitter>
<jaitaiwan_gitlab> Hey folks, just quickly, how can I read a file that contains null bytes and get all the bytes? it looks like gets_to_end stops too early
<FromGitter>
<Blacksmoke16> `gets_to_end` returns a string
<FromGitter>
<jaitaiwan_gitlab> Mhmm and I've been doing .to_slice on it
<FromGitter>
<jaitaiwan_gitlab> yeah most if not all require you to know the size of the file or the only other one I can think of is peak? but I'm not sure that's what I'm going for...
<FromGitter>
<jaitaiwan_gitlab> @asterite It does, code issue was my fault because I was converting it back to a string later using a slice of the pointer rather than a slice of the string.
<FromGitter>
<asterite> π
<FromGitter>
<jaitaiwan_gitlab> I was building a simple git implementation: https://gitlab.com/devdemandco/devdemand.io/code-ano β β Plan is to create an extension for git that allows for line-by-line code annotations that are stored in your git repo and (by choice) synced automatically with pushes.
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
<FromGitter>
<asterite> Make sure to either `file.close` after you use a file, or use the block version of `File.open`
<FromGitter>
<jaitaiwan_twitter> Ahh of course. Thank you. I was using a block in a previous version and forgot to close. Thanks
<FromGitter>
<Blacksmoke16> to be clear the block `File.open` closes it for you.
<FromGitter>
<Blacksmoke16> only need to close it manually when you're not using `File.open`
<FromGitter>
<RespiteSage> Is there a way to make an empty tuple?
<FromGitter>
<Blacksmoke16> `Tuple.new`?
<FromGitter>
<RespiteSage> Yeah, I should've expected that. I'm trying to do this: https://carc.in/#/r/9e2d
<FromGitter>
<RespiteSage> I was hoping there might be a workaround.
<FromGitter>
<Blacksmoke16> check if its empty before calling .types
<FromGitter>
<RespiteSage> Yeah, I just came to that conclusion as well. Thanks, though. :)
<FromGitter>
<RespiteSage> Next time I'll just take 30 seconds to think about it before asking. :P
<FromGitter>
<RespiteSage> Okay, so this is more of a design question. I mentioned this in the chat a couple days ago, but I'm trying to extend a library for representing measured quantities in a type-safe way independent of unit (e.g. you don't have to worry whether you have a quantity in feet or meters; just use a Length and conversion methods). It already has the base units (Length, Mass, Frequency, etc.) and several
<FromGitter>
... manually-created derived units (Velocity, Density, etc.) implemented, and those work well. However, I'd like to be able to just multiply or divide any Unit class (like the aforementioned ones) and get a derived unit that keeps the "unit" information (e.g. `Mass#/(Length)` ends up with a `DerivedUnit` with a `Mass` numerator and `Length ... [https://gitter.im/crystal-lang/crystal?at=5f04df50a9378637e8b332cd]
<FromGitter>
<RespiteSage> Should I just give up on using generics and instead have a runtime tuple or something (and have the API primarily require instantiation of derived types using non-derived types, like `Mass#per(type : U) forall U`)?
<FromGitter>
<Blacksmoke16> :magic:
<FromGitter>
<RespiteSage> o.O
<FromGitter>
<Blacksmoke16> is there a reason to use tuples here versus like `Length.new 10, :meters` or whatever
<FromGitter>
<Blacksmoke16> or even `abstract class struct Length` and `Meters < Length` then reopen Number like:
<FromGitter>
<RespiteSage> I think I wasn't clear about what my problem was. What you're describing is already how the library works (and it's really nice, though unfortunately closed-source atm).
<FromGitter>
<Blacksmoke16> ah cool
<FromGitter>
<RespiteSage> The derived type part is what I'm working on.
<FromGitter>
<Blacksmoke16> is there no parent type to all these?
<FromGitter>
<Blacksmoke16> make them separate ivars
<FromGitter>
<RespiteSage> Yes, there's a hierarchy of abstract structs with `Unit` at the top (a hierarchy because of `DimensionlessUnit`, which has some special logic).
<FromGitter>
<RespiteSage> Yeah, the ivar approach was the other one I considered. I just really liked the idea of being able to say `struct Force < DerivedUnit({Mass, Length}, {Timespan, Timespan})`.
<FromGitter>
<RespiteSage> (As an aside, whether to use a `Timespan` class or just use `Time::Span` is an ongoing discussion.)
<FromGitter>
<Blacksmoke16> π
HumanGeek has joined #crystal-lang
Human_G33k has quit [Ping timeout: 265 seconds]
jetpack_joe has quit [Ping timeout: 246 seconds]
melthelesbian has quit [Ping timeout: 246 seconds]
Liothen has quit [Ping timeout: 260 seconds]
issyl0 has quit [Ping timeout: 256 seconds]
r0bby has quit [Ping timeout: 260 seconds]
kevinsjoberg has quit [Ping timeout: 246 seconds]
sz0 has quit [Ping timeout: 244 seconds]
alexherbo2 has quit [Ping timeout: 272 seconds]
cerulean has joined #crystal-lang
<cerulean>
is this chat still a thing?
<cerulean>
How do I know when TCPServer has disconnected?
<cerulean>
a socket has disconnected from TCPServer
<cerulean>
I want to remove it from the sockets array
<FromGitter>
<Blacksmoke16> i think there is a `#closed?` method on it
<FromGitter>
<Blacksmoke16> but i dont think that is what you actually want...
<cerulean>
I figured it out
<cerulean>
it returns from while message = client.gets when its closed but you have to close it manually