ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.31.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<hightower2> ehm, yes when block is passed as argument to macro(), but no otherwise...
<FromGitter> <Blacksmoke16> hmm
<hightower2> actually I got it working, seems that the -> Nil did work after all
<FromGitter> <Blacksmoke16> ah nice one
<hightower2> So now I have block working, and handler = Event::Handler.new {|x|...} working.
<hightower2> One thing which doesn't work is the ->(e : ClickedEvent) { ... } notation, which requires the block to exit with nil
<hightower2> Looking into that now
snsei has quit [Ping timeout: 250 seconds]
<hightower2> And Proc(ClickedEvent, Nil).new { |e| ... } also works
<hightower2> Docs say that in the case of ->(){} return type is inferred from the body, which isn't ideal
<hightower2> By the way, is there any difference between Nil and Void return type?
<FromGitter> <Blacksmoke16> not really
<hightower2> great
<hightower2> Still perplexed by the ->(){}, not sure why in Proc(Event,Nil).new the return value would be ignored, but in ->(){} wouldn't.
<hightower2> or rather,
<hightower2> why when passing a block defined as Event -> Nil it is ignored regardless of what the block exits with and it matches the overload, while when passing a ->(){} for a Proc it isn't
<FromGitter> <watzon> Nice
<FromGitter> <Blacksmoke16> :shrug:
<hightower2> The second and third example both hit the same overload
<hightower2> but one works, the other one doesn't
<FromGitter> <Blacksmoke16> when you make a playground link, can you make it so it shows the behavior?
<hightower2> The function is def on( type : ..., handler : Proc({{e.id}}, Nil), ... )
<hightower2> sure I think I could extract it
<FromGitter> <Blacksmoke16> prob could just define a class with a proc typed ivar?
<FromGitter> <Blacksmoke16> `p` returns the obj
<hightower2> yes that's not the problem, or rather that's exactly what I wanted to show
<FromGitter> <Blacksmoke16> so in reality the return value of the proc is `Int32` implicitly
<hightower2> no no, yes
<hightower2> I mean to show that the first two variants, which don't return Nil (they return what p returns), do get their return value ignored and replaced with Nil
<hightower2> whereas the third example does not, it remains being inferred as Proc(Int32,Int32), and fails to match the on() overload
<FromGitter> <Blacksmoke16> well the first one is explicitly setting its return type to `Nil` in the proc type def
<FromGitter> <Blacksmoke16> the second is returning nil so its return type is inferred to be `Nil`
<FromGitter> <Blacksmoke16> not sure i see the issue?
<hightower2> Well, yes, right, I meant to show the difference between the third example and the behavior of a block
<hightower2> Let me do that
<hightower2> Case 3 and 4 are comparable, that's what I wanted to show originally
<hightower2> both don't return a nil, but block version works, while the ->(){} one doesn't
<FromGitter> <Blacksmoke16> heres what i think is going on
<FromGitter> <Blacksmoke16> first example explicitly setting its return type to Nil in the proc type def
<FromGitter> <Blacksmoke16> second is returning nil so its return type is inferred to be Nil
<FromGitter> <Blacksmoke16> third is using the block overload of `on` which explicitly says the return type is `Nil`, similar to the first one
<hightower2> right
<FromGitter> <Blacksmoke16> the fourth example is using the non block overload which requires the passed proc to have a return type of `Nil`, but it has a return type of `Int32` so it isnt compatible, thus errors saying there isnt an overload for the proc
<hightower2> yes, but go back to the third example.. this block doesn't return a Nil, yet it does match the overload which says that Block is of type Int32 -> Nil
<hightower2> Whereas that same situation, but with overload 1 and Proc, doesn't work
<FromGitter> <Blacksmoke16> the `Nil` return type is defined in the type restriction of the block `&handler : Int32 -> Nil) āŽ `
<FromGitter> <Blacksmoke16> which is similar to the first example
<hightower2> Yes, agreed. Let me change the order of examples in that paste:
teardown has joined #crystal-lang
<FromGitter> <Blacksmoke16> they're not the same tho
<FromGitter> <Blacksmoke16> first is saying this method must be called with a block, while the 2nd is just restricting the type of a passed in proc
<hightower2> yes. But the point I'm trying to make is, the block doesn't return Nil, yet crystal thinks it fits the requirement of Int32 -> Nil
<hightower2> Whereas in the second case, the Proc also doesn't return nil, but crystal does not think it fits the requirement of Int32 -> Nil
<FromGitter> <Blacksmoke16> im pretty sure its doing https://crystal-lang.org/reference/syntax_and_semantics/return_types.html#nil-return-type but for the block
<FromGitter> <Blacksmoke16> which doesn't happen for a proc unless you give it the return type
<hightower2> yes, yes, agreed on all of that. But I mean, block does not return Nil, yet his return type is overriden by the overload which says that block is "Int32 -> Nil"
<hightower2> Whereas when Proc doesn't return nil, its return type is not overriden by the overload which says Proc(Int32,Nil)
<hightower2> So it looks like not blocks, but procs defined with ->(){} notation, will be the edge case where specifying "nil" at the end is required...
<FromGitter> <Blacksmoke16> im 99% sure both wouldn't work if you used a return type other than Nil
<hightower2> Sure, fully agree on that. We're talking about the behavior of Nil
<FromGitter> <Blacksmoke16> maybe someone else can explain it better but im quite certain its just special behavior with declared `Nil` return type so that you don't have to add a new line with just `nil` on it
<FromGitter> <Blacksmoke16> but im just not seeing the problem you're describing :/
<FromGitter> <Blacksmoke16> > but procs defined with ->(){} notation, will be the edge case where specifying "nil" at the end is required... āŽ āŽ ah i think i see
<FromGitter> <Blacksmoke16> the main difference there is the return type is specified to be `Nil` so its inferred from the body, which if you dont explicitly say it returns nil, it wont do the special nil case for you
<FromGitter> <Blacksmoke16> isn't specified*
<FromGitter> <Blacksmoke16> afaik there isnt anything you can do there
<hightower2> Yeah, other than using Proc(Int32,Nil) { |num| p num }; that works, as well as creating an alias for Proc(Int32,Nil)...
<hightower2> but still I am very puzzled by why it works with blocks and not with procs defined with ->(){}
<FromGitter> <Blacksmoke16> because the former has an explicit return type while the latter is inferred
<hightower2> Ok, will let what you said sink for a couple days, as right now I don't understand it
<FromGitter> <Blacksmoke16> Another way to think of it be like two methods
<FromGitter> <Blacksmoke16> One that has a return type of a specific type
<hightower2> Where do you say is this specific return type? In the definition of the overload, or in the definition of the block/proc?
<FromGitter> <Blacksmoke16> Like`def foo : Int32` vs `def foo`
<hightower2> Right. In our case, the block type is: &handler : Int32 -> Nil, and Proc type is: Proc(Int32, Nil). Doesn't this make both of them have specific return type?
<hightower2> (the Nil-magic one)
<FromGitter> <Blacksmoke16> no, for the same reason why https://play.crystal-lang.org/#/r/829e doesnt work
<FromGitter> <Blacksmoke16> the latter proc type is just a restriction, while the block type restriction is more similar to a method return type like `foo : Nil`
<FromGitter> <Blacksmoke16> proc type is just an argument type restriction*
<hightower2> ah ok, ok all clear now... hence your comment that there's not much what can be done about it
<FromGitter> <Blacksmoke16> could make a macro that defines the proc
<hightower2> yes, yes, I do have Proc(Int32,Nil) option, and alias Handler = Proc(Int32,Nil), both of those work
<FromGitter> <Blacksmoke16> šŸ‘
<hightower2> I was trying to get ->(){} to work without needing an explicit nil, but obviously no-go
<FromGitter> <Blacksmoke16> yea
<FromGitter> <Blacksmoke16> trying to figure out a bug i found
<FromGitter> <Blacksmoke16> `Athena::EventDispatcher::EventListener(@listener=, @priority=99)`
<FromGitter> <Blacksmoke16> looks like the listener proc isnt being set?
<FromGitter> <Blacksmoke16> oh boy, you'll like this one
<FromGitter> <Blacksmoke16> ill have to try and reduce, but it was because i didnt explicitly return `nil`in my proc ha
<hightower2> haha
<FromGitter> <Blacksmoke16> apparently it like silently didnt set the ivar or something? :shrug:
<FromGitter> <Blacksmoke16> think its pretty much done
<FromGitter> <Blacksmoke16> going to work on integrating it into Athena now, so will see if i find any bugs or improvements
<FromGitter> <Blacksmoke16> oo need to make an example for the api docs
<hightower2> Cool! Really excited about that project
<hightower2> (Athena as a whole)
<FromGitter> <Blacksmoke16> Thanks, still a ways to go. Got some refactoring to do
snsei has joined #crystal-lang
<FromGitter> <Blacksmoke16> plus a lot of design decisions to make still :/
<hightower2> @Daniel-Worrall: I made the handlers return Nil now, and documented how to get return value in the Event itself if necessary
<hightower2> released v0.11.0, https://github.com/crystallabs/event_handler
snsei has quit [Ping timeout: 240 seconds]
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 265 seconds]
kotrcka has joined #crystal-lang
snsei has joined #crystal-lang
ur5us__ has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
ur5us__ has quit [Ping timeout: 245 seconds]
kotrcka has left #crystal-lang [#crystal-lang]
return0e_ has joined #crystal-lang
return0e has quit [Ping timeout: 265 seconds]
snsei has joined #crystal-lang
<FromGitter> <firejox> @lbarasti The `close case` was not handled in `blocking select` in 0.31.1. And it fixed after #8304 .
<DeBot> https://github.com/crystal-lang/crystal/pull/8304 (Fix select with receive? and closed channels)
snsei has quit [Ping timeout: 276 seconds]
<FromGitter> <lbarasti> Thanks @firejox, looking forward to 0.32!
alexherbo2 has joined #crystal-lang
DTZUZO has quit [Ping timeout: 250 seconds]
ur5us__ has joined #crystal-lang
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 240 seconds]
snsei has joined #crystal-lang
ur5us__ has quit [Ping timeout: 245 seconds]
DTZUZO has joined #crystal-lang
<hightower2> Can I detect whether a macro is called in the context of a class or at toplevel?
snsei has quit [Ping timeout: 240 seconds]
dwdv has joined #crystal-lang
<hightower2> Can I create a method which keeps some variable outside of it in its scope? Kind of like a proc would do, but that it's created as a method with def, and not a proc
DTZUZO has quit [Ping timeout: 265 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 252 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 245 seconds]
<hightower2> Hey Blacksmoke16 , going through your article on creating JSON API with Athena. I see that you used a convention of Blog::Models and Blog::Controllers, which is great. However, why did you keep the "Controller" at the end instead of removing it? (Blog::Controllers::UserController <-- )
snsei has joined #crystal-lang
DTZUZO has joined #crystal-lang
<raz> oh come on... seriously. does the awesomeness ever stop? every time i go looking for a small utility shard (this time: to humanize numbers) i learn that crystal has it baked right in.
DTZUZO has quit [Ping timeout: 245 seconds]
<hightower2> Regarding my question above about recognizing whether macro is executing at top level, I'll try seeing what does @type say
<hightower2> Blacksmoke16 that Athena + JSON API article and article on annotations are great. When I get back to some web-related development I'll be interested in pairing Athena with GraphQL
snsei has quit [Ping timeout: 252 seconds]
DTZUZO has joined #crystal-lang
<hightower2> Hey where is the list of 3rd party Crystal shards which the manas/crystal team has in mind and verifies after every release?
<FromGitter> <j8r> Do you guys knows any health metric I can expose from a Crystal app? Maybe some related to the GC?
<raz> GC.stats is quite informative
<FromGitter> <Blacksmoke16> @phangs that should be fixed now
<FromGitter> <Blacksmoke16> hightower2: iirc you can make a macro protected?
<FromGitter> <Blacksmoke16> > *<hightower2>* Hey Blacksmoke16 , going through your article on creating JSON API with Athena. I see that you used a convention of Blog::Models and Blog::Controllers, which is great. However, why did you keep the "Controller" at the end instead of removing it? (Blog::Controllers::UserController <-- ) āŽ āŽ Probably just a habit, but yea it's unnecessary because of the namespace
<FromGitter> <Blacksmoke16> > *<hightower2>* Blacksmoke16 that Athena + JSON API article and article on annotations are great. When I get back to some web-related development I'll be interested in pairing Athena with GraphQL āŽ āŽ šŸ‘ sounds like a plan
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/82cu
<FromGitter> <Blacksmoke16> private* not protected
snsei has joined #crystal-lang
<FromGitter> <christopherzimmerman> @watzon hmm, Iā€™m surprised I never came across apatite. How far did you get with ND arrays?
<hightower2> Aha at toplevel, [[@type}} returns <Program> that's nice
<FromGitter> <j8r> hightower2: Ok for GC.stats, but what can be considered healthy and unhealthy?
<hightower2> (you meant it for @raz )
snsei has quit [Ping timeout: 246 seconds]
<hightower2> So many nice things coming in 0.32
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 240 seconds]
duane has quit [Ping timeout: 240 seconds]
duane has joined #crystal-lang
<jrayhawk> What's the easiest way to type-restrict a function argument down to two static strings? Something like def foo( x : "bar" | "baz" )
<FromGitter> <Blacksmoke16> an enum
<FromGitter> <tenebrousedge> good idea
<FromGitter> <Blacksmoke16> wouldnt be exactly what you want but its the best option
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ddab4261bf5192e669898f0]
<FromGitter> <Blacksmoke16> could override `to_s` if you want it to be some other format, as it would be like `"Bar"` atm
<FromGitter> <tenebrousedge> couldn't you do āŽ āŽ ```enum Option āŽ Bar = "bar"``` [https://gitter.im/crystal-lang/crystal?at=5ddab5ccb010e6227661657d]
<FromGitter> <Blacksmoke16> no
<FromGitter> <Blacksmoke16> enum values are `Int`
<FromGitter> <Blacksmoke16> would be nice tho
<FromGitter> <tenebrousedge> hmmm
* FromGitter * tenebrousedge pokes it with a stick
<FromGitter> <tenebrousedge> still nope :(
snsei has joined #crystal-lang
<jrayhawk> Huh, okay, thanks.
<FromGitter> <Blacksmoke16> well i guess the *easiest* option would just be like āŽ āŽ ```raise ArgumentError.new "x must be\"bar\" or \"baz\"" unless {"bar", "baz"}.includes? x``` [https://gitter.im/crystal-lang/crystal?at=5ddab8beb010e62276617f91]
<FromGitter> <Blacksmoke16> but ofc that would be a runtime error
<raz> how ruby'esque
* raz wiggles his monocle in disgust
<FromGitter> <Blacksmoke16> yea, so if you want a compile error it has to be an enum, or a unique type
<FromGitter> <tenebrousedge> you could use a constant?
<FromGitter> <Blacksmoke16> granted symbols are casted into enum members so you could do `:bar` vs `Option::Bar`
<FromGitter> <tenebrousedge> that's a thing too
<FromGitter> <tenebrousedge> dang, constants don't work either <__< Crystal, you are harshing my mellow
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
Human_G33k has joined #crystal-lang
HumanG33k has quit [Ping timeout: 240 seconds]
snsei has quit [Ping timeout: 252 seconds]
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
f1reflyylmao has quit [Remote host closed the connection]
f1refly has joined #crystal-lang
ua has quit [Ping timeout: 240 seconds]
ua has joined #crystal-lang
snsei has joined #crystal-lang
ur5us__ has joined #crystal-lang
ur5us__ has quit [Remote host closed the connection]
ur5us__ has joined #crystal-lang
ur5us__ has quit [Read error: Connection reset by peer]
ur5us has joined #crystal-lang
snsei has quit [Ping timeout: 246 seconds]
<FromGitter> <watzon> @christopherzimmerman I didn't really get anywhere with ndarrays. I implemented Matrices and Vectors based on Ruby's standard library implementations, but I didn't really need ndarrays for what I was working on.
ht_ has joined #crystal-lang
dingenskirchen has quit [Quit: dingenskirchen]
ht_ has quit [Quit: ht_]
snsei has joined #crystal-lang
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
alexherbo2 has joined #crystal-lang
<hightower2> Hey, I have class Event, and its subclass Subevent. Type Proc(Subevent,Nil) is not accepted into a method defined as accepting Proc(Event, Nil).
<hightower2> Remind me please, did we already discuss this and was the conclusion that otherwise it would work, but within Procs it doesn't?
<FromGitter> <Blacksmoke16> would have to have a wrapping proc
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
<hightower2> Although there must be more to it, because an isolated example seems to work:
<FromGitter> <Blacksmoke16> ah i think that would work, but not sure about if you try to do the call
<hightower2> indeed, doesn't work if .call is attempted
snsei has quit [Ping timeout: 240 seconds]
<hightower2> actually let me get this example in shape
<hightower2> https://play.crystal-lang.org/#/r/82er <-- I thought I had this case, but on play it works. I need to look more into the code to figure out what's different than this example
<hightower2> (note that in this case I don't need to .call() the proc, so that's why I didn't try .call in the example)
<hightower2> fg
<FromGitter> <christopherzimmerman> @watzon not sure if you looked into it, but it might be worth adding an option in the makefile to compile SOD against opencv, which would allow us to integrate. Also, thoughts on supporting video streams in library itself?
<FromGitter> <watzon> I'd be all for supporting video streams, I could see that being extremely useful. Anything that allows us to compete with some Python libraries out there
<FromGitter> <watzon> Do you have a reference to docs talking about compiling against opencv?
<FromGitter> <christopherzimmerman> https://sod.pixlab.io/api.html#cmpl_opencv
<FromGitter> <christopherzimmerman> The integration might be tricky, I haven't looked into at all, just remember seeing it was an option.
<FromGitter> <watzon> Ahh yeah, I did think about that, but it would probably be most useful if we had a working opencv wrapper for Crystal
<FromGitter> <watzon> Then we could provide an interface to that
<FromGitter> <christopherzimmerman> Good point. I'm not at all optimistic about that happening anytime soon. OpenCV is a mess to deal with.
<FromGitter> <christopherzimmerman> In the same vein, might be worth adding in support for the other compile-time directives.
alexherbo2 has joined #crystal-lang
<FromGitter> <watzon> Yeah I'm thinking specifically `SOD_ENABLE_NET_TRAIN`
<FromGitter> <watzon> I need to read about it though