ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.22.0 | Fund Crystal's 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
bjz has joined #crystal-lang
bjz has quit [Client Quit]
txdv has joined #crystal-lang
<FromGitter> <elorest> Just wondering of anyone going to the code camp. What hotels did you book. I’m staying at the Royal Pacific Motor Inn.
<FromGitter> <drosehn> Ah, yeah, the code-camp. Some of the core developers might be busy preparing for that, in one way or another.
vikaton has joined #crystal-lang
<FromGitter> <bew> Why `Int32 === Int32` is `false` ?
zipR4ND has quit [Ping timeout: 240 seconds]
<FromGitter> <MatthewBennington> Okay, this is definitely really obvious, but I can't figure out how to read the next byte of a file as an int. Like, what's an equivalent to `file.gets 1` that returns and int.
<FromGitter> <Sija> `file.gets(1).to_i`?
<FromGitter> <bew> `read_byte.to_i`?
<FromGitter> <Sija> `file.read_byte.try(&.to_i)` :)
<FromGitter> <bew> oh yeah was writing about `not_nil!`, I always forget about `try`!
<FromGitter> <MatthewBennington> Thanks a lot!
<FromGitter> <bew> stupid thought: what do you prefer between `raise MyError.new "loooog message here" if true === 1` and `if true === 1; raise MyError.new "loooog message here"; end` (s/;/\n/g)
<FromGitter> <fridgerator> first one
<FromGitter> <bew> even if the line is between than 100-120 characters long?
<FromGitter> <fridgerator> ah, no not if the line is long, then the 2nd
<FromGitter> <fridgerator> should't have to scroll to see the condition
<FromGitter> <bew> agree
livcd_ has quit [Ping timeout: 255 seconds]
livcd has joined #crystal-lang
ryanf has joined #crystal-lang
<ryanf> is there no Crystal equivalent to Hash[ [['key1', 'val1'], ['key2', 'val2']] ]?
<ryanf> all I see is `zip`, which is different
<FromGitter> <bew> what do you want to do?
<ryanf> actually, in this case I just want to map a hash to another hash, so maybe there's a more direct way
<ryanf> which in Ruby would be Hash[hash1.map { |k, v| [k.whatever, v.whatever] }]
<FromGitter> <bew> what are the keys of this new hash?
<ryanf> for the sake of argument, let's say they're the same as the keys of the input hash, but I want to map the values through a function
<ryanf> actually I just ran into another case where I also would have used Hash[] in Ruby, which is that I have an array and I want to make a hash where the keys are the values in the array and all of the values are the same
<ryanf> in Ruby that would be Hash[arr.map { |v| [v, {}] }] (since the value I want is an empty hash)
<FromGitter> <bew> sth like? : {"one" => 1, "two" => 2}.map {|k, v| {k, {k, v}} }.to_h
<FromGitter> <bew> ryanf, see above
<ryanf> ahhh
<ryanf> yep, that's it
<ryanf> thanks
<ryanf> I knew I was missing something obvious :/
<FromGitter> <bew> yw :)
<FromGitter> <bew> it wasn't easy to find^^
<ryanf> oh yeah, I see
<ryanf> I searched for "hash" on the array page but
<ryanf> the description wasn't on there because it comes from enumerable
vikaton has quit [Quit: Connection closed for inactivity]
Cyrus has quit [Remote host closed the connection]
Qchmqs has joined #crystal-lang
jokke has joined #crystal-lang
Ven has joined #crystal-lang
Ven is now known as Guest85461
Guest85461 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ven has joined #crystal-lang
Ven is now known as Guest91537
Guest91537 has quit [Client Quit]
Ven_ has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
Ven_ has quit [Ping timeout: 260 seconds]
Ven has joined #crystal-lang
Ven is now known as Guest98432
_whitelogger has joined #crystal-lang
Qchmqs has quit [Read error: Connection reset by peer]
Qchmqs has joined #crystal-lang
Guest98432 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
zipR4ND has joined #crystal-lang
Ven_ has joined #crystal-lang
bjz has joined #crystal-lang
zipR4ND has quit [Ping timeout: 260 seconds]
Ven_ has quit [Ping timeout: 260 seconds]
Ven has joined #crystal-lang
Ven is now known as Guest9182
splitty___ has joined #crystal-lang
splitty__ has quit [Ping timeout: 252 seconds]
<FromGitter> <jlebray> Hi, I ran into some issue.
<Papierkorb> Go on..
<FromGitter> <jlebray> Hi, I just ran into some issue. ⏎ When I use a map on an array defined as a reduce result, it works. But if I use it inside a conditional, I get a wrong type inference : ⏎ http://1.1m.yt/iMorjw_.png ⏎ Is that intended ? [https://gitter.im/crystal-lang/crystal?at=59072843edf919574a66d634]
<FromGitter> <sdogruyol> it's
<FromGitter> <sdogruyol> because it can be nil and you need to handle nil
<FromGitter> <jlebray> But then why the first one is working ?
unshadow has joined #crystal-lang
<unshadow> What tools can I use to identify mem leaks in Crystal programs ? could I use valgrind ?
<Yxhuvud> sure.
<Yxhuvud> assuming it is an actual leak and not just an accumulation of references that doen't get colelcted. If that is the case I don't know
<FromGitter> <drosehn> @jlebray : so, `list` is an array of integers?
<FromGitter> <jlebray> Oh sorry, I got it... my next set result to nil so it's type can be nil on the next iteration. I can't use this syntax here.
<FromGitter> <drosehn> I think it'd help to see the missing lines. Note that when you're looping-through the reduce, the value of `result` is set by the value of the last command which was executed in the previous loop.
<FromGitter> <drosehn> ok. I don't use map/reduce much, but I didn't want to leave your question just hanging there. :smile:
<FromGitter> <jlebray> Thanks :smiley:
<FromGitter> <luislavena> @jlebray reduce is expecting the last instruction of the block be the result that will be the new value used for the next iteration: https://crystal-lang.org/api/0.22.0/Enumerable.html#reduce%28%26block%29-instance-method
<FromGitter> <luislavena> Since you're doing `next` there, some of the values will be `nil`, which is why fails to compile.
<FromGitter> <luislavena> what are you trying to obtain?
<FromGitter> <drosehn> I must admit that the few times I've used reduce, the last statement that my block would execute would explicitly set a new value for `result`. It wasn't until seeing this example that I realized `result` was set by the value of the last statement executed in the block!
<FromGitter> <drosehn> is the value of the statement `next` always `nil`? If so, it seems like `next` is awkward to use in a `reduce{}` block.
Kilo`byte has left #crystal-lang [#crystal-lang]
<Yxhuvud> what happens if you do next 5 ? At least in ruby that will have the value 5.
<Papierkorb> next acts like return and accepts an optional result value
<FromGitter> <jlebray> @luislavena @drosehn next works like return, I used it to avoid if/else statement at the end of the block, like rubocop would have told me
<FromGitter> <jlebray> I just changed it to "return result unless valid"
<FromGitter> <drosehn> Ah. I didn't see that in the description of `next`: https://crystal-lang.org/docs/syntax_and_semantics/next.html
<FromGitter> <luislavena> @jlebray but when using reduce, you're setting the last value to `nil`. My question was what you're trying to achieve.
<FromGitter> <jlebray> I was doing some Exercism ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59073abcf22385553d936f12]
<Papierkorb> Why not use #select?
<FromGitter> <jlebray> Yes :confused: Should have
<Papierkorb> apart from that, `array << value` is much more efficient than `array + [value]`
<Papierkorb> That code would copy that array over and over again
<FromGitter> <jlebray> The reduce allows me to check the unicity case-insensitively
<FromGitter> <jlebray> Yes, thanks
<Papierkorb> Then select (or reject) beforehand, and if you need further manipulation, add a #map afterwards
<RX14> and if you use iterators you can even get away without an intermediate array
<FromGitter> <luislavena> @jlebray seems that `test` value is saved unaltered, so perhaps you can use `select` as indicated, and combine with `map` if further transformation is required.
<FromGitter> <luislavena> but since you're checking against previous stored results, then perhaps is a matter of changing the last 2 lines:
<FromGitter> <luislavena> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59073c638fcce56b205375a6]
<FromGitter> <luislavena> one problem I see is that you're transforming on every iteration `result` to be downcase and compare `test.downcase` against it. That will be a performance penalty the bigger `result` gets
<FromGitter> <jlebray> Yes, I could also a create a HashSet to check the already stored values
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<FromGitter> <jlebray> This fills the requirements ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59073e776aea30763d5cc817]
<Papierkorb> Or just using functionality of Enumerable and Array: https://gist.github.com/Papierkorb/4b1977b3bfffccc46fb13b107e66e983
<FromGitter> <KCreate> Hey, does anyone know how I could fix this error: ⏎ ⏎ ```Error in a.cr:3: undefined constant Bar ⏎ ⏎ Foo.define Bar ⏎ ^~~``` [https://gitter.im/crystal-lang/crystal?at=59074a02edf919574a676c57]
<FromGitter> <KCreate> It's as if crystal doesn't know that Foo.define is a macro method
<FromGitter> <KCreate> It's weird because this works: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59074adb8bb56c2d11fde80f]
<FromGitter> <fridgerator> this works too: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59074b26881b89e101a2760e]
<FromGitter> <KCreate> I would have thought that would create the macro method as an instance method
<FromGitter> <KCreate> Alright I solved my issue, turns it it was a syntax error in my original code... duh
<FromGitter> <KCreate> Is it possible to do something like this? ⏎ ⏎ ```class Baz(T) < T ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=59074ee66aea30763d5d12c5]
<FromGitter> <sdogruyol> ugh
<FromGitter> <sdogruyol> why?
<FromGitter> <KCreate> Ah, nevermind.. Was a stupid idea and I solved in a different way
Dreamer3 has quit [Quit: Leaving...]
Qchmqs has quit [Ping timeout: 245 seconds]
Guest9182 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ven has joined #crystal-lang
Ven is now known as Guest61766
unshadow has quit [Quit: leaving]
adam- has joined #crystal-lang
dannyAAM has quit [*.net *.split]
poikon has quit [*.net *.split]
adam12 has quit [*.net *.split]
dannyAAM has joined #crystal-lang
poikon has joined #crystal-lang
<FromGitter> <flgr> I know someone who implemented pseudo-mixins in C++ along those lines @ ancestor class from a type parameter
unshadow has joined #crystal-lang
<unshadow> Why does unhandled exception in spawn prints to STDERR ? (even if it's inside a begin rescue above)
<oprypin> unshadow, because that's how things work
<oprypin> the line with `spawn` finished executing and didnt raise any exception, so rescue didn't catch it
<oprypin> the fact that it changed something in the background is irrelevant
<unshadow> Hmmmm I see, so I have to catch the exceptions inside the Fiber else it wont go back out to the main process right ?
Guest61766 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<oprypin> yes
yogg-saron has joined #crystal-lang
<unshadow> Cool, Thanks oprypin
oprypin has quit [Quit: Bye]
oprypin has joined #crystal-lang
adam- is now known as adam12
vikaton has joined #crystal-lang
<FromGitter> <fridgerator> I am creating an `HTTP::Server`in one file, then in a separate file sending multiple get requests with a single `HTTP::Client`. This is pipelining requests correct?
<FromGitter> <fridgerator> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5907828ed32c6f2f095aeeea]
<FromGitter> <lucas-wade> @Rinkana whats the url for your 3d engine?
<FromGitter> <elorest> So I was reading through this: https://github.com/crystal-lang/crystal/wiki/MetaProgramming-Help ⏎ ⏎ but it seems like the second on method_missing doesn’t have any content. The fact that there’s a second for it though seems to imply its possible?
tzekid has joined #crystal-lang
zipR4ND has joined #crystal-lang
<FromGitter> <chuckremes> @elorest That page is still “under construction.” Haven’t had time to work on it the last week. Maybe later this week I’ll flesh out a few more topics.
<FromGitter> <elorest> Ok. Sounds good. Do you have an example off the top of your head that would be the macro equivalent to ruby `method_missing`
Ven has joined #crystal-lang
Ven is now known as Guest7768
yogg-saron has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Guest7768 is now known as Ven`
Ven` is now known as Ven``
Ven`` has quit [Ping timeout: 260 seconds]
Ven_ has joined #crystal-lang
unshadow has quit [Ping timeout: 260 seconds]
unshadow has joined #crystal-lang
tzekid has quit [Quit: tzekid]
Ven_ has quit [Ping timeout: 260 seconds]
Raimondii has joined #crystal-lang
zipR4ND has quit [Ping timeout: 240 seconds]
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
zipR4ND has joined #crystal-lang
<FromGitter> <chuckremes> @elorest I don’t have a quick example, sorry. I’ll put my thinking cap on later this week and update the wiki.
<FromGitter> <elorest> Sounds good. Thanks
sz0 has joined #crystal-lang
<FromGitter> <eliasjpr> Question is there a way to define a polymorphic type in crystal?
<FromGitter> <eliasjpr> instead of doing something like (Int | String | Bool | Int32 | Array | Hash) etc
<FromGitter> <eliasjpr> I can just do `α` as a representation of a polymorphic type
<FromGitter> <Sija> I’m not sure I understand what do u mean by “polymorphic types”, there r which might suits u tho'
<FromGitter> <Sija> there r generics*
<FromGitter> <eliasjpr> thanks for the help not exactly what I was looking for
<FromGitter> <Sija> yeah, more information would help :)
<FromGitter> <eliasjpr> I dont want to complicate you, but basically in some languages you can define a method like `a, b -> α`
<FromGitter> <eliasjpr> where alpha `α` can be of any type
<FromGitter> <eliasjpr> so I writing a crystal mehtod that takes a proc acrgument, but in order to run it I have to specify the type returned by the proc
<FromGitter> <eliasjpr> `method( &block : ->Nil)` it would be nice to say `method( &block : ->α)`
<FromGitter> <Sija> u can use generic `T` (or any other uppercased name) for that