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
<FromGitter> <Blacksmoke16> i found a bug ^.^ https://play.crystal-lang.org/#/r/auwf
<FromGitter> <Blacksmoke16> nvm
<FromGitter> <Blacksmoke16> `next` not `return` πŸ™ˆ
renich has joined #crystal-lang
renich has quit [Client Quit]
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 260 seconds]
f1reflyylmao is now known as f1refly
andremedeiros has quit [Quit: ZNC 1.8.2 - https://znc.in]
andremedeiros has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
Seich has joined #crystal-lang
_ht has joined #crystal-lang
postmodern has quit [Quit: Leaving]
asterite has quit [Quit: Bye]
straight-shoota has quit [Quit: ZNC 1.8.2 - https://znc.in]
asterite has joined #crystal-lang
straight-shoota has joined #crystal-lang
hendursa1 has joined #crystal-lang
hendursaga has quit [Ping timeout: 240 seconds]
<FromGitter> <HertzDevil> writing mpfr bindings for fun
<FromGitter> <asterite> Nice! I think they are more powerful than gmp, so if it works we could just use those instead
<FromGitter> <HertzDevil> apart from the new rounding modes i mentioned, they also have proper inf and nan
<FromGitter> <HertzDevil> almost every def looks like this
<FromGitter> <HertzDevil> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=6075794e46a93d4a19c2e0dd]
<FromGitter> <HertzDevil> and if `+(other)` (no restriction) exists, currently that's stricter than the overload above so `+(other : BigFloatR)` needs to be written out too
<FromGitter> <HertzDevil> mutating variants don't help much since the rounding mode is still there
alexherbo2 has joined #crystal-lang
richbridger has joined #crystal-lang
<FromGitter> <lodenos> Hello guy’s, I’ve a question, how can we make a singleton class ?
<FromGitter> <naqvis> make constructor private
<FromGitter> <naqvis> create a class level variable and assign instance to that
<FromGitter> <naqvis> create a static method which will return that instance
<FromGitter> <naqvis> https://carc.in/#/r/av5w
<FromGitter> <Blacksmoke16> `class_getter instance : self { new }` also works
<FromGitter> <lodenos> Thx 😊
<FromGitter> <lodenos> It’s usefull https://carc.in/#/r/av73
<FromGitter> <lodenos> ez
<FromGitter> <Blacksmoke16> id still also use the private `initialize` method
<FromGitter> <Blacksmoke16> so you cant get an instance without using that class method
<FromGitter> <lodenos> πŸ‘Œ
alexherbo20 has joined #crystal-lang
alexherbo20 is now known as alexherbo2
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo20 has joined #crystal-lang
<FromGitter> <Dan-Do> Is there a simple way to completely exit a block? https://carc.in/#/r/av94
alexherbo20 is now known as alexherbo2
<FromGitter> <Dan-Do> After `next`, it continues at `p ok` in the `ensure`
<FromGitter> <Blacksmoke16> `break`?
<FromGitter> <HertzDevil> but that's exactly what `ensure` is for
<FromGitter> <Dan-Do> > `break`? ⏎ ⏎ does not :) work https://carc.in/#/r/av98
<FromGitter> <Blacksmoke16> what are you expecting it to output?
<FromGitter> <Dan-Do> just exit the block, like `return` in other language
<FromGitter> <Blacksmoke16> it is tho? thats why `end` isnt being printed
<FromGitter> <Blacksmoke16> you have an `ensure` block which is being executed, because thats what it does
<FromGitter> <Dan-Do> Just thought that `ensure` is only run when there is exception :)
<FromGitter> <Blacksmoke16> thats `rescue`
<FromGitter> <Blacksmoke16> `else` when no exceptions
<FromGitter> <Blacksmoke16> `ensure` after either
<FromGitter> <Dan-Do> No, I mean `next` should not be an exception, IMO
<FromGitter> <Blacksmoke16> its not an exception tho?
<FromGitter> <Dan-Do> Ah, ok, I miss this `regardless of whether an exception was raised or not`
<FromGitter> <Blacksmoke16> mhm
<FromGitter> <Dan-Do> So, if I still want to put `ensure` there, any way to stop the execution and return?
<FromGitter> <Blacksmoke16> dont use the `ensure`?
<FromGitter> <Dan-Do> Ok, just double the code like this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=6075b87cdc24646812bb880c]
<FromGitter> <Blacksmoke16> whats the end goal here?
<FromGitter> <Blacksmoke16> looks right
<FromGitter> <Daniel-Worrall> `ensure` ensures the code is read regardless of what happens, whether successful, unsuccesful, or errors
<FromGitter> <Daniel-Worrall> s/read/run
<FromGitter> <Daniel-Worrall> Not coding atm, but a thought came up. Does JSON::Serializable have a native way to store as String and parse data lazily as it's accessed?
<FromGitter> <Daniel-Worrall> though I doubt converters are that expensive
<FromGitter> <Blacksmoke16> i doubt it, as it uses a pull parser, so it couldnt just stop and wait before continuing as it couldnt parse anything else
<FromGitter> <Daniel-Worrall> I mean like pulling it in as a string, then only converting it on an accessor or something
<FromGitter> <Blacksmoke16> e.g. for a like nested obj or something?
<FromGitter> <Daniel-Worrall> It could easily support a nested object, sure, but I didn't have it in mind
<FromGitter> <Blacksmoke16> would still need to store the string, unless the data is really big i doubt it would have an affect
<FromGitter> <Daniel-Worrall> This was prompted from the Time::Span regex from yesterday in the discord
<FromGitter> <Daniel-Worrall> Yeah, but then you'd have no overhead from parsing
<FromGitter> <Blacksmoke16> technically theres like no overhead for converters as they're usually class methods on a module, so dont even need to instantiate them
<FromGitter> <Daniel-Worrall> there's the computation time?
<FromGitter> <Blacksmoke16> prob not much more than you'd need to parse it as a raw string
<FromGitter> <Daniel-Worrall> hmmm
<FromGitter> <Blacksmoke16> maybe benchmark it?
<FromGitter> <Daniel-Worrall> Idk what kind of objects would be computationally parse heavy, but you're right, it's something that needs to be benchmarked to gleam insight
<FromGitter> <Blacksmoke16> it doesnt like large unions
<FromGitter> <Blacksmoke16> as it essentially tries to parse it for each member
<FromGitter> <Blacksmoke16> which raises an exception on each failure until it finds one that works
<FromGitter> <Daniel-Worrall> oof
<FromGitter> <Blacksmoke16> but thats not a real common use case imo
<FromGitter> <Daniel-Worrall> Is there an Ordering you can provide if you know which objects are most common?
<FromGitter> <HertzDevil> no
<FromGitter> <HertzDevil> it's always alphabetical order since crystal internally canonicalizes all unions like that
<FromGitter> <Daniel-Worrall> makes sense
<FromGitter> <HertzDevil> which is reflected in `TypeNode#union_types`
<FromGitter> <Daniel-Worrall> Maybe you could provide an option ordering
<FromGitter> <Daniel-Worrall> optional
<FromGitter> <HertzDevil> just write your own converter at that point
<FromGitter> <Daniel-Worrall> Ahh
<FromGitter> <HertzDevil> the default impl is in `json/from_json.cr`
<FromGitter> <HertzDevil> `def Union.new(pull : JSON::PullParser)`
<FromGitter> <Daniel-Worrall> yeah, makes more sense now
<FromGitter> <HertzDevil> it actually does try the json primitive types first
<FromGitter> <HertzDevil> then it does this to the remaining types
<FromGitter> <HertzDevil> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=6075c1c306e2e024e84f0273]
<FromGitter> <HertzDevil> where `non_primitives = T.reject { ... }`
<olbat> Hello everyone, is there anyone from the core team available to review/merge this MR: https://github.com/crystal-lang/clang.cr/pull/9 O:-)
<olbat> Thanks in advance! :)
<FromGitter> <Daniel-Worrall> How can I sort by multiple parameters at once? Like i want to sort_by(&.property_one) and if they're equal sort_by(&property_two) without iterating multiple times. Iterator maybe?
<FromGitter> <Blacksmoke16> `include Comparable(self)` and define `<=>`
<FromGitter> <tenebrousedge> there's a sorting method that takes a block, yeah?
<FromGitter> <Daniel-Worrall> Yeah, `sort_by`
<FromGitter> <HertzDevil> `sort_by { |v| {v.property_one, v.property_two} }
<FromGitter> <tenebrousedge> ^
<FromGitter> <Daniel-Worrall> Ah, tuples, nice
<FromGitter> <Daniel-Worrall> Any way to short syntax that?
<FromGitter> <HertzDevil> why
<FromGitter> <Daniel-Worrall> brevity
<FromGitter> <Blacksmoke16> if this logic is common use `Comparable`, then just can do `.sort`
<FromGitter> <tenebrousedge> do what @Blacksmoke16 said
<FromGitter> <HertzDevil> doesn't look any briefer to me
<FromGitter> <Daniel-Worrall> It's for a codewars kata, so I'm not looking to make a new class or extend stdlib
<FromGitter> <HertzDevil> but if you must, make that a def then you can do `&.sort_key`
<FromGitter> <Blacksmoke16> oh, whats the type you're sorting by then?
<FromGitter> <Daniel-Worrall> Just wondering if there was a way to &.method short syntax
<FromGitter> <Daniel-Worrall> weight by sum of digits, then alphabetical
<FromGitter> <Daniel-Worrall> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=6075cec0dfe7ca1b11b335e8]
<FromGitter> <tenebrousedge> `each_char` rather than `chars`
<FromGitter> <tenebrousedge> I would omit the arg to `split` but that's just me
<FromGitter> <Daniel-Worrall> I omitted the arg on split, and used sort_by! on amend
<FromGitter> <Daniel-Worrall> Why `each_char`? `chars` reads better to me
<FromGitter> <tenebrousedge> no need to allocate a new array
<FromGitter> <Daniel-Worrall> ahh.
<FromGitter> <tenebrousedge> the only time to use `chars` is when you need a method that's on `Array` but not the iterator
<FromGitter> <Daniel-Worrall> Fair
andremedeiros has quit [Read error: Connection reset by peer]
andremedeiros has joined #crystal-lang
ua has quit [Read error: Connection reset by peer]
ua has joined #crystal-lang
_ht has quit [Remote host closed the connection]
fifr` has quit [Quit: Gateway shutdown]
<FromGitter> <erdnaxeli:cervoi.se> hi, is that a bug? https://carc.in/#/r/avee
<FromGitter> <erdnaxeli:cervoi.se> in `a[0].test` the compiler knows that `Parent` can't be instancied, so it must be `Child1` or `Child2` and that's ok (as said in https://crystal-lang.org/reference/syntax_and_semantics/virtual_and_abstract_types.html)
<FromGitter> <erdnaxeli:cervoi.se> but in the case it complains it is not exhaustive, `in Parent` must be added
<FromGitter> <tenebrousedge> huh. It also does this if you do `a = [] of Child1 | Child2`
<FromGitter> <Blacksmoke16> compiler reduces it to `Array(Parent)`
<FromGitter> <tenebrousedge> and I guess https://github.com/crystal-lang/crystal/issues/9116
fifr` has joined #crystal-lang
hendursa1 has quit [Ping timeout: 240 seconds]
hendursa1 has joined #crystal-lang