jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.19.1 | Fund Crystals development: http://is.gd/X7PRtI | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
<crystal-gh> [crystal] kostya closed pull request #3287: add IO::Buffered#rewind_buffer (master...rewind_buffer) https://git.io/vi0Go
Ven_ has joined #crystal-lang
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 244 seconds]
akwiatkowski has joined #crystal-lang
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 244 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 260 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 276 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 265 seconds]
akwiatkowski has quit [Ping timeout: 244 seconds]
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 276 seconds]
pawnbox has joined #crystal-lang
Ven_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
pawnbox has quit [Ping timeout: 250 seconds]
pduncan has joined #crystal-lang
Philpax has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 276 seconds]
bjz has joined #crystal-lang
pduncan has quit [Ping timeout: 250 seconds]
pawnbox has joined #crystal-lang
balduin has left #crystal-lang [#crystal-lang]
pawnbox has quit [Ping timeout: 250 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 240 seconds]
vikaton has joined #crystal-lang
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 276 seconds]
pabs has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
willl has joined #crystal-lang
kulelu88 has quit [Quit: Leaving]
DeBot has joined #crystal-lang
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 265 seconds]
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 276 seconds]
Raimondi has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
bjz has quit [Client Quit]
leftylink has joined #crystal-lang
Philpax has quit [Ping timeout: 265 seconds]
tombruijn has joined #crystal-lang
<FromGitter> <anicholson> Hi everyone :)
<FromGitter> <cjgajard> hello :)
<FromGitter> <anicholson> I want to be able to pass a class as a parameter to a method (HTTP::Client, in my case) but I don't know how to get this past the type-checker. Is this something I should expect to be able to do?
<BlaXpirit> >> def a(c); c.new(6); end; a(Float32)
<DeBot> BlaXpirit: # => 6 - https://carc.in/#/r/193r
<BlaXpirit> anicholson, no problem at all
<BlaXpirit> though if you get specific with it, it means you can only pass that particular class and not subclasses
tombruijn has left #crystal-lang ["Leaving"]
<FromGitter> <anicholson> @BlacXpirit this is the sort of problem I'm running into: https://carc.in#/r/193t
soveran has joined #crystal-lang
pawnbox has joined #crystal-lang
<FromGitter> <anicholson> ^ the type-checker won't let me annotate the thing as `Class` (which == `typeof(HTTP::Client)`)
<BlaXpirit> anicholson, ah well you're running into the exact use case for generics, have you read about them?
<FromGitter> <anicholson> @BlaXpirit not for this use-case, no :)
<FromGitter> <anicholson> oh I get it
<FromGitter> <anicholson> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=57d50b5f83c1556511b9024c]
<FromGitter> <anicholson> ^ @BlaXpirit something like this?
Raimondi has joined #crystal-lang
<BlaXpirit> `@client = T.new` but yes
<FromGitter> <anicholson> but I don't _want_ a new T, I want to call methods on T directly!
<BlaXpirit> oh then that's ok too
<BlaXpirit> wait, you don't need an instance variable, what's the point
<BlaXpirit> just T.get ...
<BlaXpirit> i don't get why you even need a class then
<FromGitter> <anicholson> @BlaXpirit I'm wrapping an OAuth flow and wanted to be able to inject a different HTTP client for testing purposes
<FromGitter> <anicholson> and yeah, the `ivar` can go now
<FromGitter> <anicholson> I'm coming from Ruby-land, so my thought process for encoding knowledge comes from somewhere else
<BlaXpirit> i can see that
Raimondi has quit [Ping timeout: 240 seconds]
<FromGitter> <anicholson> aha, perfect
<FromGitter> <anicholson> thanks so much for the help, @BlaXpirit ! I wouldn't have gone to generics without your nudge :)
<FromGitter> <anicholson> gotta loosen that "everything is an object" mentality
<FromGitter> <cjgajard> little style thing... in https://carc.in/#/r/193t line 4 defines `@http_client` but in line 5 `http_client`is used instead, that is quite abusing of that syntax sugar...
<FromGitter> <anicholson> @cjgajard yeah, I was just bashing out a proof-of-concept, so very sloppy style ;)
_whitelogger has joined #crystal-lang
bjz has joined #crystal-lang
_whitelogger has joined #crystal-lang
akwiatkowski has joined #crystal-lang
aolko has joined #crystal-lang
sapphire_brb has quit [Ping timeout: 240 seconds]
_jaitaiwan has joined #crystal-lang
<_jaitaiwan> Sup guys... if I have a simple class which implements YAML.mapping, how can I get to_yaml to work with the class?
<RX14> YAML.mapping doesn't add to_yaml unfortunately
<RX14> yaml is quite hard to generate properly
soveran has quit [Remote host closed the connection]
<_jaitaiwan> @RX14 what about going through each instance variable and mapping to a hash? How would one go about that? I've tried a few things from ruby land but they don't seem to work
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has joined #crystal-lang
Raimondi has joined #crystal-lang
Philpax has joined #crystal-lang
<RX14> _jaitaiwan, you either write that manually or use macros
Raimondi has quit [Ping timeout: 240 seconds]
<_jaitaiwan> Is there some documentation or tutorials you can recommend? I'm at a loss as how to go about this. I've tried a few different methods to no avail
<RX14> there's the macro syntax docs, then the macro object docs
soveran has quit [Remote host closed the connection]
balduin has joined #crystal-lang
<balduin> why do I get typeof( variable) the following result: (String | Nil )?
<RX14> balduin, which variable?
<balduin> I have a variable which I expected to be a string, but it could also be null. However, through testing I made sure it is a string
<balduin> Nevertheless I get as result of typeof: (String | Nil )
<balduin> how can I ensure it is only String?
soveran has joined #crystal-lang
<RX14> balduin, well you can call .not_nil! on it which raises if it's nil, but depending on your code that might not be the best way to do it
<RX14> can you show me your code?
akwiatkowski has quit [Quit: Konversation terminated!]
akwiatkowski has joined #crystal-lang
akwiatkowski has quit [Ping timeout: 244 seconds]
<RX14> balduin, where's the Pipe class?
<RX14> i imagine the pull operation returns nil if there's nothing to pull
<RX14> or there's a coding error in pull which means it returns nil
<balduin> RX14: yes, the pull operation can return nil, but in this case I made sure that first_list and second_list is not null
<RX14> where did you make sure?
<balduin> but every time I want to do something like content = first_list + second_list I still get an 'Nil' error
<balduin> RX14 from a type perspective never, but through testing I know that first_list and second_list contain a string
<RX14> i can't get the whole picture because I don't have the whole code with every class you reference so the only thing I can suggest is calling not_nil! on the pull call
<balduin> @RX14: how would the 'not_nil!' look like?
<RX14> it's a method call
<RX14> on anything except nil it returns self
<RX14> on nil it raises
<RX14> @pip.pull.not_nil!
<RX14> s/pip/pipe/
<balduin> okay, thanks :-)
<balduin> that was exactly what I was looking for
<balduin> :-)
<balduin> thanks :-)
<_jaitaiwan> So I'm giving this macro thing a go... But I'm getting a syntax error and I can't for the life of me see why. Can I get a second pair of eyes please? http://pastebin.com/YkcgUcqG
Raimondi has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
<BlaXpirit> _jaitaiwan, the result of a top-level macro expression must be valid syntax
<BlaXpirit> just a: b, c: d by itself is not valid syntax
<BlaXpirit> so for a quick solution you should simply wrap the body of the method in {% begin %} {% end %}
qard_ has joined #crystal-lang
<_jaitaiwan> interesting thanks
<BlaXpirit> hm i need a way to get notifications for this channel, but in a way that doesnt ping for every single message
<_jaitaiwan> most irc ones allow you to ping with your username?
qard has quit [Ping timeout: 265 seconds]
<BlaXpirit> _jaitaiwan, well you needed help but of course you didn't mention me personally
<_jaitaiwan> BlaXpirit: True :)
soveran has quit [Remote host closed the connection]
<_jaitaiwan> BlaXpirit: Do you know why instance_vars would be empty here? https://play.crystal-lang.org/#/r/1956
<RX14> remove {% begin %} and end
triangles2 has quit [Quit: Leaving]
<RX14> the reason why is complicated
<RX14> but basically adding begin and end stops `def to_yaml2` from becoming a `macro def`
<RX14> normal macros don't have much access to type info because they run before the typing phase of the compiler
<RX14> macro defs run after
<RX14> @type confuses me
<_jaitaiwan> RX14: me too...
<RX14> you should make an issue on github asking for clarification from asterite because he probably knows what @type is set to where and why
<_jaitaiwan> Yeah
<_jaitaiwan> RX14 the hard part for me is that I'm trying to get the instance vars in a hash... but when I add a for loop to the same code above it crashes
<RX14> lol what
<BlaXpirit> RX14, it's simple what @type is
<BlaXpirit> it is the current type that the method is in, and applies only to macro def
<BlaXpirit> the only magical thing about @type is that it forces a macro def
<RX14> nope
<RX14> @type exists in normal macros too
<RX14> especially hook macros
<BlaXpirit> it cannot by definition
<RX14> "When a macro is invoked you can access the current scope, or type, with a special instance variable: @type. The type of this variable is TypeNode, which gives you access to type information at compile time.
<RX14> "
<RX14> Note that @type is always the instance type, even when the macro is invoked in a class method.
<RX14> from the docs
<BlaXpirit> so..?
<RX14> that implies it exists in normal macros
<BlaXpirit> > A def is implicitly considered a macro def when you use @type inside a macro expression inside it.
<RX14> yes
<RX14> both these staements can be true
<BlaXpirit> oh i should read better, you say normal macros, i thought about normal defs
<RX14> ...
<BlaXpirit> but it wasn't really relevant to the situation
<RX14> @type is weird
<BlaXpirit> in actual macros it is very weird
<RX14> exactly
<RX14> heh
<BlaXpirit> that's... educational
<RX14> and this is just weird
<BlaXpirit> nah it's normal
<RX14> it
<RX14> 's weird if you don't know how the compiler works
<_jaitaiwan> Yeah that's normal
<RX14> is there even a way to generate arbitrary code after typing?
<BlaXpirit> this is what I don't understand though https://carc.in/#/r/195w - i thought normal defs have their macros executed only once
<RX14> there's macro defs and no generic hook for after typing
<RX14> BlaXpirit, yeah but thats a different method
<RX14> inheritance is an illusion
<BlaXpirit> no,what's the point of macro def then?
<RX14> what?
<RX14> the point is to be able to access @type
<BlaXpirit> alrighty then.....
<RX14> i'm starting to dislike crystal for being a little too magic
<RX14> we're making the same mistakes as ruby by adding 1001 features
<RX14> then in 15 years, guess what they're lagacy cruft that nobody wants
<_jaitaiwan> Fair enough
<_jaitaiwan> Gents can you tell me why https://play.crystal-lang.org/#/r/1967 works but https://play.crystal-lang.org/#/r/1968 doesnt?
<_jaitaiwan> Syntax is correct no?
<BlaXpirit> _jaitaiwan, haven't i told you previously :O {% begin %}
<_jaitaiwan> Yes but when you do that @type no longer works?
<BlaXpirit> _jaitaiwan, that wasn't in the right place. ok
<_jaitaiwan> Oh right
<_jaitaiwan> Thank you. I thought I had tried that
PositiveDown has joined #crystal-lang
<PositiveDown> how is the windows support looking? Has there been some progress made?
PositiveDown has quit [Client Quit]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
<FromGitter> <sdogruyol> @RX14 what do you mean?
soveran has quit [Ping timeout: 265 seconds]
<Papierkorb> https://crystal-lang.org/docs/syntax_and_semantics/attributes.html is the ThreadLocal example outdated with Crystal 0.19?
Raimondi has joined #crystal-lang
pduncan has joined #crystal-lang
pduncan has quit [Ping timeout: 250 seconds]
pduncan has joined #crystal-lang
<BlaXpirit> for sure
pduncan has quit [Ping timeout: 250 seconds]
pduncan has joined #crystal-lang
<FromGitter> <sdogruyol> how can i debug a spec that just errors out
mhib has joined #crystal-lang
<BlaXpirit> sdogruyol, same way as any normal code that just errors out
<FromGitter> <sdogruyol> by removal / trial :/
<BlaXpirit> it's a pain alright, and good luck if it only reproduces on travis
<FromGitter> <sdogruyol> nope its same as local
soveran has joined #crystal-lang
<crystal-gh> [crystal] asterite pushed 1 new commit to master: https://git.io/vi0Xd
<crystal-gh> crystal/master c7f06c7 Ary Borenszweig: Compiler: fixed codegen bug related to inlineable calls and forced Nil return type
soveran has quit [Ping timeout: 276 seconds]
pduncan has quit [Ping timeout: 250 seconds]
<travis-ci> crystal-lang/crystal#c7f06c7 (master - Compiler: fixed codegen bug related to inlineable calls and forced Nil return type): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/159114261
Ven_ has joined #crystal-lang
mhib has quit [Quit: Leaving]
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
matp has joined #crystal-lang
<crystal-gh> [crystal] asterite pushed 1 new commit to master: https://git.io/vi0S9
<crystal-gh> crystal/master e4dd5b4 Ary Borenszweig: FIxed Float64#to_s for 0.9999... Fixes #3292
Ven_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kulelu88 has joined #crystal-lang
<Papierkorb> Wrote a "broker" which accepts TCP connections and then publishes a string message to all connections at once. 10k clients (wrote that one in C), after ~3.6ms every client got the ~140Byte test message. Wanted to try Channels/Fibers. quite good results
Ven_ has joined #crystal-lang
Ven_ has quit [Client Quit]
Ven_ has joined #crystal-lang
Ven_ has quit [Ping timeout: 244 seconds]
soveran has joined #crystal-lang
<travis-ci> crystal-lang/crystal#e4dd5b4 (master - FIxed Float64#to_s for 0.9999... Fixes #3292): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/159126347
<DeBot> https://github.com/crystal-lang/crystal/issues/3292 (Incorrect Float64#to_s for 0.99999999...)
soveran has quit [Ping timeout: 265 seconds]
kulelu88 has quit [Ping timeout: 250 seconds]
<FromGitter> <sdogruyol> How was it compared to C
_jaitaiwan has quit [Ping timeout: 264 seconds]
Philpax has quit [Ping timeout: 252 seconds]
kulelu88 has joined #crystal-lang
soveran has joined #crystal-lang
<Papierkorb> sdogruyol, I didn't write the server ("broker") in C, only the client to make sure I'm not measuring any overhead Crystals client could introduce over the plain C implementation
akwiatkowski has joined #crystal-lang
ponga has quit []
<RX14> Papierkorb, can you write a broker in C nd compare?
<Papierkorb> When I feel like, I could
<FromGitter> <sdogruyol> Cool
Ven_ has joined #crystal-lang
<RX14> now in erlang/elixir and nodejs too!
<RX14> and run C1M while you're at ot :P
Ven_ has quit [Ping timeout: 264 seconds]
akwiatkowski has quit [Ping timeout: 244 seconds]
<FromGitter> <sdogruyol> Lol
soveran has quit [Remote host closed the connection]
akwiatkowski has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Read error: Connection reset by peer]
soveran_ has joined #crystal-lang
<akwiatkowski> How can I check if variable is uninitialized? By using var.uninitialized? ?
<RX14> akwiatkowski, if you need to know, don't use uninitialized
<RX14> if you don't know that it's set by the time of use you should be using nil instead
<akwiatkowski> I'm not using it.
<RX14> there is no way to tell
<akwiatkowski> But it is used in kemal
<RX14> what exactly are you trying to do?
<RX14> work on kemal itself?
<akwiatkowski> Run kemal spawned and wait till http server is ready. I think I'll check if there is open port.
<RX14> uhh
<akwiatkowski> I'm writing something like integration test
<RX14> just wait 1ms
<RX14> should be enough
<akwiatkowski> ok
<akwiatkowski> thx for convincing me
<RX14> lol
<RX14> i assume there's only 2 fibers
<RX14> the main one and the kemal one
<RX14> sleep 1ms will execute kemal until it blocks
<RX14> and it's very likely that the first blocking operation for kemal will be waiting for HTTP requests
<RX14> eh it's actually going to be the stdio write
<RX14> but I would reckon that 1ms will be enough to ensure
<akwiatkowski> I'll put 10ms to be sure
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 240 seconds]
Ven_ has joined #crystal-lang
Ven_ has quit [Ping timeout: 240 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 260 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 252 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 276 seconds]
Ven_ has joined #crystal-lang
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 240 seconds]
pawnbox has joined #crystal-lang
Ven_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
pawnbox has quit [Ping timeout: 264 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 244 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 250 seconds]
pawnbox has joined #crystal-lang
dhk has joined #crystal-lang
pawnbox has quit [Ping timeout: 250 seconds]
<travis-ci> crystal-lang/crystal#798b2e2 (master - Updated Changelog): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/158772553
<RX14> does this sound like a bug to anyone else? shouldn't the type only be changed after the proc is created: https://carc.in/#/r/198k
dhk has quit [Quit: Leaving]
A124 has quit [Quit: '']
pawnbox has joined #crystal-lang
A124 has joined #crystal-lang
pawnbox has quit [Ping timeout: 240 seconds]
A124 has quit [Read error: No route to host]
<BlaXpirit> RX14, uh wait what? you remove the proc and the result is still the same
<BlaXpirit> oh no i made a mistake
<RX14> yes, the rand
<BlaXpirit> that's why i dont use rand, this is enough https://carc.in/#/r/198m
A124 has joined #crystal-lang
<RX14> yeah i should
<BlaXpirit> sure, probably a bug
<BlaXpirit> in fact, why should the proc change its type at all, even if it was before?
pawnbox has joined #crystal-lang
vikaton has quit [Quit: Connection closed for inactivity]
pawnbox has quit [Ping timeout: 250 seconds]
soveran_ has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
akwiatkowski has quit [Ping timeout: 244 seconds]
pawnbox_ has joined #crystal-lang
pawnbox has quit [Ping timeout: 244 seconds]
pawnbox_ has quit [Ping timeout: 240 seconds]
<RX14> BlaXpirit, because type = nil
<RX14> idk
<RX14> i guess that doesn't make sense
<RX14> because you could do type = "" and type doesn't become Object
<RX14> as in can be set to anything
<RX14> so yeah
<RX14> weird
<RX14> i should report it but i need to get up early tomorrow so...
vikaton has joined #crystal-lang
Philpax has joined #crystal-lang
qard_ has quit [Ping timeout: 265 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 276 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
Philpax has quit [Ping timeout: 244 seconds]
bew78 has joined #crystal-lang
<crystal-gh> [crystal] asterite opened pull request #3294: Lift the restriction that type variables can only be single letter names (master...feature/relax_type_vars) https://git.io/viEtS