jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | 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
<raz> hmm why does crystal spec not know `xit`
<raz> it only knows `pending`
<raz> the amount of typing is outrageous
* raz grumbles
<straight-shoota> what's xit?
<raz> in ruby land it's just an alias for pending ;)
<raz> super handy to quickly x-out or in things
<FromGitter> <Blacksmoke16> `fit` for focusing
<straight-shoota> also easy to miss =) And hard to understand
<straight-shoota> `pending` is clear
<straight-shoota> wtf is `xit`
<straight-shoota> sure, if you want to use it, just make `def xit; pending { yield }; end`
<raz> ha, i might actually do that :D
<hightower3> :)
<FromGitter> <asterite> oprypin: nice. Elm docs also work like that I wouldn't mind making the doc tool work like that, to be honest, in contrast to having a separate tool. I did it that way because I didn't know Elm by then (nor how Python did it either).
woodruffw has quit [Ping timeout: 272 seconds]
woodruffw has joined #crystal-lang
sagax has quit [Read error: Connection reset by peer]
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 256 seconds]
hightower3 has quit [Ping timeout: 268 seconds]
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
<FromGitter> <viraptor1:matrix.org> I'm a bit confused about openssl/hmac. It looks like it doesn't take Bytes as the key because it runs `key_slice = key.to_slice` and I get undefined to_slice for Array(UInt8). But in that case... How do you even pass a binary blob to it?
<FromGitter> <viraptor1:matrix.org> Grrr... Keep forgetting String.bytes doesn't return Bytes. I just need to encode / to_slice my data.
_whitelogger has joined #crystal-lang
<FromGitter> <cuteghost> Hi everyone. Does anyone know is there any way to connect to the SMTP server to read received emails via Crystal lang?
<FromGitter> <cuteghost> I found only one link related to that and the only answer was "no"
_whitelogger has joined #crystal-lang
<FromGitter> <viraptor1:matrix.org> No, but not because of the language. SMTP is only for sending emails. For receiving you want IMAP / Exchange / POP3 / JMAP
_ht has joined #crystal-lang
hightower4 has joined #crystal-lang
<hightower4> Hm if inside `lib` I have `union X; i : Int32, p : UInt8*; end `, and then a function which accepts argument of X[10], how do I actually create that argument?
<hightower4> Hm I got it with one = X.new; ten = StaticArray(X, 10).new(one).. then call function with 'ten' as argument in that place
<hightower4> Here's what I have so far, with question marked with TODO: https://carc.in/#/r/a555
<hightower4> https://carc.in/#/r/a557 (minor changes)
<hightower4> got it, needed to assign value.. ten[i] = X::Var.new; ten[i].i = some_int, or ten[i].p = some_string
<hightower4> thanks for the discussion ;-)
_whitelogger has joined #crystal-lang
<FromGitter> <bew:matrix.org> Can't you do X::Var.new i: some_int ?
<FromGitter> <bew:matrix.org> hightower4
<hightower4> bew: yes, yes, but the Vars are already initialized, so I just need to set their .i= or .p=
<FromGitter> <bew:matrix.org> Ah yes, you're doing the static vars for terminfo run I'm guessing?
<hightower4> Yes, got it working :) (Based on your code which already had the lib/fun definition, I just made the format/run be exported to crystal code)
<FromGitter> <bew:matrix.org> Cool (;
<raz> athena + clear = ♥️
<raz> it all clicks together
<hightower4> crystal + any = ♥️
<raz> +1
<straight-shoota> today is funny hash failure finding day =)
<straight-shoota> this is fun: `raise "non-matching hash #{actual_value.class} #{@expected_value.class}" if actual_value.hash != @expected_value.hash` in EqualExpectation
MasterdonX has quit [Remote host closed the connection]
<yxhuvud> I got some nice progress on my nested scheduler, and is now getting a passed test for io_uring context 1/5 times, and a BUG the other times.,
MasterdonX has joined #crystal-lang
<FromGitter> <jrei:matrix.org> ho, https://crystal-lang.org/reference/ is not EU regulations compliant...
<FromGitter> <jrei:matrix.org> aka "Cookie law"
<yxhuvud> Hmm, what are those cookies used for?
<FromGitter> <jrei:matrix.org> Google Analytics
<FromGitter> <jrei:matrix.org> Same for https://crystal-lang.org/
<FromGitter> <jrei:matrix.org> 🎉 https://github.blog/2020-12-17-no-cookie-for-you/
<yxhuvud> Ah, they show up in chrome but seemingly not firefox. weird.
<oprypin> firefox just slaughters them
<FromGitter> <jrei:matrix.org> too bad because this are likely not very used, at least advanced features justifying the use of GA :/
<FromGitter> <jrei:matrix.org> I don't know its pricing, I just know it can be a powerful tool
<oprypin> the price is the data of all the visitors
<hightower4> Hm if I have two Slice(UInt8), how to join them into one?
<FromGitter> <jrei:matrix.org> IO::Memory is an option, not sure it is the best
<oprypin> hightower4, that really should be built in
<oprypin> im quite sure this had been brought up. slice generally should have more operation
<hightower4> ok, thanks for info. for the moment I got away by converting to string since that happens anyway at a later point
<oprypin> 😬
<oprypin> hightower4, u can always manually create a new slice and then `a.copy_to(self); b.copy_to(self + a.size)`
<hightower4> ++
<oprypin> to avoid some boundary checks, convert them to pointer
<oprypin> `new = typeof(a).new(a.size + b.size); a.copy_to(new.to_unsafe); b.copy_to(new.to_unsafe + a.size)`
<FromGitter> <Daniel-Worrall> Ah, that's how you insert on an offset
<FromGitter> <jrei:matrix.org> oprypin I think then better use IO::Memory, it also creates a new buffer
<oprypin> jrei:matrix.org, what do u mean, doesnt this also create a new buffer
<oprypin> your argument is like, don't use string1+string2, use IO::Memory, it also creates a new buffer
<FromGitter> <jrei:matrix.org> I mean, instead of your last solution using typeof and copy_to
<FromGitter> <jrei:matrix.org> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fdf72d8acd1e516f8a3fc02]
<oprypin> i get that it's *a* solution but it's one with a much higher overhead
<FromGitter> <jrei:matrix.org> how? the class of IO::Memory?
<FromGitter> <jrei:matrix.org> note that if you talk about the initial buffer capacity, it can also be set
<FromGitter> <jrei:matrix.org> the copy_to is done there https://github.com/crystal-lang/crystal/blob/cf9c261/src/io/memory.cr#L99
<oprypin> ok well then you're left with the overhead of the class and almost the same code logic
<FromGitter> <jrei:matrix.org> Indeed there are overhead of simple if conditions and math, but there are negligible
<oprypin> also limits the solution specifically to `Bytes`
<FromGitter> <jrei:matrix.org> Essentially, here we have unsafe performance vs safety
<oprypin> there's no additional safety
<FromGitter> <jrei:matrix.org> one could make an error by using the wrong elements size in your example
<FromGitter> <oprypin> just for comparison ⏎ ⏎ ```new = Bytes.new(a.size + b.size) ⏎ a.copy_to(new) ⏎ b.copy_to(new + a.size) ⏎ new``` [https://gitter.im/crystal-lang/crystal?at=5fdf747169ee7f0422b2d825]
<FromGitter> <jrei:matrix.org> yeah
<FromGitter> <jrei:matrix.org> A `Slice+(other)` could exist
<FromGitter> <jrei:matrix.org> or` merge(**others)`
<FromGitter> <jrei:matrix.org> hum not merge, concat
<FromGitter> <jrei:matrix.org> sure oprypin it is similar for this simple use case. ⏎ If we have to concat, say 5 slices, it won't be the same story :/
<FromGitter> <jrei:matrix.org> Hopefully, the case of hightower4 is simple, so I agree that's similar
ua_ has quit [Ping timeout: 260 seconds]
<FromGitter> <tenebrousedge> how do I make `Foo{arg1, arg2}` give me a new `Foo` object?
<FromGitter> <Blacksmoke16> > This literal can be used with any type as long as it has an argless constructor and responds to []=.
<FromGitter> <tenebrousedge> where the meow is that documented?
<straight-shoota> and for array-like literals it's << instead of []=
<FromGitter> <tenebrousedge> kay, I did read that, but I think my eyes skipped the relevant section, thanks muchly
<FromGitter> <tenebrousedge> <3
ua_ has joined #crystal-lang
<hightower4> Hey folks, why is .x==0 instead of 100 and 200 respectively in this code: https://carc.in/#/r/a56e
<FromGitter> <Blacksmoke16> prob passed by copy?
<hightower4> it happens because of StaticArray, otherwise it works
<hightower4> well, reading https://crystal-lang.org/api/0.35.1/StaticArray.html , gonna try with the uninitialized approach
<hightower4> hm yeah, with uninitialized it works, now just having an issue of saving 10i32 in the Int32 field somehow resulting in -2147483647
<hightower4> fg
<hightower4> actually that's a separate issue, not related to this
<hightower4> thanks
<hightower4> ah yes, with uninitialized, I need to reset everything manually to nulls
<hightower4> hm why setting one value in a union also affects the other one: https://carc.in/#/r/a576. I'd expect the y to be Pointer().null
<hightower4> (like it is until .x is set to 10)
<FromGitter> <HertzDevil> but that's exactly what c unions do?
<hightower4> ah yes, without thinking I thought the values were offset. Ok so that's not the issue then
<hightower4> hm, gonna give it a break, can't see why it doesn't work: https://carc.in/#/r/a57k
<FromGitter> <HertzDevil> `unibi_var_t` is a struct though
<FromGitter> <HertzDevil> https://carc.in/#/r/a57z
<hightower4> aaah, you're a legend
<hightower4> this part with a union already existed in the code, didn't check it
<hightower4> works, thank you kindly
<FromGitter> <naqvis> https://carc.in/#/r/a589 ⏎ ⏎ isn't this a bug?
<FromGitter> <tenebrousedge> I mean I'm not one to overestimate the compiler's inference abilities. Does it work to initialize the var in like a `getter` block ?
<FromGitter> <naqvis> nope, its same
<FromGitter> <naqvis> i changed to `ivar` instead of `getter` to avoid cluttered message
<FromGitter> <tenebrousedge> https://carc.in/#/r/a58b
<FromGitter> <naqvis> Ouch
<FromGitter> <naqvis> :P
<FromGitter> <naqvis> lazy instantiation works
<FromGitter> <tenebrousedge> :plus1:
<FromGitter> <naqvis> Thanks @tenebrousedge
<FromGitter> <tenebrousedge> any time 😸
<FromGitter> <asterite> Ali: not a bug. When you pass self in initialize the object isn't yet initialized. What if that method where you pass self accessed bar? Boom!
<FromGitter> <Daniel-Worrall> Is there a stdlib way to merge an Array of Ranges as much as possible?
<FromGitter> <asterite> what is merging a range? (that's the answer :-))
<FromGitter> <Daniel-Worrall> the minimal amount of ranges that cover the same values
<FromGitter> <Daniel-Worrall> 1) .5, 3..6 => 1..6
<FromGitter> <Daniel-Worrall> is what I meant
<FromGitter> <Daniel-Worrall> I'll just attempt a coding of such thing
<FromGitter> <Daniel-Worrall> but I fear it'll be recursive
<oprypin> Daniel-Worrall, there is no such functionality. it is actually a challenging algorithmic problem
<FromGitter> <Daniel-Worrall> Interesting
<Andriamanitra> i've seen it on leetcode or similar sites at least 3 times
<oprypin> oh i remember now. i must have solved it myself at least once
<oprypin> u just sort all start and end points
<FromGitter> <Daniel-Worrall> I was just gonna sort the start and iterate on it
<oprypin> you need `[{1,:start},{5,:stop},{3,:start},{6,:stop}].sort!`
_ht has quit [Remote host closed the connection]
<oprypin> iterate over them, doing +1 or -1 on a counter each time. every time it changes from 0 to non0 you start a range, and when it changes from non0 to 0 you end it
<FromGitter> <erdnaxeli:cervoi.se> hi, while this does not work? https://carc.in/#/r/a58s
<FromGitter> <erdnaxeli:cervoi.se> if I remove the `.times` it is ok
<FromGitter> <erdnaxeli:cervoi.se> you can't chain methods in a case's when? :(
<FromGitter> <Blacksmoke16> why would you expect it to work?
<FromGitter> <erdnaxeli:cervoi.se> because I can call a method on the object
<FromGitter> <erdnaxeli:cervoi.se> so I could expect I can chain call, and it check the last return value
<FromGitter> <erdnaxeli:cervoi.se> well, the whole expression's value
<FromGitter> <Blacksmoke16> cant just do that then case on that returned value?
<FromGitter> <erdnaxeli:cervoi.se> no, because I have different when conditions
<FromGitter> <erdnaxeli:cervoi.se> well I can but I need to have multiple temp vars
<FromGitter> <erdnaxeli:cervoi.se> this is just unexpected that I can call a method, but just one, not chaining on the method's result
<FromGitter> <Daniel-Worrall> I came up with this ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Only works on inclusive ranges [https://gitter.im/crystal-lang/crystal?at=5fdfc0e9e7f693041f2083e3]
<FromGitter> <erdnaxeli:cervoi.se> actually I (naively) though the case was juste rewritten (or interpreted) as a if, but that's clearly not the case
<FromGitter> <Blacksmoke16> it is, but syntax parser might just not handle that case
<FromGitter> <erdnaxeli:cervoi.se> ok
<FromGitter> <Blacksmoke16> granted idk what you would expect it to do after calling .times
<FromGitter> <Daniel-Worrall> Yeah, I've wanted to do that before erdnaxeli
<FromGitter> <Daniel-Worrall> but that's the limitation of the pattern matchin
<FromGitter> <erdnaxeli:cervoi.se> I would expected `case var when .a.b.c` to be interperted as `if var.a.b.c`
<FromGitter> <erdnaxeli:cervoi.se> actually I was even doing `when .a.b && something_else`
<FromGitter> <Blacksmoke16> its more like `var === var.a.b.c`
<FromGitter> <erdnaxeli:cervoi.se> I will just go with a plain if elsif :)
<FromGitter> <Daniel-Worrall> Does a proc help you here? https://carc.in/#/r/a598
<FromGitter> <Blacksmoke16> i still dont see what thats checking tho
<FromGitter> <Blacksmoke16> like its never going to be false so always would print that no?
<FromGitter> <erdnaxeli:cervoi.se> @Daniel-Worrall: ahah it works but I prefer as well do a simple if
<FromGitter> <erdnaxeli:cervoi.se> @Blacksmoke16: the check was with a flag enum and another condition: `case var when .enumvar.value? && somethingelseistrue`
<FromGitter> <Daniel-Worrall> Yeah, I didn't know what exact methods you wanted so I just put the nonesense of the example
<FromGitter> <Blacksmoke16> can you make an example with that setup?
<FromGitter> <erdnaxeli:cervoi.se> I was just using the case as a sortcut to write an if / elsif, that's not a big deal
<FromGitter> <Blacksmoke16> ok, because using `&&` in it is deff not going to work
<FromGitter> <erdnaxeli:cervoi.se> yeah I realized
straight-shoota has quit [Ping timeout: 272 seconds]
asterite has quit [Ping timeout: 260 seconds]
jhass has quit [Ping timeout: 272 seconds]
<FromGitter> <christopherzimmerman> Is there a way to get a generic type's generic type? So something like the following: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ If anyone is familiar with Nim I'm looking for the equivalent of `T` and then `TT` [https://gitter.im/crystal-lang/crystal?at=5fdfd4a8dbb17f28c58e0258]
<FromGitter> <HertzDevil> `{{ T.type_vars }}`, assuming they are public
<FromGitter> <HertzDevil> in this specific case you can also do `typeof(c.first.first)` or
<FromGitter> <HertzDevil> ```def generic_child(c : Array(Array(T))) forall T ⏎ T ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5fdfd52793af5216fc52ef2c]
<FromGitter> <christopherzimmerman> Yea the second would be nice if I knew what the inner type was, but it could be any generic in my case, not just array, and can't do `T(V)` for example. Might have to do some macro magic.
<FromGitter> <HertzDevil> at the minimum you have to ensure the inner type isn't a union
straight-shoota has joined #crystal-lang
<FromGitter> <christopherzimmerman> Luckily that will never happen, the inner type should only be a single numeric type, but that makes me wonder if there is a way to enforce that at compile time, is there a way to make sure a generic isn't a union?
<FromGitter> <christopherzimmerman> Right now I just check explicitly against all numeric types
<FromGitter> <HertzDevil> ```{% if T.union_types.size > 1 %} ⏎ {% raise "Inner type cannot be a union" %} ⏎ {% end %}``` [https://gitter.im/crystal-lang/crystal?at=5fdfda15ac9d8e7463c08c4a]
<FromGitter> <HertzDevil> you can't *overload* based on the number of union types but that's probably immaterial to this example
<FromGitter> <HertzDevil> i'd argue returning a type in a def and not immediately doing anything with it is not very helpful
<FromGitter> <christopherzimmerman> The actual use case is being able to create scalar values based on the type of a generic's inner type. So if I pass a `Num::Grad::Context(Tensor(Float32))`, I need to be able to create Float32's to pass around to C libraries. But unfortunately, it can be a context of Tensors, ClTensors, or CudaTensors so I can't nest the generics as far as I want.
<FromGitter> <christopherzimmerman> Might be worth a PR to the lang itself, it's a super convenient feature in Nim, I use it all the time.
<FromGitter> <HertzDevil> why would you want to match an unrestricted generic here
straight-shoota has left #crystal-lang ["Leaving"]
<FromGitter> <HertzDevil> i don't see what prevents you from just doing `def generic_child(c : Num::Grad::Context(Tensor(T))) forall T` and `def generic_child(c : Num::Grad::Context(CudaTensors(T))) forall T` and so on
<FromGitter> <HertzDevil> and again, it's unlikely you want the type alone, and when there's more context `typeof` can also extract inner types without the private type issue
<FromGitter> <christopherzimmerman> Nothing stopping me from doing it, but when I have hundreds of functions that would be `N` identical copies for each storage backend, with the only difference being the signature, trying to find a way to avoid it.
<oprypin> christopherzimmerman, note that if i have `arr = Array(Int32).new`, i can use `typeof(arr.first) == Int32`
<FromGitter> <HertzDevil> https://play.crystal-lang.org/#/r/a5cm
<FromGitter> <HertzDevil> if you have hundreds of functions, instantiatng the same def with hundreds of free vars isn't much different from creating hundreds of defs
<FromGitter> <HertzDevil> is there a reason you can't use typeof
<FromGitter> <asterite> erdnaxeli: it's a bug, please report it. Thank you!
<FromGitter> <erdnaxeli:cervoi.se> oh ok, will do!
straight-shoota has joined #crystal-lang
asterite has joined #crystal-lang
jhass has joined #crystal-lang