<Nickage>
this behaviour feels weird since it works fine for Classes (using the inherited macro) but for Modules it doesn't recognize methods after the include https://hastebin.com/kisatusuzu.rb
<FromGitter>
<Blacksmoke16> not sure how modules are implemented, but then you do `include MyModule` does it just plop in the methods as if they were part of that class by default?
<FromGitter>
<Blacksmoke16> looks like the module macro code gets executed before your methods are defined
Nickage has quit [Ping timeout: 256 seconds]
_whitelogger has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter>
<fusillicode_twitter> Guys I'm in a situation in which I'm getting an union type where I really want the unique parent type of the union :(
<FromGitter>
<fusillicode_twitter> In particular I've an hash where the values are actually the types that a given method can accept
<FromGitter>
<fusillicode_twitter> However when a try to pass the fetched values to the method, the compiler complains that the method accept only the parent type (in my case a mixed in module) rather than the union type of the values of hash :(
<FromGitter>
<fusillicode_twitter> Basically what I want is polymorphism without explicitly use inheritance and by relying only on mixins
<FromGitter>
<fusillicode_twitter> Right now I've worked around the issue with a type alias but it is really not what I wanted :(
<FromGitter>
<fusillicode_twitter> I mean, I already have a type (read module) that has the main logic of the two concrete types and what I want is to simply be able to use the two concrete types transparently without knowing which one I've in hand at a given moment
jokke has quit [Ping timeout: 252 seconds]
jokke has joined #crystal-lang
<jhass>
What do you folks think, where would I reach more of our community, mailing list or reddit?
<FromGitter>
<bew> github x) personnaly I never look the mailing list..
<FromGitter>
<bew> can you show an example @fusillicode_twitter ?
<FromGitter>
<fusillicode_twitter> @bew sure mate, I'll try do extract a snippet of my code
<jhass>
well github is not for meta-talk ;)
<FromGitter>
<fusillicode_twitter> thanks for the support 🙇♂️
<FromGitter>
<fusillicode_twitter> jhass I think that a subreddit for crystal would be awesome :D
<FromGitter>
<mettuaditya> is there any breath first search(BFS) implementation in crystal
<FromGitter>
<mettuaditya> any ideas on how to implement graph in crystal
<FromGitter>
<r00ster91> you could use a graphics library
<FromGitter>
<mettuaditya> like
<FromGitter>
<r00ster91> do you want to do it in the console or a new graphical window?
<FromGitter>
<mettuaditya> i just want to implement some graph algorithms
<FromGitter>
<fridgerator> @r00ster91 graph, not graphics
<FromGitter>
<r00ster91> I thought you want to display the graphs as well
<FromGitter>
<mettuaditya> @r00ster91 no problem... but help me if u know anything about it
<FromGitter>
<yxhuvud> I don't think I've had explicit graphs when implementing BFS, they tend to arise naturally from the neighbours and visited-methods.
DTZUZO has joined #crystal-lang
flaviodesousa has joined #crystal-lang
<FromGitter>
<wontruefree> is there a crystal version manager ?
<FromGitter>
<wontruefree> I just saw that on awesome crystal
<FromGitter>
<wontruefree> I am trying to use the HTTP::Client and it is not working as expected but if I use a TCPSocket with `client << "GET / HTTP 1.1\n\n"` it seems to work fine
<FromGitter>
<wontruefree> The server is Crystals HTTP::Server
<FromGitter>
<wontruefree> seems like HTTP::Client should send `GET / HTTP 1.1\n\n ` right?
<jhass>
moar code, less "not working", moar description of expectation vs observed behaviour
<jhass>
pls
<FromGitter>
<wontruefree> yeah I didnt want to spam the chat
<FromGitter>
<wontruefree> I can open an issue
<jhass>
do a gist ;)
<jhass>
issues are for when you're sure of a bug in the compiler or stdlib
<FromGitter>
<wontruefree> also crenv works really well +1 to @pine work
<FromGitter>
<fusillicode_twitter> @bew ok I managed only now to get a little boiled down snippet of code that I think is the root of my problem
<FromGitter>
<jwoertink> I thought doing this would work, but I guess not.
<FromGitter>
<fusillicode_twitter> @jwoertink let me take a look :)
<FromGitter>
<jwoertink> I can't really do `Array(SomeHandler)` since I have no idea what names those handlers would be
<FromGitter>
<fusillicode_twitter> mmm
<FromGitter>
<fusillicode_twitter> I think that the problem may be the fact that you're trying to pass something "general" to something that accept something more "specific"
<FromGitter>
<fusillicode_twitter> shouldn't be the other way around?
<FromGitter>
<fusillicode_twitter> (but sincerely I'm not sure at all...it seems something similar to contra/covariance in Scala 🤔)
<z64>
`App.new([SomeHandler.new] of HTTP::Handler)` will compile
<FromGitter>
<jwoertink> Well, I want my array to be an array of any class that includes that module
<FromGitter>
<jwoertink> oh.. interesting. let me try that
<FromGitter>
<jwoertink> Ok, that's awesome that it works that way, but now the big question is, how can I do this without forcing the user to have to do that?
<FromGitter>
<fusillicode_twitter> I recall I read it somewhere inside the Crystal book but I didn't find it a second ago when I searched for it
<FromGitter>
<jwoertink> So the `App.new` part would be user interface, and the rest would be the underlying lib. I would have to tell the user that they would need to add the `of HTTP::Handler` part (not a horrible deal, just not as clean)
<FromGitter>
<jwoertink> and also, why does it work if I pass that array directly in to `HTTP::Server.new` which has the same signature?
<FromGitter>
<jwoertink> `HTTP::Server.new([SomeHandler.new])` works, but `App.new([SomeHandler.new])` doesn't 😕
<z64>
@jwoertink i recommend readind the source for HTTP::Server; its different from what you are doing. it has an intermediate `def self.new` that takes the array, uses a helper method to internally chain the middleware with each other, and only stores the *first* middelware
<FromGitter>
<jwoertink> Yeah, I was looking at the source just now. I'm gonna have to rethink this for sure
<FromGitter>
<jwoertink> ok, if I pass it around as a local variable and don't add the type, then it all works
<FromGitter>
<jwoertink> so finicky, but close enough for government work
<FromGitter>
<rishavs> Any chance of making a minor release of Crystal-db? Would be nice to get some of the fixes which have gone in.
<oprypin>
i thought it might have been a case of class<->instance method mismatch, but no https://carc.in/#/r/5gj8
<FromGitter>
<straight-shoota> Yeah, I guess `responds_to?` should work with constants directly. But it doesn't currently. A workaround is to assign it to a local var.
<FromGitter>
<vladfaust> Should I be OK with the macro? I mean that later definition stuff
<FromGitter>
<vladfaust> Wrapped into `finished` for sure
<oprypin>
well it's a runtime check around a supposed compile error
<FromGitter>
<vladfaust> Or is it? :)
<oprypin>
oh right, A.g() is a compile error, a.g() isn't
<FromGitter>
<straight-shoota> `responds_to?` is compile time like `is_a?`. It effectively restricts the type.
<oprypin>
that's the trick, and not the fact that it "makes responds_to? work"
<oprypin>
it works anyway, just that you cant compile the condition body without circumventing the compile error
<FromGitter>
<straight-shoota> yeah well, but with constants it could restrict the type of the constant directly without assigning it to a local var. At least theoretically.
<FromGitter>
<straight-shoota> Not sure if that's practical.
<oprypin>
if you write A.f() and f() doesnt exist, it doesnt matter at all what responds_to? does
<oprypin>
vladfaust, anyhow, seems like you're looking for a compile time check, so you should indeed prefer to use macros like you showed
<FromGitter>
<vladfaust> Yup, looks like
<FromGitter>
<vladfaust> Macros aren't bad
<oprypin>
responds_to? is for dynamically typed values
<oprypin>
hm that's not the right term
<oprypin>
"polymorphic values", i guess
<FromGitter>
<straight-shoota> I don't think there is anything wrong with `(a = A).responds_to?`
<FromGitter>
<straight-shoota> but, yeah `{% A.has_method? %}` can be used similarly
<FromGitter>
<vladfaust> > I don't think there is anything wrong with `(a = A).responds_to?` ⏎ ⏎ It's definitely wrong if we speak about convenience, quality of a developers life and adoption
<oprypin>
straight-shoota, i'm not sure if you're correct in saying that `responds_to?` is compile time. I'm sure that it has a runtime component, and I'm guessing that it can't not have at least some runtime part in all cases
<FromGitter>
<vladfaust> I judge a language by the level of expectations matching aka intuitivity. `A.responds_to?` *is* intuitive and expected
<FromGitter>
<straight-shoota> I'm pretty sure the type restrictions like `responds_to?` and `is_a?` are completely removed from codegen if it can't be satisfied by any of the static types
<oprypin>
vladfaust, the way you're using the language in this case is not intuitive, so this is a natural consequence
<oprypin>
why would you not know whether an exact class does or does not have a method?
<FromGitter>
<vladfaust> Oh, that's too complex :)
<oprypin>
yes, it certainly is
<FromGitter>
<straight-shoota> The compiler knows all types a value can possibly have. `responds_to?` and `is_a?` filter out only the matching types.
<FromGitter>
<vladfaust> @straight-shoota, when is `responds_to?` assessed? I mean, sometimes the object is required later in the code
<FromGitter>
<vladfaust> I'm worrying about difference with macro approach
<FromGitter>
<vladfaust> I.e. `{% Foo.has_method?("bar") %}` could return false in some situations, e.g. when "bar" is defined in another macro
<FromGitter>
<vladfaust> Is `responds_to?` more reliable in this case?
<FromGitter>
<vladfaust> I guess I have to test it myself, right
<FromGitter>
<straight-shoota> `Foo.has_method?("bar")` should only be `true` when this method is actually defined as a method on `Foo` (class method).
<oprypin>
straight-shoota, you're right.
<FromGitter>
<straight-shoota> Yeah, I looked at codegen
<FromGitter>
<jwoertink> > On macOS, SO_REUSEPORT is only for hot swapover, so when socket is closed it goes to next process.
<FromGitter>
<jwoertink> well, that answers that
<FromGitter>
<asterite> Instance var information is only available inside methods. At the top level you never know when more instance vars are going to be added, and the compiler keeps them all and eventually solves them in one go considering all the type hierarchy
<FromGitter>
<bew> removing the include gives a compile error
<FromGitter>
<j8r> yes
<FromGitter>
<bew> maybe some `new`-related magic
<FromGitter>
<j8r> thanks @bew extend do what I want :)
<oprypin>
regarding the "type-theory-smartness reason why class methods cant be imported": `extend` ensures that `SomeClass.is_a? SomeModule`, and `include` ensures that `SomeClass.new.is_a? SomeModule` - and I suppose that class methods don't affect this definition in any way so they're ignored :p
<FromGitter>
<bew> oh that's interesting
<FromGitter>
<bew> is it from Cr docs?
<oprypin>
i wish
<FromGitter>
<bew> please add it !!
<FromGitter>
<j8r> hum extend is weird
<oprypin>
very much so
<oprypin>
i think the inspiration is from some post that @jhass made on github a long time ago. what was that?
<oprypin>
can't find it. the post tried to generalize this notion of inheritance across classes and modules -- and also generics, I think
<FromGitter>
<bajro17> how to append text in file is there any example