<FromGitter>
<jwoertink> The reason I need it to be a hash is so I can call `reject`. If it comes through as a NamedTuple, it would throw an error on that.
<FromGitter>
<Blacksmoke16> am sure there is some reason to it but yea, wish solution was cleaner :/
<FromGitter>
<jwoertink> interesting... I'm gonna play with your last example there and see how that works out
<FromGitter>
<jwoertink> Thanks for the help!
<FromGitter>
<jwoertink> > cast from NamedTuple() to Hash(Symbol, String)+ failed
<FromGitter>
<jwoertink> lol
<FromGitter>
<Blacksmoke16> rip
<FromGitter>
<jwoertink> right? I started just commenting some stuff out to see where I can get it to compile, then got
<FromGitter>
<jwoertink> > Error: you've found a bug in the Crystal compiler
<FromGitter>
<jwoertink> woo hoo!
<FromGitter>
<Blacksmoke16> xD
<FromGitter>
<paulcsmith> Does anyone know of a clever way to get around this limitation? I'm trying to restrict the instance variable type that is a generic https://play.crystal-lang.org/#/r/4l9q
<FromGitter>
<paulcsmith> I can't seem to get it to work (maybe because it isn't supported π)
<robacarp>
@paulcsmith I ran into that with amber_router and found that you have to pass T into OtherClass as well
<robacarp>
er, OtherThing
<FromGitter>
<paulcsmith> robacarp: Hmm, could you give an example? I'm not sure I understand
<FromGitter>
<jwoertink> You didn't pass `Bool` in to the OtherThing in that exmaple
<robacarp>
it doesn't need to
<robacarp>
that play makes Thing and OtherThing both generic
<FromGitter>
<jwoertink> I thought `class OtherThing(T)` meant that you have to write `OtherThing(SomeConstantRequredHere)`
<robacarp>
@paulcsmith I think, unfortunately, that because of `@field : Field(T)` restriction on the constructor, that this locks both Field and OtherThing to be the _same_ generic
<robacarp>
@jwoertink are you confused about the type restriction on the constructor parameter?
<FromGitter>
<jwoertink> no, that makes sense to me
<FromGitter>
<jwoertink> Just the part where the `T` is passed in to the class, but you don't actually have to pass a type in
<FromGitter>
<jwoertink> learn something new everyday! :d
<FromGitter>
<jwoertink> :D
<robacarp>
oh, I think that part is a bug
<robacarp>
that'll explode later, I think
<FromGitter>
<jwoertink> lol
<FromGitter>
<jwoertink> ok, then that makes sense to me
<robacarp>
you mean it should be `OtherThing(Bool).new(field)`
<FromGitter>
<jwoertink> right
<robacarp>
Crystal support for generics is shakey, and that's one place where it is so (cc @paulcsmith)
<FromGitter>
<paulcsmith> Oh I thought that was a feature (one that I like a lot :P)
<FromGitter>
<jwoertink> "feature" ...
<FromGitter>
<paulcsmith> I like that I don't need to pass the generic type in and that the compiler can figure it out
<robacarp>
if you can get it to work, :celebrate: but when it segfaults :sadness:
<FromGitter>
<jwoertink> That's awesome if it works!
<FromGitter>
<paulcsmith> Have you had it segfault because of that? It seems like it should fail or work
<FromGitter>
<paulcsmith> Or maybe you were joking and I didn't catch on until it was too late :P
<robacarp>
It's been several weeks, but I have had crystal experience some catastrophic failures that required manually dividing the code to find resolution
<robacarp>
I don't remember the exact situation, but I do know that it was related to some fancier use of Generics
<robacarp>
come to think of it, that might have been on the query builder for granite
<FromGitter>
<paulcsmith> Uh-oh! I'll definitely keep an eye out then. Thanks for the heads up
<robacarp>
@drinkmorewaters the community effort is at crystal-lang.org/docs
<FromGitter>
<drinkmorewaters> @FromIRC It's a great resource for people coming to Crystal as professional developers. But i'm more looking at complete beginner materials.
<robacarp>
oh, I see. I've heard chatter about this sort of thing, but I have no idea if anything has materialized
<FromGitter>
<jwoertink> @drinkmorewaters there's https://crystalmastery.io if you're looking for beginner stuff. I think it's down at the moment, but there's a few different starter things out there
<FromGitter>
<jwoertink> https://crystal-ann.com/ also has some good stuff that pops up if you keep an eye on that
<FromGitter>
<jwoertink> And I think http://crystalweekly.com/ might have some tutorials that come up from time to time
<FromGitter>
<drinkmorewaters> @jwoertink I check all those daily, i also check Medium, Reddit and Twitter "Crystal Lang" daily. But i guess the tutorials will come at a later date for now, until the language reaches 1.0+.
moei has quit [Read error: Connection reset by peer]
moei has joined #crystal-lang
pinupgeek has quit [Quit: pinupgeek]
<FromGitter>
<drinkmorewaters> Does this OSX package work for anyone? Does it load?
<FromGitter>
<colonlc> This produces an error at `sound.buffer.finalize()`: `argument 'result' of 'VoidCSFML#sfml_sound_getbuffer' must be Pointer(Pointer(Void)), not SF::SoundBuffer (nor Pointer(Void) returned by 'SF::SoundBuffer#to_unsafe')`
<FromGitter>
<colonlc> Seems like a bug at `VoidCSFML.sfml_sound_getbuffer`
rohitpaulk has quit [Ping timeout: 256 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
livcd has quit [Ping timeout: 276 seconds]
livcd has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
DTZUZO has quit [Ping timeout: 276 seconds]
<crystal-gh>
[crystal] RX14 opened pull request #6439: Change Foo:Class representation of Class types to Foo.class (master...feature/change-class-string) https://git.io/fN4Aa
<FromGitter>
<bew> @drinkmorewaters you can do `if accounts.is_a?(Array(String))` to check that `accounts` is an array of strings
<FromGitter>
<bew> for numbers you'd do `if accounts.is_a?(Array(Int32))` (`Int32` is the default number type when you write `2`)
akaiiro has quit [Ping timeout: 276 seconds]
<oprypin>
colonlc, why are u calling finalize?
<FromGitter>
<drinkmorewaters> @bew cheers dude!
<FromGitter>
<colonlc> This is just an example to show the error, I actually tried to build a 'finalize-everything' method and I do not have a reference to the soundbuffer.
<FromGitter>
<rishavs> Seriously though, is there downside to that kind of code? I was planning on using these blocks in my HTML heredocs to take care of the conditional views
<FromGitter>
<colonlc> How do I get Zipfile entries behind a subfolder? `Zip::Reader#each_entry` only gets me the folder, not the contents of it.. (Zipfile structure: ``` β file.zip β β 1) foo.txt (file) β 2) bar (directory)1) baz.txt (file) <- how do i get to this? ... [https://gitter.im/crystal-lang/crystal?at=5b57520ec579673e6b903167]
<FromGitter>
<j8r> @rishavs use at least `xx += " Index: #{index}"` π
<FromGitter>
<j8r> I never had to use `begin; end` outside exception handling with `rescue`
<Yxhuvud>
rishavs: yes, it is very inefficient as you will end up allocating an exponential length of strings. Use Array#join to merge the strings, instead.
<Yxhuvud>
or a stringbuilder.
<Yxhuvud>
hmm. or quadratic perhaps, but still very inefficient
hightower4 has quit [Ping timeout: 264 seconds]
<FromGitter>
<rishavs> thanks
<FromGitter>
<colonlc> To my question: My zipfile subfolder was empty lol
hightower4 has joined #crystal-lang
alex`` has quit [Quit: WeeChat 2.1]
<FromGitter>
<bew> @rishavs you'd better use ECR instead
<FromGitter>
<rishavs> @bew I actually didnt want to use ECR. I wanted to see how far can I go without using it. So far, things have been great and my pure string templates render in 0.5 ms
<FromGitter>
<rishavs> By using simple case-when routing and string/heredoc templates, i am so far getting about 2x the speed of Kemal. Of course, everything goes for a toss when Db calls get into the picture
<FromGitter>
<rishavs> Then my lovely 50us pages become 250ms pages T_T
alex`` has joined #crystal-lang
<FromGitter>
<bew> ECR is a compile time templating system, so you'd get the same speed
<FromGitter>
<rishavs> ooh, nice! I didn't know that
<FromGitter>
<rishavs> btw, do you have any idea if our db/pg connections are not fully optimized? I could have sworn that when I was using node/koa to connect to a cloud based elephantsql instance, i was getting must faster query replies than I am getting now with my crystal db
alex`` has quit [Quit: WeeChat 2.1]
<FromGitter>
<fridgerator> I have heard others say crystal-db is not optimized and needs some work, but I dont' have any specific information
<FromGitter>
<talbergs> may crystal-db have `dgraph` or `neo4j` as they become more of use these days
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzzβ¦]
wontruefree has joined #crystal-lang
wontruef_ has quit [Ping timeout: 256 seconds]
wontruefree has quit [Client Quit]
wontruefree has joined #crystal-lang
wontruefree has quit [Client Quit]
<FromGitter>
<sam0x17> in crystal how can I set an Int32 to equal infinity?
<FromGitter>
<bew> That doesn't exist, an Int32 has a limit
<FromGitter>
<sam0x17> yeah I just need the max and min int values
<FromGitter>
<bew> Int32::MAX
<FromGitter>
<sam0x17> omg
<FromGitter>
<sam0x17> thx
<FromGitter>
<bew> Same for min
<FromGitter>
<sam0x17> thx
wontruefree has joined #crystal-lang
alex`` has joined #crystal-lang
wontruefree has quit [Quit: bye]
wontruefree has joined #crystal-lang
wontruefree has quit [Quit: bye]
<hightower4>
What's the fastest way to check a .cr file for syntax?
<hightower4>
(i.e. a syntax check like ruby -c)
<FromGitter>
<colonlc> You could use `crystal tool format --check <file / folder>`
jokke is now known as foxxx0
foxxx0 has quit [Disconnected by services]
jokke has joined #crystal-lang
<FromGitter>
<DanilaFe> How does the Crystal tuple type work? The docs says its type is Tuple(*T), and I'd like to be able to implement something that can take an arbitrary number of types
hightower4 has quit [Ping timeout: 265 seconds]
<FromGitter>
<straight-shoota> a tuple has a fixed number of elements
<FromGitter>
<DanilaFe> What I mean is, you can have Tuple(Int32), Tuple(Int32, String), and so on
<FromGitter>
<straight-shoota> if you need dynamic size, you should use a different data structure like `Array`
<FromGitter>
<straight-shoota> I don't understand
<FromGitter>
<DanilaFe> The size is known at compile time
<FromGitter>
<DanilaFe> From what I understand, tuple is a single generic type. But the generic type can have different numbers of type parameters. { 3 } creates Tuple(Int32), and { 3, 4, "hi" } creates Tuple(Int32, Int32, String). These two instances of the tuple struct, but they have a different number of type parameters (though fixed at compile time)
<FromGitter>
<j8r> What do you need?
<FromGitter>
<j8r> You could either use Tuple, Array or StaticArray
<crystal-gh>
[crystal] straight-shoota opened pull request #6442: Change WinError to get message as UTF16 string (master...jm/winerror-wchar) https://git.io/fNBXd
<FromGitter>
<j8r> Depending of how much flexibility you need
<FromGitter>
<DanilaFe> I'd like to be able to do things like MyClass(Int32), MyClass(Int32, String) and so on, similarly to the way that Tuple does it
<FromGitter>
<DanilaFe> I'm wondering if that's possible at all
<FromGitter>
<j8r> Does the type and the size change at run time or not?
<FromGitter>
<DanilaFe> no, it does not
<FromGitter>
<j8r> Ok you can use Tuple so, which is immutable
<FromGitter>
<j8r> (by types I mean the elements inside the array, not the array itself)
<FromGitter>
<DanilaFe> Yeah, nothing changes at run time. My question isn't what built-in type to use, but whether it's possible to use generics to achieve the same effect that tuple has, where it can have 1, 3, or any number of type parameters
<FromGitter>
<straight-shoota> yes, just do the same thing as tuple: Use `*T` as generic argument
<FromGitter>
<DanilaFe> That's what I've been trying to do. I've gotten the *args : *T part, but now, I don't know where to go from there: what's the type of *args? Can I iterate over each arg while being aware of its type? Do I need to use macros to write code that does work on each individual argument?
<FromGitter>
<DanilaFe> Sorry if this is a dumb question
<FromGitter>
<straight-shoota> `args` is of type `*T` which is essentially a `Tuple` type
<FromGitter>
<straight-shoota> you can use it like any splat argument
<FromGitter>
<DanilaFe> Thank you. I'm going to try this out
wontruefree has quit [Ping timeout: 256 seconds]
pbodev1 has quit [Quit: ChatZilla 0.9.93 [Firefox 56.0/20170903140023]]
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
alex`` has quit [Ping timeout: 256 seconds]
alex`` has joined #crystal-lang
<FromGitter>
<DanilaFe> Ok, I've got another question. Say I've got my `*T` type parameter. But I'd like a method that accepts a different type, which depends on `*T`. To clarify, let's say I have `*T = Int32, String` and I'd like to have a method that accepts `Array(Int32), Array(String)`. This is asking for a lot it seems like. Is there even a way to do this?
<FromGitter>
<DanilaFe> I've tried to mess with typeof until I realized it's not allowed in type restrictions
<FromGitter>
<straight-shoota> This can probably be done with a macro
<FromGitter>
<DanilaFe> My first attempt (the "dumb way") was to try use macros inside the parameter declaration. That didn't work (not that I expected it to)
<FromGitter>
<straight-shoota> Yeah, that's not that easy. I think it can be done, though, somehow...
<FromGitter>
<straight-shoota> @asterite would know =)
<FromGitter>
<DanilaFe> I would be very impressed to see this done
<FromGitter>
<DanilaFe> or even to get a pointer in the right direction
<FromGitter>
<DanilaFe> (by the way, thanks a lot for helping me with the `*T` thing)
<FromGitter>
<DanilaFe> almost, except that A and B in the second example are actually `*T`, that is, a tuple-like type like straight-shoota explained above
<FromGitter>
<bew> I think he wants `*T` as the generic, like