laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
alexherbo21 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 255 seconds]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
early has quit [Quit: Leaving]
early has joined #crystal-lang
teardown has joined #crystal-lang
early has quit [Quit: Leaving]
early has joined #crystal-lang
laaron has quit [Remote host closed the connection]
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 245 seconds]
Raimondii is now known as Raimondi
teardown has quit [Read error: Connection reset by peer]
teardown has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter>
<watzon> I can't remember who was trying to help me before, I think it was you @Blacksmoke16, but I think I found the error that was causing my seemingly simple method that works in Javascript to fail in Crystal
<FromGitter>
<watzon> #7782
<FromGitter>
<watzon> I'm finding a lot of weirdness here
<FromGitter>
<dscottboggs_gitlab> so... at some point it was decided to automatically assign values their types based on constant values. Integers still default to `Int32`. So, `0x10000000000` is a literal which MUST be of type `Int64` (because it overflows `Int32`), but `j` has defaulted to `Int32`. `Int32#+(Int64)` should return an `Int64`, imo, but it does not, and there inlies your problem.
<FromGitter>
<straight-shoota> @dscottboggs_gitlab If `Int32#+(Int64)` returned `Int564`, you couldn't do `a += b` when `a` is restricted to `Int32` and `b` is `Int64`. And the same should probably apply for `UInt64`, which would make `-2 + 1_u64` overflow.
<FromGitter>
<dscottboggs_gitlab> oof
<FromGitter>
<dscottboggs_gitlab> yeah
<FromGitter>
<dscottboggs_gitlab> I was thinking after I said that that that would probably be confusing
<FromGitter>
<dscottboggs_gitlab> so then I think your only option in that case is to annotate `j` as an `Int64`? Which seems pretty fair to me considering
<FromGitter>
<straight-shoota> Yes, if you wan't Int64 maths
sz0_ has joined #crystal-lang
<FromGitter>
<mwlang> @Blacksmoke16 ⏎ ⏎ > hardest part of all this is making sure the required services are registered before they are needed, if you have any ideas im open to them :) ⏎ ⏎ I don't think you should solve this particular case. This is a programmer's error. if a compiler error's not possible here (remember, I'm still learning crystal..) and depending on how you implemented it under the covers, my thought
<FromGitter>
<Blacksmoke16> when you iterate over children of the parent class, AService would be registered first, since it was defined first
<FromGitter>
<Blacksmoke16> which would mean it doesnt know about the `Store` dependency
<FromGitter>
<Blacksmoke16> would be a terrible UX to require the user to define their services in right order just for it to work
<FromGitter>
<mwlang> Ah, I get you.
<FromGitter>
<Blacksmoke16> yea, have it working atm but im not a fan of it
<FromGitter>
<mwlang> Are these typically all in the same file or are they dispersed into specific folders of a typical Athena project?
<FromGitter>
<Blacksmoke16> id imagine each service would be its own file
<FromGitter>
<Blacksmoke16> there isnt a specific folder structure for athena unlike rails or whatever
<FromGitter>
<mwlang> so, can you rely on establishing a convention that would reduce likelihood of this case occurring?
<FromGitter>
<Blacksmoke16> like what?
<FromGitter>
<mwlang> well, without the folder structure a-la Rails, nixes that idea I had. ;-)
<FromGitter>
<Blacksmoke16> even if there was a `services` directory, it would require them in abc order, so would run into same problem
<FromGitter>
<Blacksmoke16> could*
<FromGitter>
<mwlang> I was just thinking if there's a conventional structure established, then you can control order of loading.
<FromGitter>
<Blacksmoke16> currently im doing it in three steps
<FromGitter>
<Blacksmoke16> first step is to register the ones that do not have any deps, or no service deps
<FromGitter>
<Blacksmoke16> then iterate services that have service deps and see if they are all registered by now
<FromGitter>
<Blacksmoke16> if so, register them, otherwise add them to a diff hash
<FromGitter>
<Blacksmoke16> stage 3, iterate over that other hash until they are all registered, via checking if they have all been resolved and adding/deleting that record from the other hash if so, otherwise continue
<FromGitter>
<mwlang> possible to lazy evaluate on first time encounter/usage?
<FromGitter>
<Blacksmoke16> maybe?
<FromGitter>
<Blacksmoke16> well hmm
<FromGitter>
<Blacksmoke16> that would be harder as you would have to have a way to new up services but without actually newing them up?
<FromGitter>
<Blacksmoke16> or at least delay the initialization, could be an optoin
<FromGitter>
<mwlang> delaying the initialization is what I was thinking
<FromGitter>
<mwlang> the register call just adds them to that hash of yours
<FromGitter>
<mwlang> then when it's invoked the first time, that's when you instantiate.
<FromGitter>
<mwlang> presumably by the time the code that's using it is encountered, everything's been loaded and registered.
<FromGitter>
<Blacksmoke16> possibly, might have to think about that more
<FromGitter>
<r00ster91> I'm really confused. In LLVM there are custom integer bit-width types (https://llvm.org/docs/LangRef.html#integer-type) ranging from 1 bit to 8388607 bits. An integer with 8388607 can represent a number that fills my entire terminal when printing it (>9001 lines). So why don't we go higher than 128 bits and use LLVM's custom bit widths instead of using GMP?
<FromGitter>
<Blacksmoke16> thanks for the idea, ill keep you posted :p
<FromGitter>
<mwlang> I'm gathering & is like Ruby's & and essentially passing a Proc in, but could someone describe the whole of what's happening here left to right in English to help me interpret?
<FromGitter>
<mwlang> especially the -> after the String is tripping me.
<FromGitter>
<Blacksmoke16> normally `&` inthe args is a way to show that that arg is a block
<FromGitter>
<Blacksmoke16> where the blocks gets a string, but returns anything?
<FromGitter>
<Blacksmoke16> `String -> String` vs this where the block would be required to return a string as well
<FromGitter>
<mwlang> So, "a block assigned to @on_close instance variable whose result must return a String"
<FromGitter>
<mwlang> what would be the difference between ```(&@on_close : String)``` and ```(&@on_close : String ->)```
<FromGitter>
<mwlang> Is this a blocking call? ```while data = @channel.receive?``` or can I add to this something like ```while data = @channel.receive? || idle_too_long?``` with intent that of implementing a means of sending a keep alive signal on the websocket if it goes too long without receiving any new data in it's on_message event.
DTZUZO has joined #crystal-lang
<FromGitter>
<mwlang> Woah, this LLVM project is really cool. I never looked before! I just thought LLVM referred to how the parser for Crystal was built....as in an alternative to Lex/Bison for building fast parsers for the compiler.
alexherbo21 has quit [Ping timeout: 268 seconds]
alexherbo21 has joined #crystal-lang
<FromGitter>
<Blacksmoke16> @mwlang close, the value in the block would be a string, not the return value
<FromGitter>
<Blacksmoke16> to avoid the map, make intent more clear?
<FromGitter>
<tenebrousedge> why avoid map?
<FromGitter>
<mavu> not more clear to me :P
<FromGitter>
<mavu> what is
<FromGitter>
<Blacksmoke16> because it implies you're returning an array then clearing it, vs iterating over each delay, cancelling it, then clearing the delays array
<FromGitter>
<Blacksmoke16> map has to create an intermediate array, then clears it, while tap each, clears the actual delays array, this avoiding another array
<FromGitter>
<tenebrousedge> and if those few nanoseconds and bytes matter, use that
<FromGitter>
<tenebrousedge> but otherwise use the higher-level iterator
<FromGitter>
<mavu> @Blacksmoke16 Interesting.
<FromGitter>
<Blacksmoke16> IMO the latter makes it more clear that you're "canceling each delay, then clearing the array", while the map version would make me think "im creating an array from the return value of `cancel` then clearing it"
<FromGitter>
<tenebrousedge> you just like using `each`
<FromGitter>
<tenebrousedge> you could do `@delays = @delays.map` but using `tap/each` makes more sense there. But using lower-level iterators without a specific need always produces worse code
<FromGitter>
<vladfaust> Is it normal that we cannot define `abstract def self.foo` on abstract objects?
<FromGitter>
<mwlang> > I thought there might be a nice way. ⏎ ⏎ Implement within a method, returning what's not "deleted" and assign method result back to the @delays variable.
<FromGitter>
<tenebrousedge> yes, these things were mentioned
<FromGitter>
<watzon> I'm not good with this kind o stuff. Does anyone know how I could take an array of integers and split it into groups of 512 bits each?
<FromGitter>
<bcardiff> @watzon you might be looking for `BitArray`
<FromGitter>
<watzon> Maybe if it was possible to turn an Array into a BitArray and then back again. All I need to do is take each element in an array of integers, count the bits (most likely 16), and then chunk groups of those elements together where their total size is 512 bits.
<FromGitter>
<watzon> I was thinking the `Array#chunk` method would work, but it's not looking like it
<FromGitter>
<tenebrousedge> @z64 would there be an advantage to using `Iterator`, do you think?
<FromGitter>
<z64> for his use case, it doesn't sound like it, no
<FromGitter>
<tenebrousedge> what might a good heuristic be for deciding between those?
<FromGitter>
<z64> iterator is good for things you want to do lazily
<FromGitter>
<z64> in his case, he'll always want to "consume" the entire set of bits in the number, and not stop short
<FromGitter>
<Blacksmoke16> e.x. iterating a large array of objects so that the whole array isnt in memory at once right?
<FromGitter>
<z64> sure
<FromGitter>
<z64> thats what i understand they want to do, anyways - waiting for them to reply to clarify:V
<FromGitter>
<z64> additionally in this case, all these calculations happen on the stack / don't allocate anything, and have a fixed upper size (the biggest int) ⏎ so no need to worry about memory or speed here, should be plenty fast
<FromGitter>
<tenebrousedge> sure, I'm just theorizing
<FromGitter>
<z64> another example i like, Iterator is good for something like, wrapping an API endpoint that is paginated
<FromGitter>
<z64> where you would have some state to keep track of a cursor
<FromGitter>
<tenebrousedge> 👍
<FromGitter>
<Blacksmoke16> oo where your `next` method would fetch the next page
<FromGitter>
<Blacksmoke16> neat
<FromGitter>
<z64> exactly - then the user doesn't have to juggle the cursor themselves, they just `paginated_request.each do |page_of_results|`, or like `paginated_request.each.to_a` to get an array of all results
<FromGitter>
<Blacksmoke16> 💯 clever
greengriminal has joined #crystal-lang
sz0_ has quit [Quit: Connection closed for inactivity]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
dannyAAM has quit [Client Quit]
dannyAAM has joined #crystal-lang
laaron has quit [Remote host closed the connection]
<FromGitter>
<mwlang> How do you spawn, say 10 fibers then wait for all 10 to complete before moving on? i.e. Ruby's ```threads.each(&:join)``` where threads is an array of Thread
laaron has joined #crystal-lang
<FromGitter>
<mwlang> goal is to download data in parallel from REST API and once all data is collected, then fire up Websocket to listen for changes in the data.