jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.12.0 | 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
pawnbox has quit [Ping timeout: 250 seconds]
sp4rrow has quit [Quit: The Internet needs a break and I need a cookie]
sp4rrow has joined #crystal-lang
sp4rrow has quit [Ping timeout: 244 seconds]
sp4rrow has joined #crystal-lang
bcardiff has joined #crystal-lang
Gasher has quit [Quit: Leaving]
trapped has quit [Read error: Connection reset by peer]
trapped has joined #crystal-lang
sp4rrow has quit [Quit: The Internet needs a break and I need a cookie]
bcardiff has quit [Ping timeout: 268 seconds]
<umurgdk> Im having a strange error about generics and inheritance
<umurgdk> is it a compiler bug or am i doing something wrong?
bcardiff has joined #crystal-lang
bcardiff has quit [Quit: bcardiff]
umurgdk has quit [Remote host closed the connection]
trapped has quit [Read error: Connection reset by peer]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 276 seconds]
sp4rrow has joined #crystal-lang
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 264 seconds]
fowlduck_ has joined #crystal-lang
fowlduck has quit [Read error: Connection reset by peer]
fowlduck_ has quit [Read error: Connection reset by peer]
fowlduck has joined #crystal-lang
plukevdh has joined #crystal-lang
plukevdh has quit [Client Quit]
sp4rrow has quit [Quit: The Internet needs a break and I need a cookie]
sp4rrow has joined #crystal-lang
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 268 seconds]
sp4rrow has quit [Quit: Textual]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 268 seconds]
Philpax has quit [Ping timeout: 244 seconds]
Philpax has joined #crystal-lang
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 240 seconds]
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
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
fowlduck has quit [Remote host closed the connection]
<pawnbox> Is it possible to run a single spec using crystal spec.
<pawnbox> ??
<jhass> yes
<jhass> I think you can just crystal spec spec/foo_spec.cr:line_number
<pawnbox> Tried it but it runs all the specs.
<pawnbox> Maybe it beacause i am using spec2.
<jhass> yes likely
<RX14> hmmn
<RX14> has anyone done work on groovy-style power asserts using crystal?
<RX14> oh yep, they have
<RX14> do we still not have line numbers for errors?
fowlduck has joined #crystal-lang
<jhass> try compiling with -d
fowlduck has quit [Ping timeout: 252 seconds]
Gasher has joined #crystal-lang
trapped has joined #crystal-lang
umurgdk has joined #crystal-lang
ponga has joined #crystal-lang
<RX14> jhass, how can I run crystal spec with -d?
<jhass> idk but it doesn't do much special stuff, you should be fine with using crystal build on a spec file
<RX14> jhass, still no line numbers with -d
<jhass> too bad
<jhass> tried HEAD? I think ary did some stuff for proc literals at least
<jhass> also iirc it only works with llvm 3.5 atm
<RX14> do I need a specific llvm version?
<RX14> oh
<RX14> i have llvm 2.5
<RX14> 3.5*
<RX14> heh
* jhass shrugs
<jhass> it's all wonky still
<RX14> oh well, not too big of a deal
<umurgdk> guys does any have an idea about subclassing from abstract generic base class?
<umurgdk> I tried to explain in GH issue
<jhass> umurgdk: def intialize
<jhass> spot the typo ;)
<RX14> haha i would never have spotted that
<umurgdk> ahhh :D
<umurgdk> dammit
<RX14> the compiler could make warnings for methods which are closely named to initialize
<jhass> I think we're still warning free and I kinda like that fact
<umurgdk> ohh warning could help. i spent more than one hour :(
<jhass> I guess on that error message the compiler could try to look for misspelled ones
<jhass> and point it out inside the error message
<RX14> ah yeah, that would be cool
<umurgdk> elm-lang's compiler does a great job in that manner
<RX14> crystal's errors are pretty damn good
<RX14> but there's always room for improvement
<umurgdk> btw should i call super in initialize methods to be sure parent class's constructor is called?
<jhass> yes
<jhass> I think so
<umurgdk> @RX14 i agree nil traces and steps are really cool
<crystal-gh> [crystal] jhass closed pull request #2260: update manual installation ubuntu and debian [ci skip] (gh-pages...update-installation-debian-ubuntu) https://git.io/v2yCS
fmcevoy has quit [Quit: Lost terminal]
fmcevoy has joined #crystal-lang
Philpax has quit [Ping timeout: 252 seconds]
<crystal-gh> [crystal] asterite pushed 1 new commit to master: https://git.io/v2NI1
<crystal-gh> crystal/master bcafd9b Ary Borenszweig: Call error: suggest that there might be a typo in a method whose name is similar to 'initialize'. Fixes #2271
<umurgdk> Is there any documentation about how to use Type+
<umurgdk> what + means
<travis-ci> crystal-lang/crystal#bcafd9b (master - Call error: suggest that there might be a typo in a method whose name is similar to 'initialize'. Fixes #2271): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/113892103
Ven has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
<crystal-gh> [crystal] asterite pushed 1 new commit to master: https://git.io/v2NtQ
<crystal-gh> crystal/master 46ba2ec Ary Borenszweig: Lexer: inside macros, make sure to parse `#{{{` as `#{ {{`
<jhass> umurgdk: compiler internal relic, will eventually go, safe to ignore in any case
<jhass> it just means the type has child types
<umurgdk> jhass: heh anyway i solve the problem. but it was a bit strange
<umurgdk> i have this class named String inside of Parsec module
<umurgdk> but compile finds standard String even i type Parsec::String
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
<jhass> sounds unlikely
<umurgdk> i renamed it to StringParser and it solved :D
<jhass> >> module Parsec; class String; end; end; s = Parsec::String.new; s.is_a? String
<DeBot> jhass: # => false - https://carc.in/#/r/tnm
<umurgdk> after i changed the classname it find other issues with types after i solved them it worked. maybe it was selecting standard String because it can't compile other stuff i don't know o.O
<jhass> hard to tell without having seen it
<jhass> >> module Parsec; end; Parsec::String.new
<DeBot> jhass: undefined constant Parsec::String - https://carc.in/#/r/tnn
<travis-ci> crystal-lang/crystal#46ba2ec (master - Lexer: inside macros, make sure to parse `#{{{` as `#{ {{`): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/113897658
<umurgdk> probably i made something wrong :)
<umurgdk> *did
bcardiff has joined #crystal-lang
daemonwrangler has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
rok has joined #crystal-lang
pawnbox has joined #crystal-lang
bcardiff has quit [Quit: bcardiff]
<crystal-gh> [crystal] asterite pushed 2 new commits to master: https://git.io/v2NOz
<crystal-gh> crystal/master b4b1eea Brian J. Cardiff: add BitArray#to_slice to return a UInt8 slice
<crystal-gh> crystal/master 5095c16 Ary Borenszweig: Merge pull request #2270 from bcardiff/feature/bit-array-slice...
<travis-ci> crystal-lang/crystal#5095c16 (master - Merge pull request #2270 from bcardiff/feature/bit-array-slice): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/113904807
bcardiff has joined #crystal-lang
_kfpratt has joined #crystal-lang
kfpratt has quit [Ping timeout: 248 seconds]
Gasher has quit [Quit: Leaving]
dom96 has quit [Changing host]
dom96 has joined #crystal-lang
zeno_ has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<umurgdk> does crystal compiler code elimination? i mean even i implement many helpers in my library if developer don't use them compiler get rid of unused things?
<jhass> kind of, yes. methods are typed on call, not on definition, so methods not called won't even generate llvm IR
<umurgdk> jhass: cool thanks
Ven has joined #crystal-lang
ponga has quit [Quit: Connection closed for inactivity]
<RX14> jhass, is there any sort of dead code elimination that could affect benchmarking?
<jhass> why would it affect benchmarking?
<jhass> I don't think there's any done by crystal on that granular level, that's more a LLVM optimizer job
<RX14> well, if your whole code gets optimised to nothing because the value is never used, then your benchmark is void
<jhass> I'd argue then your benchmark is buggy ;)
<RX14> i'd argue the benchmark harness would be buggy
<jhass> but sure, LLVM does that kind of elimination
<RX14> JMH has a class called blackhole which deals with this
zeno_ has quit [Ping timeout: 252 seconds]
krtv` has joined #crystal-lang
<umurgdk> can i define custom operators for classes (not overloading new ones)?
<jhass> you can't make up new syntax, but most if not all operators are just method calls
<jhass> and interpret all syntax in interesting ways if you use it in a macro call I guess
<umurgdk> im writing a parser combinator library
<umurgdk> as far as i would be able to do like this: string("ruby") | string("crystal")
<umurgdk> but if i had custom operators (infix methods with custom precedence i would be able to write + / ! etc. without paranthesis or temp variables
<RX14> + and / should be methods
<jhass> | too
<RX14> yeah
<umurgdk> is there any precedence table i can check
<jhass> not aware of any yet
<jhass> I'd expect it to be similar to ruby's though
<umurgdk> ok i will write a script to test :)
krtv` has quit [Ping timeout: 244 seconds]
krtv` has joined #crystal-lang
krtv` has quit [Ping timeout: 252 seconds]
krtv` has joined #crystal-lang
krtv` has quit [Ping timeout: 250 seconds]
fowlduck has joined #crystal-lang
fowlduck has quit [Remote host closed the connection]
krtv` has joined #crystal-lang
bcardiff has quit [Quit: bcardiff]
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
shama has joined #crystal-lang
krtv` has quit [Ping timeout: 276 seconds]
krtv` has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
krtv` has quit [Ping timeout: 244 seconds]
shadeslayer has quit [Read error: Connection reset by peer]
krtv` has joined #crystal-lang
krtv` has quit [Ping timeout: 268 seconds]
ragmaanir has joined #crystal-lang
umurgdk has quit [Read error: Connection reset by peer]
umurgdk has joined #crystal-lang
Gasher has joined #crystal-lang
shama has quit [Remote host closed the connection]
shama has joined #crystal-lang
umurgdk has quit [Remote host closed the connection]
umurgdk has joined #crystal-lang
sp4rrow has joined #crystal-lang
shama has quit [Quit: (╯°□°)╯︵ɐɯɐɥs]
robacarp has quit [Ping timeout: 244 seconds]
Gasher has quit [Quit: Leaving]
robacarp has joined #crystal-lang
bcardiff has joined #crystal-lang
Ven has joined #crystal-lang
bcardiff has quit [Client Quit]
Gasher has joined #crystal-lang
ready has joined #crystal-lang
<ready> undefined method 'to_i' for Nil
<BlaXpirit> ready, indeed
<ready> hi, how i can convert env.params["sid"] to int?
<BlaXpirit> ready, not enough information
<ready> i get env.params["sid"] from request
<ready> and i want convert to int
<BlaXpirit> ready, that must be some library that you're using?
<ready> but seems dont exist safe method for converting
<BlaXpirit> ready, no, you just probably haven't read any tutorial about Crystal
<BlaXpirit> >> {"a": "5"}["a"].to_i
<DeBot> BlaXpirit: # => 5 - https://carc.in/#/r/toy
<BlaXpirit> ready, see, no problem
<umurgdk> ready: env.params["sid"].try &.to_i
<ready> >> [nil,"4",""][3].to_i
<DeBot> ready: undefined method 'to_i' for Nil (compile-time type is String?) (did you mean 'to_s'?) - https://carc.in/#/r/tp3
<umurgdk> >> [nil,"4",""][3].try &.to_i
<BlaXpirit> ready, indeed, you're just trying to write Ruby in Crystal. that won't do
<DeBot> umurgdk: Index out of bounds (IndexError) - https://carc.in/#/r/tp7
<ready> >> [nil,"4",""][2].to_i
<DeBot> ready: undefined method 'to_i' for Nil (compile-time type is String?) (did you mean 'to_s'?) - https://carc.in/#/r/tpa
<umurgdk> >> [nil,"4",""][0].try &.to_i
<DeBot> umurgdk: # => nil - https://carc.in/#/r/tpc
krtv` has joined #crystal-lang
<umurgdk> >> [nil,"4",""][1].try &.to_i
<DeBot> umurgdk: # => 4 - https://carc.in/#/r/tpe
rok has quit [Quit: rok]
<BlaXpirit> yeah this is pretty good but I suspect that this library that ready is using doesn't follow Crystal's conventions
<ready> >> [nil,"4",""][2].try &.to_i
<DeBot> ready: invalid Int32: (ArgumentError) - https://carc.in/#/r/tpk
<BlaXpirit> if it did, this wouldn't be a problem in the first place
<BlaXpirit> namely, params["a"] acts the way params["a"]? should
<umurgdk> BlaXpirit: isn't try method defined on the Object and Nil?
<BlaXpirit> umurgdk, I'm not sure what you mean. but I would say that idiomatic code rarely needs 'try'
<BlaXpirit> there we go
<ready> i want convert to Int32 env.params
<BlaXpirit> now I know to avoid and never recommend Kemal
<ready> can't cast (Nil | String | Float64 | Int64 | Bool | Array(JSON::Type) | Hash(String, JSON::Type)) to Int32
<ready> seems lang looks like a bit of shit
bjz has quit [Max SendQ exceeded]
<BlaXpirit> ready, no, it's just this library and you
<ready> dude , lol
<BlaXpirit> you should start with the tutorial and simpler examples, instead of expecting a magical fast ruby
bjz has joined #crystal-lang
Philpax has joined #crystal-lang
<umurgdk> BlaXpirit: how it should be?
<jhass> I guess it returns a potential nil there because it parses json request bodies for you
Gasher^ has joined #crystal-lang
<BlaXpirit> jhass, it parses json AND returns simple request arguments in the same function AND can also return nil for whatever reason
<umurgdk> and / or query params
<BlaXpirit> terrible design
<jhass> >> JSON.parse("null")
<DeBot> jhass: undefined constant JSON - https://carc.in/#/r/tpq
<jhass> >> require "json"; JSON.parse("null")
<DeBot> jhass: in line 21: can't require dynamically - https://carc.in/#/r/tpr
Gasher has quit [Ping timeout: 244 seconds]
<jhass> meh
<BlaXpirit> jhass, :D ran into this recently as well
<jhass> anyway, still proves the point
<jhass> null is parsed to nil
<BlaXpirit> ready, i'm sorry that i'm so rude. but seriously that Kemal library will not be a good starting point
<BlaXpirit> jhass, still if I want to read request args I need a method that returns String and nothing else
<ready> why
<jhass> ready: the proper solution is .try &.to_i or .try &.to_i? if you want to be exception free and handle the case it's nil
<ready> dont work
<BlaXpirit> jhass, no, that's not proper. that's the best workaround.
<ready> undefined method 'to_i' for Bool
<jhass> BlaXpirit: ssssh
<jhass> relax
<jhass> ugh
<BlaXpirit> I would guess.... (params["a"] as String).to_i
<BlaXpirit> I seriously don't remember ever using .try , forgot it even existed
<jhass> or exception free, foo = request.params["foo"]; foo = foo.to_i? if foo.is_a? String; bad_request unless foo.is_a? Int32
<BlaXpirit> jhass, pretty sure that won't work
<jhass> bad_request is pseudo for sure
<BlaXpirit> oh I missed the suffix if, sorry
<BlaXpirit> what a mouthful
<BlaXpirit> and what it really should be, under proper design: params["a"].to_i; rescue; bad_request
<jhass> well, I can follow the motivation for having the framework handle application/json vs application/multipart-form-data-whatever for you transparently
fka has joined #crystal-lang
<BlaXpirit> jhass, problem is the SAME method is used for /resize?width=200&height=200 env.params["width"]
<ready> working sid = env.params["sid"].to_s.to_i
<ready> looks shitty
<jhass> ready: it's the least proper solution, yes
<jhass> >> false.to_s.to_i
<DeBot> jhass: invalid Int32: false (ArgumentError) - https://carc.in/#/r/tpt
<umurgdk> >> false.to_s.to_i?
<DeBot> umurgdk: # => nil - https://carc.in/#/r/tpu
<jhass> don't...
<BlaXpirit> the cringes are real
<ready> BlaXpirit, dude, kemal is pretty good
<BlaXpirit> ready, i can only repeat, the shittiness comes only from kemal
<ready> not beatiful but good
<jhass> BlaXpirit: conflating query and post parameters is controversial but not that uncommon, but the point I made causes the same issues
<fka> hey all
<jhass> BlaXpirit: watch your tone a bit please
<fka> <- one of the core devs of kemal here :)
<BlaXpirit> jhass, just paraphrasing [:23:51] <ready> looks shitty
<ready> has done simple 5 pages site for 2 hours
<jhass> BlaXpirit: let's not play that game, thanks
<ready> if u find better lib , ping us
<fka> we still develop kemal and we know it has some issues. PR's are welcome :)
<jhass> fka: I think you'll win a lot by separating API for body, query and path params
<BlaXpirit> well, I don't see any good web framework in top 5
<jhass> the latter too being string only and far more often subject to conversions will make it easier to use
<jhass> *two
<fka> actually me and serdar (sdogruyol, the owner of kemal) argued about it many times. but we decided a post and a get parameter with the same key is a bad design itself.
<BlaXpirit> fka, here I see GET and JSON with the same key
<jhass> read the backlog for ready's question, it's not about being able to have that
<BlaXpirit> /resize?width=200&height=200 someone tries env.params["width"] and gets a ... (Nil | String | Float64 | Int64 | Bool | Array(JSON::Type) | Hash(String, JSON::Type))
<BlaXpirit> fka, why?
fka_ has joined #crystal-lang
<fka_> sorry my connection lost
<jhass> ?logs
<DeBot> jhass: Nothing known about logs.
fka has quit [Ping timeout: 248 seconds]
fka_ is now known as fka
<jhass> ?logs=You can find a log of this channel at http://irclog.whitequark.org/crystal-lang/
<DeBot> jhass: Set logs.
<fka> oh thanks
<jhass> ?log=?logs
<DeBot> jhass: Set log.
<fka> @BlaXpirit you may be right. that's what sdogruyol decided when we are developing. but that doesn't mean it's the truth
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<fka> that's why your PR's are welcome. help us to make it better. "avoid using kemal" doesn't make things better, imho.
<jhass> fka: maybe faster and to get to the point: get "/photos/:id" do |env| id = env.request["id"] # here convert id to an Int32
<jhass> er, params, you get it
<jhass> try to solve the issue, you'll notice the issue with the current design
<fka> yep. i agree. i'm not defending the design btw. it may be wrong. i'm here just because of the manner to the kemal
<umurgdk> jhass: before this discussions i was thinking about how to make routing typesafe
<umurgdk> instead of converting in the handler
<umurgdk> you can define handler function with type restrictions
<umurgdk> and maybe /:id{Int32} like type restrictions on the path
<umurgdk> then if type mismatch that means 404
<jhass> yeah, could be interesting
<BlaXpirit> umurgdk, that gets a meh from me
<fka> route parsing is done at luislavena/radix
<umurgdk> BlaXpirit: lovely :)
<fka> i mean url params.
<BlaXpirit> I don't think it's possible to change a return type based on a string argument
<BlaXpirit> and without this it's just not very much use
<BlaXpirit> much easier to just write params["id"].to_i; rescue; bad_request
<BlaXpirit> fka, well yes, the problem is very clear by looking at this file
<fka> it pulls the url params and pushes to the env.params. you still can use simply `env.request.url_params`
<fka> it will give you a hash
<BlaXpirit> fka, that's nice then
shama has joined #crystal-lang
<BlaXpirit> well... not so nice, too long
<jhass> ready: so in case you're not following, sid = env.request.url_params["sid"].to_i
<ready> ok
<fka> and you can also use `HTTP::Params.parse(env.request.query)`
<fka> it will give you a hash of query strings.
<fka> yes, kinda long.
<fka> we may create a simple shortcut
<crystal-gh> [crystal] ysbaddaden pushed 6 new commits to master: https://git.io/v2N7u
<crystal-gh> crystal/master 690ab64 Julien Portalier: Set compiler flags from target triple
<crystal-gh> crystal/master 0566134 Julien Portalier: Compile against musl-libc (Errno)
<crystal-gh> crystal/master 141fe70 Julien Portalier: Use tzset and timezone on Linux...
<fka> and leave `env.params` as is.
<fka> `env.query_params`, `env.url_params`
<fka> `env.request.body` is already there to get the whole json or something you get from client
<ready> seems problems
<ready> instance variable '@url_params' of HTTP::Request was not initialized in all of the 'initialize' methods, rendering it nilable
<BlaXpirit> yeah slap another .try onto it -__-
<umurgdk> i was talking about something like that
krtv` has quit [Ping timeout: 250 seconds]
<BlaXpirit> umurgdk, but consider this example
<BlaXpirit> >> ("a" and 5) + 100
<DeBot> BlaXpirit: Syntax error in eval:21: unterminated parenthesized expression - https://carc.in/#/r/tpv
<BlaXpirit> >> ("a" & 5) + 100
<DeBot> BlaXpirit: undefined method '&' for String - https://carc.in/#/r/tpw
<BlaXpirit> >> ("a" && 5) + 100
<DeBot> BlaXpirit: no overload matches 'String#+' with type Int32 - https://carc.in/#/r/tpx
<BlaXpirit> finally. sorry
<BlaXpirit> umurgdk, my point is, that would be the error that you would get
<BlaXpirit> because id would be (String|Int32| 100 other types)
<umurgdk> what do you mean?
<umurgdk> you defined as Int32 and it only calls if type matches
<BlaXpirit> umurgdk, yes, it calls only if type matches. now id.class == Int32, typeof(id) == (Int32 | String)
<BlaXpirit> id + 100 does not work
<umurgdk> why typeof(id) == (Int32 | String)
<BlaXpirit> very difficult to explain and i'm not 100% sure i'm right
<umurgdk> before you call handler you tried .to_i on the id part. if error thrown that means 404 other way typeof(result of .to_i) is Int32
<BlaXpirit> umurgdk, no, before ANY of that happens, the code is compiled. this code would not compile
<travis-ci> crystal-lang/crystal#9a0ef62 (master - Merge pull request #2124 from ysbaddaden/musl-libc): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/113971488
<fka> /post/:id{Int32}, /post/:id{String}
<fka> they will be different paths then
<fka> hmm
<fka> we now have "url overloading"