RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.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
rohitpaulk has quit [Ping timeout: 268 seconds]
rohitpaulk has joined #crystal-lang
cyberarm_ has quit [Ping timeout: 240 seconds]
cyberarm has joined #crystal-lang
<hightower2> Is it possible to have a "case var; when some_list", and have the 'when' match if var's value is found in some_list?
<hightower2> I tried both with an array and tuple and specifying "when *list" and "when list", and it didn't work (no error, but didn't match)
<hightower2> (I mean I get error with '*list', and no error but also no match with 'list')
<FromGitter> <PlayLights_twitter> Include?
<hightower2> yes but I can't write that in a case/when syntax
<FromGitter> <PlayLights_twitter> well maybe you can save the result before the case when by the way thats dirty
rohitpaulk has quit [Ping timeout: 245 seconds]
rohitpaulk has joined #crystal-lang
faustinoaq has quit [Quit: IRC client terminated!]
<hightower2> I am calling var1, var2, var3 = string.split 'delimiter', and am getting Index out of bounds because there are no 3 fields in string. Is there a way to default the missing ones to nil rather than raising?
<FromGitter> <bew> Don't think so
rohitpaulk has quit [Ping timeout: 240 seconds]
return0e has quit [Remote host closed the connection]
rohitpaulk has joined #crystal-lang
return0e has joined #crystal-lang
hightower3 has joined #crystal-lang
hightower2 has quit [Ping timeout: 240 seconds]
rohitpaulk has quit [Ping timeout: 268 seconds]
<crystal-gh> [crystal] matiasgarciaisaia closed pull request #5727: Handle [CMD/CTRL]+S on Playground (master...feature/playground_binding_cmd_s_and_ctrl_s_to_run_code) https://git.io/vAlqY
rohitpaulk has joined #crystal-lang
<travis-ci> crystal-lang/crystal#163c0cb (master - binding cmd-s and ctrl-s to runCode): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/348078048
brycek has quit [Ping timeout: 240 seconds]
danzilio has quit [Ping timeout: 256 seconds]
hmans has quit [Read error: Connection reset by peer]
aarongodin has quit [Read error: Connection reset by peer]
andersh has quit [Read error: Connection reset by peer]
aemadrid has quit [Ping timeout: 255 seconds]
mroth has quit [Read error: Connection reset by peer]
manveru has quit [Write error: Connection reset by peer]
jwaldrip has quit [Ping timeout: 256 seconds]
Majost has quit [Read error: Connection reset by peer]
avdi has quit [Ping timeout: 240 seconds]
thi_ has quit [Ping timeout: 256 seconds]
thi_ has joined #crystal-lang
hmans has joined #crystal-lang
ilovezfs_ has quit [Ping timeout: 240 seconds]
andersh has joined #crystal-lang
aemadrid has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
aarongodin has joined #crystal-lang
avdi has joined #crystal-lang
brycek has joined #crystal-lang
Majost has joined #crystal-lang
jwaldrip has joined #crystal-lang
rohitpaulk has joined #crystal-lang
ilovezfs_ has joined #crystal-lang
manveru has joined #crystal-lang
mroth has joined #crystal-lang
danzilio has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <aisrael> @hightower2 This isn’t pretty but does the job: ⏎ `var1, var2, var3 = string.split(delimiter) + [nil, nil, nil]`
alex`` has joined #crystal-lang
rohitpaulk has joined #crystal-lang
jetpack_joe has joined #crystal-lang
<FromGitter> <bew> this is very very bad memory wise, as I think it'll create 4 arrays: one for the split, one for the `[nil]`, one for the `[nil] * 3` and one for the concatenation of the split's array, and the `[nil] * 3`'s array...
rohitpaulk has quit [Ping timeout: 256 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 265 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <aisrael> That’s true. Well, maybe in the future the compiler can optimize the `[nil] * 3` and make it like, `Array.new(3, nil)` so less one array creation :)
<FromGitter> <aisrael> Is there a way to resize or add capacity to an array, filling up the new elements with some default value (or `nil`)?
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <Qwerp-Derp> How do I get the maximum value an `IntXX` class can be from an instance of that class? So for example, if I have `x` which is an `Int16`, I want to get `Int16.MAX`, but if it's an `Int64` I want `Int64.max` instead.
<FromGitter> <ezrast> @Qwerp-Derp I'm not sure if there's a general way but there's this: https://carc.in/#/r/3nv6
alex`` has quit [Quit: WeeChat 2.0.1]
<FromGitter> <Qwerp-Derp> OK, now I have a really hacky solution for #5715: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a990c4ac3c5f8b90d231a79]
<DeBot> https://github.com/crystal-lang/crystal/issues/5715 (`Number.round` does not handle its arguments correctly)
<FromGitter> <Qwerp-Derp> `Math.round` just rounds to whatever precision is the maximum for `base.max`, so in this case it only rounds to 9 decimal places
<FromGitter> <Qwerp-Derp> This is probably not the best solution but I'm open to ideas before I make a PR
bonemind has joined #crystal-lang
rohitpaulk has joined #crystal-lang
alex`` has joined #crystal-lang
bonemind has quit [Ping timeout: 256 seconds]
duane has joined #crystal-lang
yaewa has joined #crystal-lang
moei has quit [Ping timeout: 245 seconds]
duane has quit [Ping timeout: 240 seconds]
gewo has quit [Quit: WeeChat 1.6]
yaewa has quit [Quit: Leaving...]
moei has joined #crystal-lang
bonemind has joined #crystal-lang
wojnar has joined #crystal-lang
return0e has quit [Read error: No route to host]
return0e has joined #crystal-lang
gewo has joined #crystal-lang
Ven`` has joined #crystal-lang
Ven`` has quit [Read error: Connection reset by peer]
Ven` has joined #crystal-lang
wuehlmaus has joined #crystal-lang
Papierkorb has joined #crystal-lang
bonemind has quit [Ping timeout: 256 seconds]
wojnar has quit [Remote host closed the connection]
duane has joined #crystal-lang
duane_ has joined #crystal-lang
duane has quit [Remote host closed the connection]
wojnar has joined #crystal-lang
<jokke> are there any "helpers" for porting ruby code to crystal?
<jokke> like somekind of half-automatic programs
<jokke> that crawl through the code and at least do the obvious stuff
maattdd_ has joined #crystal-lang
maattdd_ has quit [Ping timeout: 255 seconds]
bonemind has joined #crystal-lang
duane_ has quit [Quit: leaving]
Papierkorb has left #crystal-lang ["Konversation terminated!"]
<FromGitter> <spencerwi> Is there a roadmap or "crystal-devel" mailing list of some sort for Crystal? I always find it interesting to track the development of interesting languages, and Crystal is a pretty slick one.
gewo has quit [Ping timeout: 245 seconds]
shalmezad has joined #crystal-lang
<RX14> @spencerwi your best bet is watching the crystal github repo
gewo has joined #crystal-lang
<FromGitter> <Sija> @bew I tried different approach (https://play.crystal-lang.org/#/r/3nx7), yet unfortunately it doesn’t work :/
<FromGitter> <drosehn> jokke : You'll start out thinking that translating from ruby to crystal should be trivial, but the more you that you try that, the more you'll realize there are many issues to deal with. Any one issue might be trivial, but it's not trivial to solve all of them. Especially since the crystal language and stdlib are still changing.
Ven` has quit [Ping timeout: 240 seconds]
Ven`` has joined #crystal-lang
DTZUZU has quit [Ping timeout: 268 seconds]
maattdd_ has joined #crystal-lang
Ven`` has quit [Ping timeout: 256 seconds]
Ven`` has joined #crystal-lang
<jokke> DeBot: i know it's not trivial
<jokke> äh
<jokke> drosehn
DTZUZU has joined #crystal-lang
<FromGitter> <cserb> guys, I'm trying to access a value from a parsed json (`peer["ident"].as_s`) but I'm getting a weird error (which I can't reproduce in any other example)
<FromGitter> <cserb> Unhandled exception in spawn: ⏎ Expected Hash for # (key : String), not String (Exception) ⏎ from /usr/lib/crystal/json/any.cr:0:7 in '[]' ⏎ from src/avram.cr:108:15 in 'handle_new_peers' ⏎ from src/avram.cr:94:7 in 'handle_peer_response' ... [https://gitter.im/crystal-lang/crystal?at=5a99667c35dd17022e12034c]
Ven`` has quit [Ping timeout: 276 seconds]
<RX14> @cserb it means that `peer` is a JSON string
<RX14> since obviously "foo"["ident"] doesn't make sense you get an exception
Ven`` has joined #crystal-lang
<FromGitter> <cserb> @RX14 why would that be the case: `puts "+++++ #{typeof(peer["ident"].as_s)}"`
<FromGitter> <cserb> this works
<FromGitter> <cserb> if I remove `typeof()` I get the error
<RX14> because typeof doesn't actually do anything
<RX14> typeof asks the compiler "what is the type of this expression"
<RX14> the expression is never compiled
<RX14> or run
<RX14> or done anything with
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<RX14> typeof can never raise an exception because it's basically a constant
<FromGitter> <cserb> I'm super confused :) So you are saying `peer` is not a `JSON::any`
<RX14> no
<RX14> this is a runtime error
<RX14> typeof operates at compile-time
<RX14> the compiler has no idea what's in a JSON::Any
<FromGitter> <cserb> yeah sure. Let's forget about typeof. I just tried different things to find out what the problem is
<RX14> it could be a hash, a string, an array, the compiler has no idea
<RX14> when you do typeof(peer["ident"].as_s) you're asking the compiler what's the type of that expression
<RX14> the expression always compiles so the compiler replies "it's a string of course"
<RX14> but at runtime, if peer is not an object, then `peer["ident"]` will raise an exception
<RX14> and if `peer["ident"]` is not a string, `peer["ident"].as_s` will raise an exception
<RX14> the compiler has no idea what data is in the `peer` variable so it has no clue that those exceptions will be raised
<RX14> that's why it works
<RX14> the root cause is that `peer` is a JSON::Any containing a string
<RX14> but you're using `peer["ident"]` as if `peer` is a JSON::Any containing a Hash
<RX14> and it's not
<RX14> which is probably because you made a mistake further up your code
<RX14> or you read the structure of your JSON wrong
<RX14> or something
<FromGitter> <cserb> so assuming what you this should work: foo = JSON.parse(peer.as_s); foo["ident"].as_s
<RX14> I doubt it
<RX14> that would imply there's JSON inside a string inside json
<RX14> which I doubt there is
DTZUZU has quit [Ping timeout: 276 seconds]
<FromGitter> <cserb> but it did work
<RX14> then there's JSON in your JSON
<RX14> which is super weird
<RX14> can you show me what you're trying to parse?
<FromGitter> <cserb> ```code paste, see link```
<FromGitter> <cserb> This string I take and do a JSON.parse
<RX14> where are you getting this JSON from?
<RX14> because that JSON is super weird
<RX14> that's JSON encoded inside a string inside a json array
avdi has quit [Ping timeout: 240 seconds]
manveru has quit [Read error: Connection reset by peer]
<FromGitter> <cserb> Yes I realised this now as well...
<FromGitter> <cserb> Oh now I think I found my mistake
manveru has joined #crystal-lang
<FromGitter> <cserb> I'm creating it via to_json from a Hash
avdi has joined #crystal-lang
<RX14> so you must be calling to_json twice
<RX14> on the hash and on the array of strings
maattdd_ has quit [Ping timeout: 260 seconds]
<FromGitter> <cserb> nope
<RX14> well somehwere there's JSON encoding going on twice
<RX14> or you wouldn't get that output
<FromGitter> <cserb> ok so this is the line: ` a = "response|#{@avram_peer_repo.map {|peer| {ident: peer.ident, port: peer.port}}}"`
<FromGitter> <cserb> and I had ` a = "response|#{request}|#{@avram_peer_repo.map {|peer| {ident: peer.ident, port: peer.port}}.to_json}"`
<FromGitter> <cserb> it turns out I don't need the to_json...
maattdd_ has joined #crystal-lang
wojnar has quit [Remote host closed the connection]
wojnar has joined #crystal-lang
DTZUZU has joined #crystal-lang
<FromGitter> <cserb> hm ok so the correct way to do it is: `a = "response|#{@avram_peer_repo.map {|peer| {"ident" => peer.ident, "port" => peer.port}}.to_json}"`
<FromGitter> <cserb> this works now
<FromGitter> <cserb> many thanks @RX14
<RX14> you do need the to_json
<RX14> and the first and the last ones should be equivalent
<FromGitter> <cserb> with hash rocket I get `"[{\"ident\":\"2b781707-0d0f-428d-8867-17b2b0a5c740\",\"port\":12346}]"`
<FromGitter> <cserb> without: `"[{ident: \"d83a5cca-5961-48cb-8d82-cf7ceb8778de\", port: 12346}]"`
<RX14> "response|#{@avram_peer_repo.map {|peer| {ident: peer.ident, port: peer.port}}.to_json}"
<RX14> not for me
<FromGitter> <cserb> you are right
<RX14> oops
<FromGitter> <cserb> there is record support in crystal? I couldn't find this in the docs or api
bonemind has quit [Quit: WeeChat 2.0.1]
wojnar has quit [Remote host closed the connection]
<RX14> @cserb https://crystal-lang.org/api/master/toplevel.html#record(name,*properties)-macro
<RX14> it's in the "top level namespace" in the docs
maattdd_ has quit [Ping timeout: 256 seconds]
maattdd_ has joined #crystal-lang
<FromGitter> <bew> @Qwerp-Derp you can do `Int32::MAX` for the max value of an Int32
maattdd_ has quit [Ping timeout: 265 seconds]
<FromGitter> <Willamin> Anyone know why Crystal is wonky with unicode? ⏎ ⏎ ```"\xff".chars.first.bytes ⏎ => [255]``` [https://gitter.im/crystal-lang/crystal?at=5a9997430202dc012ea4ce40]
<pabs> my recollection is that it sasumes strings are valid unicode, and that's not a valid unicode string
<pabs> s/it sasumes/crystal assumes/
<FromGitter> <Willamin> oh I guess FF is a bad example
<FromGitter> <Willamin> same thing happens with EE
<FromGitter> <Willamin> is that also invalid unicode?
<FromGitter> <Willamin> hang on ... FF is valid: https://unicode-table.com/en/#00FF
<FromGitter> <Willamin> ```"\u{00ff}".chars.first.bytes ⏎ => [195_u8, 191_u8] ⏎ "\u{00ff}" ⏎ => "ÿ"``` [https://gitter.im/crystal-lang/crystal?at=5a999a63f3f6d24c682c6591]
duane has joined #crystal-lang
greengriminal has joined #crystal-lang
<FromGitter> <watzon> If I were to add `Enumerable#take` to the stdlib do you think it would get merged? Or is there already a method like that?
<FromGitter> <watzon> It would basically just need to wrap `Enumerable#take_while` by taking a number and returning everything up to that index.
<FromGitter> <watzon> Hmm never mind, I thought `take_while` returned an index
<FromGitter> <watzon> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a99a1e56fba1a703abec46d]
<FromGitter> <bew> You can do that with an iterator
<FromGitter> <bew> @watzon `ary.each.take 3` iirc
<FromGitter> <watzon> If so it's undocumented
<FromGitter> <watzon> Because `Iterator` seems to be lacking `take` as well. Both have `skip` but are missing `take`
<FromGitter> <bew> Right it's called `Iterator#first`
<FromGitter> <bew> Maybe it should be renamed? I don't know
rohitpaulk has quit [Ping timeout: 256 seconds]
duane has quit [Ping timeout: 256 seconds]
<FromGitter> <jwaldrip> How can I tell where this is happening? ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5a99b1098f1c77ef3a763eda]
<FromGitter> <jwaldrip> It looks like its happening in: Psykube::V2::Manifest::new<YAML::ParseContext, YAML::Nodes::Node+>
<FromGitter> <jwaldrip> But hard to find where
<FromGitter> <bew> which crystal ersion are you using?
<FromGitter> <bew> with 0.24.1 you should have a better trace iirc
<FromGitter> <watzon> Yeah feel like `Iterator#first` is kinda counterintuitive
<FromGitter> <watzon> I'd expect that to just return the first value
<FromGitter> <jwaldrip> I am using 0.24.1
<FromGitter> <bew> @watzon it is documented that it returns an iterator that would return the first or first N elements
<FromGitter> <bew> @jwaldrip hmm you're on macos maybe?
<FromGitter> <watzon> Yeah I see it now. I just feel like take makes more sense, especially in conjunction with skip. Or it could be both since skip and last seem to do the same thing.
<FromGitter> <bew> you can open an issue about that if you think there is room for discussion
<FromGitter> <jwaldrip> I am on macos
<FromGitter> <bew> I don't know it well, but iirc there is a way to have file & line number in traces, do you see what I'm taking about?
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
hightower has joined #crystal-lang
hightower has quit [Read error: Connection reset by peer]
greengriminal has quit [Quit: This computer has gone to sleep]
duane has joined #crystal-lang
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
shalmezad has quit [Quit: Leaving]
rohitpaulk has joined #crystal-lang
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
rohitpaulk has quit [Ping timeout: 256 seconds]
greengriminal has joined #crystal-lang
<FromGitter> <watzon> #5761
illy_ has quit [Read error: Connection reset by peer]
illy_ has joined #crystal-lang
duane has quit [Ping timeout: 268 seconds]
<FromGitter> <watzon> If you look at my github profile I think you can tell that Crystal is my favorite language
<FromGitter> <bew> Ahahah me too I think
<FromGitter> <watzon> @bew I think it's funny that you have Astral pinned and haven't done anything with it
<FromGitter> <watzon> Are you still planning on writing a PEG parser generator?
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 256 seconds]
<FromGitter> <bew> Yeah I know, it's not even written, just ideas & wish ˆˆ I don't know I have other projects in the work that have higher priority than astral for now
greengriminal has quit [Quit: This computer has gone to sleep]
alex`` has quit [Ping timeout: 256 seconds]