ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.31.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
duane has joined #crystal-lang
absolutejam2 has quit [Ping timeout: 240 seconds]
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
<FromGitter> <greenbigfrog> Is there a method for to get a int result when dividing 2 ints?
<FromGitter> <Blacksmoke16> `//`
<FromGitter> <greenbigfrog> Thanks. Shouldn
<FromGitter> <greenbigfrog> 't this be listed at https://crystal-lang.org/reference/syntax_and_semantics/operators.html ?
<FromGitter> <Blacksmoke16> will be as part of https://github.com/crystal-lang/crystal-book/pull/370
<FromGitter> <sam0x17> if there is ever anything in DC or baltimore I will 100% go
<FromGitter> <greenbigfrog> wow. Thanks @straight-shoota
<FromGitter> <sam0x17> side note: don't ever do what I just did and move from somewhere where the area code is (e.g.) `ABC` to a place where the area code is `ACB`.. it complicates pizza arriving
<FromGitter> <christopherzimmerman> If the meetup in Chicago is small, I doubt there is a meetup in central Texas, but who knows, maybe someday.
dwdv_ has quit [Ping timeout: 268 seconds]
<FromGitter> <christopherzimmerman> Is the Help and Support section of the forum appropriate for code review requests?
<FromGitter> <Blacksmoke16> Is it a lot?
<FromGitter> <christopherzimmerman> No, just a small iterator class.
<FromGitter> <tenebrousedge> we do code review
<FromGitter> <tenebrousedge> mostly we say, "zomg it's awful, take it away! make it stop!"
<FromGitter> <tenebrousedge> but we're happy to go into detail :P
<FromGitter> <christopherzimmerman> Ha, luckily I am aware my crystal coding style sucks, this is more of an algorithmic review :)
<FromGitter> <watzon> Lmao
<FromGitter> <christopherzimmerman> Here is a gist (https://gist.github.com/christopherzimmerman/614a90bc07b6613b8fa708ae3f021e09). I am trying to speed up the `next` method considerably.
<FromGitter> <christopherzimmerman> I have a lot of optimizations for contiguous iteration, but the n-dimensional case is slowing me down a ton.
chachasmooth has quit [Ping timeout: 276 seconds]
chachasmooth has joined #crystal-lang
<FromGitter> <ImAHopelessDev_gitlab> `15356.08× slower`
<FromGitter> <ImAHopelessDev_gitlab> dang
<FromGitter> <christopherzimmerman> That’s just computing setup costs to the actual operation so I can account for it. I only need to speed the operation up by about 3x for it to be competitive with other numerical libraries.
<FromGitter> <watzon> Ouchy
ht_ has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
ht_ has quit [Quit: ht_]
DTZUZO has quit [Ping timeout: 265 seconds]
absolutejam2 has joined #crystal-lang
tankf33der has joined #crystal-lang
DTZUZO has joined #crystal-lang
DTZUZO has quit [Remote host closed the connection]
absolutejam2 has quit [Ping timeout: 240 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 268 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 265 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 246 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 240 seconds]
repo has quit [Quit: WeeChat 2.5]
repo has joined #crystal-lang
alexherbo2 has joined #crystal-lang
repo has quit [Quit: WeeChat 2.5]
repo has joined #crystal-lang
<FromGitter> <asterite> what's the idea behind that iterator? (what is it supposed to be doing?)
duane has quit [Ping timeout: 268 seconds]
absolutejam2 has joined #crystal-lang
<FromGitter> <christopherzimmerman> @asterite access a strided array. For example, if I have the array: ⏎ ⏎ ```[[0 1 2] ⏎ [6 7 8]]``` [https://gitter.im/crystal-lang/crystal?at=5dbc2eb62a6494729c7b38ba]
duane has joined #crystal-lang
duane has quit [Remote host closed the connection]
absolutejam2 has quit [Ping timeout: 276 seconds]
duane has joined #crystal-lang
<FromGitter> <christopherzimmerman> If the array can be treated as flat, a different `next` method gets chosen that just increments by the final stride, and that one is as fast as I would expect, I'm just dealing with the ND case now, and I haven't had any luck improving performance since I came up with the algorithm.
<FromGitter> <christopherzimmerman> I am hoping I have poorly optimized crystal code rather than a poor algorithm :D
<FromGitter> <kinxer> @ImAHopelessDev_gitlab My point yesterday was what @Blacksmoke16 said: `some_array.shuffle!` is better than `some_array = some_array.shuffle`.
duane has quit [Ping timeout: 240 seconds]
<Yxhuvud> for the n-dimensional case, are you iterating in a sensible order with regards to actual layout in memory? for example, in the two dimensional case, iterating over it with one order of dimensions can have vastly different performance than the other order.
<FromGitter> <christopherzimmerman> Yes. The 2D case is handled a bit differently, by simply using the leading dimension rather than explicit strides. But for the nd-case, I both store and access in row-major order.
<FromGitter> <bajro17> is it possible get index of "test".count { |i| } without extra variable
<FromGitter> <Blacksmoke16> what do you want to do?
<FromGitter> <bajro17> I want compare like this
<FromGitter> <bajro17> ```a = "tets" ⏎ "test".count { |i| a[i.index] == i }``` [https://gitter.im/crystal-lang/crystal?at=5dbc3a2afb4dab784a44fa96]
<FromGitter> <bajro17> to I get 2
<FromGitter> <Blacksmoke16> sorry i still dont follow
<FromGitter> <bajro17> I want compare 2 strings
<FromGitter> <Blacksmoke16> want to count the unique characters that are in both strings?
<FromGitter> <bajro17> to get number of characters on same position
<FromGitter> <Blacksmoke16> ah ok
<FromGitter> <Blacksmoke16> gotcha
<FromGitter> <bajro17> I do it with "test".each_char_with_index
<FromGitter> <bajro17> but instructor say I can make program shorter with Enumerable#count
<FromGitter> <christopherzimmerman> You could use `each_char` maybe? ⏎ ⏎ ```a = "tets".each_char ⏎ "test".count { |i| i == a.next }``` [https://gitter.im/crystal-lang/crystal?at=5dbc3b6b9825bd6bac097db6]
<FromGitter> <christopherzimmerman> Only if you know they are the same length I guess.
<FromGitter> <tenebrousedge> interesting choice to use the iterator like that
<FromGitter> <tenebrousedge> but you'd probably need `"test".each_char.count`
<FromGitter> <christopherzimmerman> If you use an iterator, you can compare strings that aren't the same length and still check at positions.
<FromGitter> <tenebrousedge> huh, String implements `count` directly
<FromGitter> <tenebrousedge> interesting
<FromGitter> <tenebrousedge> generally, I'd prefer using `zip` here
<FromGitter> <Blacksmoke16> `"tets".size - Levenshtein.distance("tets", "test")` :p
<FromGitter> <kinxer> @Blacksmoke16 Get out of here with your cheating. :P
<FromGitter> <bajro17> :D
teardown has quit [Quit: leaving]
teardown has joined #crystal-lang
teardown has left #crystal-lang [#crystal-lang]
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
<FromGitter> <ImAHopelessDev_gitlab> @kinxer oh yeah, i've used shuffle! a couple times.
<FromGitter> <ImAHopelessDev_gitlab> Good morning!!
<FromGitter> <ImAHopelessDev_gitlab> https://play.crystal-lang.org/#/r/7xog/edit wow, didn't know we could do [0, 2] syntax on an array. found out by looking at source of `first` 😍
<FromGitter> <kinxer> Good morning. :)
<FromGitter> <tenebrousedge> @ImAHopelessDev_gitlab I often prefer `slice`
<FromGitter> <ImAHopelessDev_gitlab> oh yeah letme check it out
<FromGitter> <tenebrousedge> you can also use `arr[0..3]` if you have a range of indexes you're after
<FromGitter> <tenebrousedge> but I almost always end up using `arr.first(n)` or `last(n)`
<FromGitter> <ImAHopelessDev_gitlab> damn working with arrays are very easy in crystal. so many nice methods and functionality, it really helps me a lot
<FromGitter> <tenebrousedge> :plus1:
<FromGitter> <wontruefree> @Blacksmoke16 I will look into the link but you can also see the event here https://www.meetup.com/Crystal-Lang-Chicago/events/bbhsjryzpbkb/
<FromGitter> <wontruefree> thank you for letting me know though
<FromGitter> <Blacksmoke16> np
<FromGitter> <wontruefree> @christopherzimmerman I think there is one that has been or will be started up in seattle
<FromGitter> <wontruefree> that is also why we try to make the meetup remote friendly
HumanG33k has joined #crystal-lang
duane has joined #crystal-lang
tankf33der has left #crystal-lang [#crystal-lang]
<FromGitter> <ilanpillemer> how do you work out what to require?
<FromGitter> <tenebrousedge> hmm?
<FromGitter> <ilanpillemer> In order to use something. Is there a rule?
<FromGitter> <ilanpillemer> for example Digest::MD5
<FromGitter> <tenebrousedge> the module name is usually a good one
<FromGitter> <ilanpillemer> do you have to guess?
<FromGitter> <jacobsun> hi, %Q with string means what?
<FromGitter> <jacobsun> The doc says "while %Q has the same meaning as %." I didn't get what this means
<FromGitter> <tenebrousedge> it's just a normal string
<FromGitter> <tenebrousedge> it's the opposite of `%q` which disables interpretation
<FromGitter> <jacobsun> So it is the same with double quotes, right?
<FromGitter> <tenebrousedge> yes, but it can be more convenient if your string has double quotes in it
<FromGitter> <jacobsun> Thanks.
ht__ has joined #crystal-lang
alexherbo2 has joined #crystal-lang
<FromGitter> <ilanpillemer> can you use back referecens in Crystal regex?
<FromGitter> <tenebrousedge> yes
<FromGitter> <ilanpillemer> `/(.)\1{3}/ =~ value`
<FromGitter> <ilanpillemer> do I have to enable something?
<FromGitter> <tenebrousedge> no?
<FromGitter> <ilanpillemer> so that should match any string with the three repeating chars?
<FromGitter> <ilanpillemer> `puts /(.)\1{3}/ =~ “0034e0923cc38887a57bd7b1d4f953df"`
<FromGitter> <ilanpillemer> is not finding a match
<FromGitter> <kinxer> That'll match any string with four repeating characters.
<FromGitter> <ilanpillemer> not three?
<FromGitter> <kinxer> No, because `(.)` matches one.
<FromGitter> <ilanpillemer> aha!
<FromGitter> <ilanpillemer> thanks
<FromGitter> <ilanpillemer> regex is quite a thing
<FromGitter> <kinxer> No problem.
<FromGitter> <ilanpillemer> `jwz`has a point
<FromGitter> <tenebrousedge> please don't say that
<FromGitter> <tenebrousedge> `jwz` is a jerk who likes to fling mud
<FromGitter> <tenebrousedge> for a number of years he set up his server so that any links to his site from HN would redirect you to an image of hairy testicles
<FromGitter> <tenebrousedge> this may still be the case
<FromGitter> <kinxer> Yeah, I had to look up who you're talking about, but a quick look through his WikiQuotes page doesn't leave me encouraged about his character.
dwdv_ has joined #crystal-lang
<FromGitter> <greenbigfrog> Any reason why `Regex::MatchData#first` doesn't exist?
<FromGitter> <greenbigfrog> `"ABC CDF".scan(/\b\S/).map { |x| x[0]}.join` is there a more efficient/better looking way of getting the first character of each word in a string?
<FromGitter> <tenebrousedge> `"ABC CDF".scan(/\b\S/).join &.[0]` is probably as close as you get
<FromGitter> <greenbigfrog> Thanks
<FromGitter> <tenebrousedge> you could also use an `Iterator` and `string_scanner`
<FromGitter> <tenebrousedge> but that's probably overengineering things
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
return0e_ has joined #crystal-lang
duane has quit [Ping timeout: 240 seconds]
<hightower3> Hey folks did option "API" disappear from the menu at top of https://crystal-lang.org/ ?
<FromGitter> <kinxer> Yes. It's under "Docs" now (along with the GitBook documentation).
<hightower3> thanks
<FromGitter> <kinxer> I'm a little torn, since I think it makes the website a little more cleaner visually, but it also slows me down.
<hightower3> just to confirm, the discussion from the other day was correct in saying that the best way to alias a method to a different name is to define a new method (with different name) and call the real one one?
<FromGitter> <tenebrousedge> apparently
<hightower3> yeah, the removed alias_method macro seemed to do exactly that
<FromGitter> <tenebrousedge> nothing stopping you from using the macro, either
<hightower3> yes, will use it
<hightower3> Is there a way to use this custom "alias_method" macro either directly before (like documentation) or directly after the method definition, so that it automatically knows which function is being aliased and that I don't have to repeat the name?
<FromGitter> <tenebrousedge> maybe. Ask @Blacksmoke16
ht__ has quit [Quit: ht__]
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <tenebrousedge> can you detect the last method defined in a macro?
<FromGitter> <tenebrousedge> or the next?
<FromGitter> <Blacksmoke16> yea prob
<FromGitter> <Blacksmoke16> `method[idx + 1]`?
<FromGitter> <tenebrousedge> o__o
<FromGitter> <Blacksmoke16> where `methods` is the array of methods
<hightower3> fabulous
<hightower3> macro alias_method(new) {{ method[idx+1] }} #=> undefined macro variable 'method'. I see {{method...}} used in crystal's sources, what might be missing in my case?
<hightower3> ah it's only used as variable that's previously defined, not as magic word
<FromGitter> <Blacksmoke16> i mean its more code than that
<hightower3> maybe 'methods'
<FromGitter> <Blacksmoke16> would have to do like ⏎ `{% methods = @type.methods %}`
<hightower3> yeah. just gotten to that, thanks!
<FromGitter> <Blacksmoke16> then could find the one you want, then get the next one
<hightower3> yes, yes, I see an example in spec/compiler/codegen/macro_spec.cr
<FromGitter> <Blacksmoke16> 👍
<hightower3> Got it, seems great, macro alias_previous(new_name) alias_method new_name, {{@type.methods[-1].name}} end
<FromGitter> <tenebrousedge> nice :plus1:
duane has joined #crystal-lang
Nekka has quit [Ping timeout: 268 seconds]
absolutejam2 has joined #crystal-lang
Nekka has joined #crystal-lang
<FromGitter> <bew> I'd suggest `.last` instead of `[-1]` for clarity
<hightower3> hehe was thinking about it, will do, thanks
<FromGitter> <Blacksmoke16> Well won't that just alias the last method all the time?
<hightower3> Yes, after I define a method, I follow it immediately with alias_previous(new_name)
<hightower3> So this way I don't have to mention new and old name on each line
<hightower3> Also for cases when some methods have multiple aliases, I've changed the macro to do a for loop, so now it supports alias_previous n1, n2, n3
<FromGitter> <Blacksmoke16> Ok