jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.28.0 | 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
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
<FromGitter> <dscottboggs_gitlab> what gives? https://carc.in/#/r/6xnx/
<FromGitter> <Blacksmoke16> what about it?
<FromGitter> <Blacksmoke16> it can only be a string
laaron has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> 1 -- when I started using crystal a variable had a type and stuck to it. When you wanted a non-nil value, you reassigned it. When did it change? ⏎ 2 -- how to create a variable whose type is *actually* `String | Nil` for testing purposes?
<FromGitter> <Blacksmoke16> `something = "foo" || nil`
<FromGitter> <dscottboggs_gitlab> but that (like my example) can only be a string
<FromGitter> <dscottboggs_gitlab> https://carc.in/#/r/6xo2
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <dscottboggs_gitlab> I must've been wrong about how nullable variables work from the get-go
<FromGitter> <Blacksmoke16> i think the problem here is `.class` is returning the class of the var
<FromGitter> <Blacksmoke16> not the possible types
<FromGitter> <dscottboggs_gitlab> oh
<FromGitter> <Blacksmoke16> i.e. a var cant be more than one class at once
<FromGitter> <Blacksmoke16> https://carc.in/#/r/6xoa
<FromGitter> <dscottboggs_gitlab> Damn it! https://carc.in/#/r/6xoc
<FromGitter> <dscottboggs_gitlab> oh well at least I have something that works with consistency
<FromGitter> <Blacksmoke16> well in that case yea, it can only ever be a string
<FromGitter> <dscottboggs_gitlab> but I've restricted the type to `String | Nil`
<FromGitter> <Blacksmoke16> that that var could take
<FromGitter> <Blacksmoke16> not what it currently is
<FromGitter> <dscottboggs_gitlab> like I expect that when I declare a variable as `String?` that on some level it's a `String | Nil` union. Idk
<FromGitter> <dscottboggs_gitlab> specs pass
<FromGitter> <Blacksmoke16> but its not a union, its a limitation of the types a var could hold, it would be a union of the possible types it *could*be was string or nil
<FromGitter> <Blacksmoke16> but in this case it can only ever be a string so thats its type
<FromGitter> <dscottboggs_gitlab> but I want to be able to declare a variable of a particular type and have it stick? Like that seems like it should be a basic feature
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <dscottboggs_gitlab> idk it's probably just a side-effect of trying to not have the compiler take up GB of memory trying to instantiate everything as unions of any type available
<FromGitter> <Blacksmoke16> ye prob
<FromGitter> <Blacksmoke16> could just do what i did tho, `var = "string" || nil || 1` etc
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <dscottboggs_gitlab> yeah that's what I did
<FromGitter> <dscottboggs_gitlab> but that really seems like a hack to me... like "string" is truthy, so it can't ever get past that point
<FromGitter> <Blacksmoke16> dunno
alexherbo2508 has joined #crystal-lang
<FromGitter> <Blacksmoke16> now, any ideas on how to pass an empty tuple as a generic type? :P
<FromGitter> <dscottboggs_gitlab> like what if they decide to optimize that away in a few versions?
<FromGitter> <dscottboggs_gitlab> Uh...`Tuple(Nil)`?
<FromGitter> <Blacksmoke16> but its not empty
<FromGitter> <dscottboggs_gitlab> fufck
<FromGitter> <dscottboggs_gitlab> `Tuple()`?
alexherbo250 has quit [Ping timeout: 246 seconds]
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6xoe
<FromGitter> <dscottboggs_gitlab> yeah of course
<FromGitter> <dscottboggs_gitlab> https://play.crystal-lang.org/#/r/6xof ?
<FromGitter> <Blacksmoke16> not empty tho
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cdf51a8509b1035c7689e6e]
<FromGitter> <Blacksmoke16> trying to splat from a tuple, so if tuple has args it breaks thinking its going to new up a class with args it doesnt need
<FromGitter> <dscottboggs_gitlab> could you just...not specify a type?
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <Blacksmoke16> `wrong number of type vars for Athena::DI::ServiceDefinition(ServiceKlass, AnnotationArgs, ServiceArgs) (given 1, expected 3)`
<FromGitter> <dscottboggs_gitlab> could you give some context? also I'm kinda tired and you might get a better answer out of me in the morning
<FromGitter> <Blacksmoke16> sure sec
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cdf530a509b1035c768a8a0]
<FromGitter> <dscottboggs_gitlab> oh shit I think I get where you're going with this
<FromGitter> <Blacksmoke16> im storing a tuple of the args for an initializer, then storing the args from the annotation in an array
<FromGitter> <Blacksmoke16> then after resolving `@some_service` to an instance to `Foo`, trying to new up a `Store` class
<FromGitter> <dscottboggs_gitlab> yeah I don't have a clue lol
<FromGitter> <Blacksmoke16> works if there are args
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> maybe i could new up ones without args beforehand
<FromGitter> <Blacksmoke16> so they never reach this
<FromGitter> <Blacksmoke16> that would prob do it
<FromGitter> <Blacksmoke16> yea that would do it
<FromGitter> <dscottboggs_gitlab> you got it??
<FromGitter> <Blacksmoke16> in theory
<FromGitter> <Blacksmoke16> playing a game atm, ill let you know :P
<FromGitter> <dscottboggs_gitlab> cool :D
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cdf60e79404bf2aed659cc4]
<FromGitter> <Blacksmoke16> seems to do the trick
<FromGitter> <Blacksmoke16> @dscottboggs_gitlab ^
<FromGitter> <dscottboggs_gitlab> nice :)
<FromGitter> <Blacksmoke16> this has proved to be quite a challenging problem
<FromGitter> <dscottboggs_gitlab> indeed. From what I've heard, DI usually is
<FromGitter> <dscottboggs_gitlab> especially for statically-typed systems
<FromGitter> <Blacksmoke16> tell me about it :p
<FromGitter> <dscottboggs_gitlab> heh
* FromGitter * dscottboggs_gitlab is hitting the hay ✌️
<FromGitter> <Blacksmoke16> third time refactoring this, getting closer i feel
<FromGitter> <Blacksmoke16> o/ night
<FromGitter> <Blacksmoke16> nope, looks like the tuple from doesnt work when the array is a union with another array
<FromGitter> <Blacksmoke16> well no, its thinking there is a type union within my clas
_whitelogger has joined #crystal-lang
<FromGitter> <watzon> I need something that's the opposite of `File.expand_path`. I want to just get the part of the path that's different, or return `nil` if the path doesn't match at all.
<FromGitter> <watzon> So `File.method("/documentation/button", "/documentation")` should just return `"/documentation"`
<FromGitter> <watzon> Does that exist? Or will I need to write it myself? I'm not finding anything.
return0e_ has joined #crystal-lang
return0e has quit [Ping timeout: 246 seconds]
<FromGitter> <watzon> Also, is anyone else having trouble signing in to https://crystal-ann.com on Firefox?
<FromGitter> <watzon> I'm getting a `SSL_ERROR_INTERNAL_ERROR_ALERT` error
<FromGitter> <watzon> Just happened on Chrome too actually
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <bew> @watzon why do you want a File method, you can just do `"/foo/bar".delete("/foo")` and get `"/bar" `
<FromGitter> <watzon> Lol my brain wasn't working. I guess that would work. It doesn't account for the possibility of `/foo/bar` having a trailing slash, but I don't think that's an issue in my case.
ashirase has quit [Ping timeout: 258 seconds]
ashirase has joined #crystal-lang
devil_tux has quit [Ping timeout: 258 seconds]
<FromGitter> <r00ster91> @watzon same with Firefox. It works with Edge though
DTZUZO has quit [Ping timeout: 244 seconds]
laaron- has joined #crystal-lang
<FromGitter> <watzon> Big surprise, Edge let's security issues slide lol
laaron has quit [Ping timeout: 256 seconds]
alexherbo25086 has joined #crystal-lang
alexherbo2508 has quit [Ping timeout: 255 seconds]
alexherbo25086 has quit [Quit: The Lounge - https://thelounge.chat]
alexherbo2 has joined #crystal-lang
DTZUZO has joined #crystal-lang
_whitelogger has joined #crystal-lang
JuanMiguel has joined #crystal-lang
<FromGitter> <Blacksmoke16> @dscottboggs_gitlab https://play.crystal-lang.org/#/r/6xru is a small sample of what im getting :/
<FromGitter> <Blacksmoke16> if anyone has any ideas ^
<FromGitter> <dscottboggs_gitlab> you can't splat an array? or is it ok because it's a `Macro::ArrayLiteral`?
<FromGitter> <Blacksmoke16> `*ServiceArgs.from args` Service args is a tuple
early has quit [Quit: Leaving]
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.28.0/Tuple.html#from%28array%3AArray%29%3Aself-class-method
<FromGitter> <pynixwang> any macro to infer method return type?
<FromGitter> <Blacksmoke16> can use a macro to get return type of a method yea
<FromGitter> <pynixwang> what?
<FromGitter> <Blacksmoke16> like uhh `@type.methods[0].return_type}}`
<FromGitter> <Blacksmoke16> ofc could find/iterate over them all if you wanted
<FromGitter> <Blacksmoke16> i also tried massing in the services hash, and building out args array from within the record, but same thing
early has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> Yeah Idk i gotta go work on my bike
<FromGitter> <Blacksmoke16> okey dokey, have fun :p
<FromGitter> <pynixwang> use abc to define a rpc interface and use method sig to generate a rpc client. is this possible?
<FromGitter> <Blacksmoke16> idk what that is, but maybe?
<FromGitter> <pynixwang> something like java proxy?
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <pynixwang> using method_missing to override abm?
JuanMiguel has quit [Quit: This computer has gone to sleep]
<FromGitter> <pynixwang> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ce01fd39404bf2aed6a712d]
<FromGitter> <pynixwang> how to rebuild method.
<FromGitter> <pynixwang> ```code paste, see link``` ⏎ ⏎ basic works, someone interested on this? [https://gitter.im/crystal-lang/crystal?at=5ce0221983ae782aee8d3065]
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
<FromGitter> <pynixwang> Def has no `abstract?` method
<FromGitter> <pynixwang> include a module get many methods, they are override by this
<FromGitter> <Blacksmoke16> hmm, might be something that is missing
<FromGitter> <pynixwang> can not get this into a module.
<FromGitter> <pynixwang> ```code paste, see link``` ⏎ ⏎ I want this [https://gitter.im/crystal-lang/crystal?at=5ce026e3509b1035c76e18c2]
<FromGitter> <Blacksmoke16> whats the point of the module?
<FromGitter> <pynixwang> common use?
<FromGitter> <Blacksmoke16> if you just want to define methods from the parent class, wouldnt inheritance handle that for you w/o macro code
<FromGitter> <pynixwang> make RpcInterface common use
<FromGitter> <Blacksmoke16> sorry i dont follow
<FromGitter> <pynixwang> eg a json rpc
<FromGitter> <pynixwang> implement java dynamic proxy?
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <pynixwang> make a clean code
<FromGitter> <pynixwang> this can be done by pass return type as an arg, but not clean enough.
<FromGitter> <pynixwang> @Blacksmoke16 not just define methods
<FromGitter> <Blacksmoke16> ok
<FromGitter> <pynixwang> ```code paste, see link``` ⏎ ⏎ include module get many methods and get overrided. [https://gitter.im/crystal-lang/crystal?at=5ce02cbe0ac9852a95fcfe5b]
<FromGitter> <dscottboggs_gitlab> ... https://carc.in/#/r/6xs1 ?
<FromGitter> <pynixwang> no args given
<FromGitter> <pynixwang> initialize can not be overload?
<FromGitter> <dscottboggs_gitlab> I mean...in every other class I've defined it can...?
<FromGitter> <pynixwang> ```code paste, see link``` ⏎ ⏎ move include to Implement class OK [https://gitter.im/crystal-lang/crystal?at=5ce02eb4ad024978c6ea6873]
<FromGitter> <pynixwang> not need inherited macro
<FromGitter> <dscottboggs_gitlab> I can't do a `self.new` either... which makes sense
<FromGitter> <dscottboggs_gitlab> I guess I could just name that method something different
JuanMiguel has joined #crystal-lang
<FromGitter> <pynixwang> new is class method
<FromGitter> <dscottboggs_gitlab> mmhmm
<FromGitter> <pynixwang> `key = nil` and remove first `initialize`
<FromGitter> <dscottboggs_gitlab> and the rest of it doesn't work anyway. I'll have to come back to it later ✌️
<FromGitter> <dscottboggs_gitlab> no key can't be nil
<FromGitter> <mwlang> Are there any examples of more complex use cases for HTTP::Client? For example, if I want to do anything like Faraday's middleware to inject additional parameters into REQUESTs....in the case of communicating with Binance API, some endpoints are public and some must be signed. The signed endpoints in the Ruby gem implements Faraday Middleware like this: ⏎ ⏎ ```code paste, see link```
<FromGitter> <mwlang> That in turn gets used in constructing the connection: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ce03306ad024978c6ea8762]
<FromGitter> <pynixwang> before_request ?
<FromGitter> <mwlang> Is that a callback hook?
<FromGitter> <pynixwang> yes
<FromGitter> <pynixwang> like before_action?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.28.0/HTTP/Client.html#before_request%28%26callback%3AHTTP%3A%3ARequest-%3E%29-instance-method
<FromGitter> <mwlang> Oh, yeah, this will fill the role needed here.
<FromGitter> <mwlang> can more than one before_request hook be defined?
<FromGitter> <Blacksmoke16> `Any number of callbacks can be added.`
<FromGitter> <mwlang> ok, good. I have to say, attempting to write a shard library is pushing me to learn a lot further than I expected.
<FromGitter> <pynixwang> just mute the request object
<FromGitter> <mwlang> huh? "just mute"...?
<FromGitter> <pynixwang> hooks
<FromGitter> <mwlang> ok, I see see how to transform this Ruby and Faraday logic to Crystal.
<FromGitter> <pynixwang> see see
<FromGitter> <mwlang> another thing, how to write specs. I don't want to hit the Binance api server every time.
<FromGitter> <pynixwang> you chinese?
<FromGitter> <mwlang> LMAO
<FromGitter> <pynixwang> stub?
<FromGitter> <mwlang> nah, I just big gulped some strong coffee
<FromGitter> <pynixwang> mock
<FromGitter> <Blacksmoke16> https://github.com/manastech/webmock.cr
JuanMiguel has quit [Quit: This computer has gone to sleep]
<FromGitter> <mwlang> perfect!
<FromGitter> <mwlang> So I put ```require "webmock"``` into spec_helper.cr, right?
<FromGitter> <Blacksmoke16> i guess?
<FromGitter> <pynixwang> maybe.
<FromGitter> <mwlang> can webmock capture a real server exchange and turn it into a stub or do I need to do all that manually?
<FromGitter> <Blacksmoke16> dunno, never used it
<FromGitter> <pynixwang> ..
<FromGitter> <pynixwang> ```code paste, see link``` ⏎ ⏎ POC [https://gitter.im/crystal-lang/crystal?at=5ce041d56366992a94deafe5]
<FromGitter> <pynixwang> method args need some effort.
<FromGitter> <Blacksmoke16> if im newing up a class with an IO like `File.open("path.log")`, do i have to explicitly close the io, or does that get handled for me at some point?
<FromGitter> <pynixwang> block may close for you
<FromGitter> <Blacksmoke16> but if im not using a block
<FromGitter> <pynixwang> or a gc finalize hook?
<FromGitter> <Blacksmoke16> could work
<FromGitter> <pynixwang> no try
<FromGitter> <Blacksmoke16> but what would happen if it never gets GC?
<FromGitter> <Blacksmoke16> i.e. short lived program or something
<FromGitter> <pynixwang> os will close for you when program exit
<FromGitter> <pynixwang> maybe
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <pynixwang> 。。
<FromGitter> <pynixwang> emmmm?
<FromGitter> <Blacksmoke16> ill just go with it for now
<FromGitter> <Blacksmoke16> https://github.com/crystal-lang/crystal/issues/3793#issuecomment-269537600 seems to imply that OS handles it so works for me
gangstacat has quit [Ping timeout: 248 seconds]
gangstacat has joined #crystal-lang
<FromGitter> <bararchy> How would I return early in a Fiber inside a block? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ce0500c0aa0de56018520db]
<FromGitter> <pynixwang> next?
<FromGitter> <bararchy> Will that break Fiber but wont effect the block outside ?
<FromGitter> <bararchy> I just want to stop the execution of the Fiber
<FromGitter> <pynixwang> you can spawn a fun
notdaniel has joined #crystal-lang
gangstacat has quit [Quit: Ĝis!]
<FromGitter> <mwlang> @bararchy Check out this play from @z64 yesterday...He showed me how to break out of a loop in a spawned block and continue to do stuff in the main loop: https://play.crystal-lang.org/#/r/6xlw
<FromGitter> <mwlang> in your case, something like ```break if condition``` would be the line to get you out of the block you spawned.
<FromGitter> <bararchy> @mwlang thanks :)
<FromGitter> <bararchy> There is a way to increase the BohemGC heap size right? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ce0550b5627560164121f7b]
laaron- has quit [Remote host closed the connection]
notdaniel has quit [Remote host closed the connection]
notdaniel has joined #crystal-lang
_whitelogger has joined #crystal-lang
gangstacat has joined #crystal-lang
<FromGitter> <Blacksmoke16> what happens to a file that is opened in a struct?
<FromGitter> <Blacksmoke16> since you cant add a finalize method, im assuming it just stays open till the program exists?
<FromGitter> <Blacksmoke16> or unless explicitly closed within the struct
<FromGitter> <Daniel-Worrall> I'm getting a `No address found for irc.chat.twitch.tv:6667 over TCP` on alpine but not ubuntu WSL :thinking:
<FromGitter> <Blacksmoke16> Missing dependency?
<FromGitter> <dscottboggs_gitlab> The DNS settings between Alpine and Ubuntu are sure to widely vary
<FromGitter> <dscottboggs_gitlab> what happens if you `curl` or `nmap` those hostnames from either system
<FromGitter> <Daniel-Worrall> It's no longer not working which can be worrying. I'm going through static linking on alpine problems
<FromGitter> <dscottboggs_gitlab> yes alpine can be difficult -- it's significantly different from other linuxes
_whitelogger has joined #crystal-lang
<FromGitter> <Daniel-Worrall> It has some open issues in crystal. I just got it working by sticking `require "llvm"` in the main file
<FromGitter> <dscottboggs_gitlab> wtf
<FromGitter> <Daniel-Worrall> Jup.
<FromGitter> <Daniel-Worrall> > it affects all programs statically linked with musl-libc
<FromGitter> <dscottboggs_gitlab> oh boyh
<FromGitter> <dscottboggs_gitlab> so um
<FromGitter> <dscottboggs_gitlab> but I feel like you might be way ahead of me
<FromGitter> <Daniel-Worrall> yeah, I got the address thing working
<FromGitter> <Daniel-Worrall> ignore that error
<FromGitter> <Daniel-Worrall> I was getting invalid mems and segfaults
<FromGitter> <Daniel-Worrall> I think my problem was I copied the wrong build file
JuanMiguel has joined #crystal-lang
JuanMiguel has quit [Quit: This computer has gone to sleep]
DTZUZO has quit [Ping timeout: 246 seconds]