daemonwrangler has quit [Quit: ZNC 1.8.2 - https://znc.in]
hendursa1 has joined #crystal-lang
hendursaga has quit [Ping timeout: 240 seconds]
Human_G33k has quit [Ping timeout: 240 seconds]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Ping timeout: 265 seconds]
<FromGitter>
<HertzDevil> there are no specs for `JSON::ArrayConverter` 😳
<yxhuvud>
postmodern: I doubt it matters. perhaps one of the latter two if you think there is a risk of accidentally changing it but otherwise I'd probably keep it simple.
<FromGitter>
<HertzDevil> `Tuple` has a hardcoded size limit of 300 and it's unfit for homogeneous data
<FromGitter>
<HertzDevil> and to my knowledge none of the other two will generate constants on the llvm side
alexherbo2 has joined #crystal-lang
hightower2 has joined #crystal-lang
<hightower2>
Hey when I add current bintray's debian repo, how do I access the 0.36.1 package? in the stable distro only 1.0.0 seems to be available
<hightower2>
interesting, when I did apt show crystal |grep Ver , only 1.0.0 was displayed
<hightower2>
will review
<straight-shoota>
I suppose it only shows the latest version
<straight-shoota>
apt install crystal=0.36.1 should install it
<hightower2>
I did that, it didn't install, saying version 0.36.1 was not found (which was expected, because Version in show does show all available versions)
<straight-shoota>
`apt show crystal` shows only the latest, you need `apt show crystal -a` to show older releases
<hightower2>
interesting... not sure why I had it remembered wrong... in any case figured it out, the exact version was 0.36.1-1
<straight-shoota>
Perhaps you need to specify the package version: apt install crystal=0.36.1-1
<hightower2>
(just like 1.0.0. is 1.0.0-1)
<hightower2>
Yes. great, thanks for the discussion as always
HumanG33k has joined #crystal-lang
hsh has quit []
hsh has joined #crystal-lang
alexherbo27 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo27 is now known as alexherbo2
postmodern has joined #crystal-lang
<postmodern>
https://carc.in/#/r/aw26 interesting that crystal will automatically type cast literals to the necessary underlying type
<FromGitter>
<HertzDevil> this happens when there is no ambiguous match
<postmodern>
if i want to specify an argument is a positive length, what type should I use? Int, Int32, Int::Unsigned, UInt32?
<FromGitter>
<Blacksmoke16> `raise ArgumentError.new "Value must be positive" if value < 0`
<FromGitter>
<Blacksmoke16> and prob just use `Int`
<postmodern>
would be nice if we had a Size type that did that i < 0 check automatically
<postmodern>
looks like Array.new does a negative check, but there's still a possibility a negative value could be passed to some other sensitive function
<FromGitter>
<Blacksmoke16> possibly
<straight-shoota>
I'd say almost certainly
<straight-shoota>
It's not just integers. Any kind of param can have value constraints that are not properly validated
<FromGitter>
<HertzDevil> seems like a call for contracts
<straight-shoota>
yeah
<FromGitter>
<HertzDevil> ~~which i'm glad they didn't make it into c++20~~
<straight-shoota>
you lose a lot of simplicity going that way
<postmodern>
i notice crystal code will preallocate arrays/sets when copying in Indexable values. is there also a perform difference between #<< and #[]= when populating preallocated arrays/sets?
<straight-shoota>
you can't really use []= with a preallocated array
<FromGitter>
<HertzDevil> preallocating a container isn't the same thing as giving it a size
<postmodern>
ah not sure what the term is for allocating with a size/capacity
<straight-shoota>
if you give it a size, you also need to initialize every value in that size
<straight-shoota>
for example `Array.new(10, nil)` initializes an array with 10 nils
<straight-shoota>
Array.new(10) just allocates the space, but it doesn't have any value, size is zero
<FromGitter>
<HertzDevil> which imo isn't a good interface
<postmodern>
right, i was thinking about getting rid of passing in Ranges and instead splatting them, but if literal splats aren't supported i'll have to go back to accepting unsplatted Range values
<postmodern>
yeah, i'm porting some very old ruby code (some of my first). i guess my goal was to write an interface for representing ABNF char ranges, which could be written as a sequence of chars, bytes, or even contain ranges in between
<postmodern>
an annoying aspect of porting old ruby code to crystal, is you start getting ideas of how to improve it's interfaces, but you have to stay focused on the task of porting first before you go and start working on a 1.0.0 branch
<postmodern>
https://carc.in/#/r/aw3j so why isn't Range(Byte, Byte) matching Range(UInt8, UInt8), if Byte is aliased to Int::Unsigned? Shouldn't that encompass UInt8?
<FromGitter>
<Blacksmoke16> `Int::Unsigned` is a union of all `U*` types not just `UInt8`
<postmodern>
so Range(T1|T2, T1|T2) won't necessarily match Range(T2, T2) ?
<FromGitter>
<Blacksmoke16> thats my understanding yes
<FromGitter>
<HertzDevil> yes, because `Range` isn't covariant
<FromGitter>
<HertzDevil> the only types that do this are `Tuple` and `NamedTuple`
<FromGitter>
<HertzDevil> also i fixed `typeof(tup.first)` in that pr
alexherbo2 has quit [Read error: Connection reset by peer]
alexherbo2 has joined #crystal-lang
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Read error: Connection reset by peer]
f1refly has quit [Read error: Connection reset by peer]
DTZUZU has joined #crystal-lang
f1refly has joined #crystal-lang
DTZUZU_ has quit [Ping timeout: 252 seconds]
f1refly has quit [Remote host closed the connection]
f1refly has joined #crystal-lang
hsh has quit []
_ht has quit [Remote host closed the connection]
hsh has joined #crystal-lang
hsh has quit [Client Quit]
<FromGitter>
<vectorselector> Hello :) I have a Crystal 0.35.1 related-question about Array.map in 2 dimensions. ⏎ I have a user-ID that gets mangled by a section of code in a controller, such that subsequent usage of that user-ID returns what looks like a hex-color value, which I'm presuming means that I overwrote/overflowed something in memory..mapping over an array of about 2500 objects
<FromGitter>
<vectorselector> The section of code in question maps over an array of about 2500 objects, and then maps across each ones "category" array, which can be from 1-10 items, so an Array.map{|item| item["category"].map{|cat| list_of_cat_ids << cat["id"] }} or something like this
<FromGitter>
<vectorselector> so my question is: if I don't care about the documents and only about my final collated list (throw away the docs, who cares) ⏎ what is the most memory-efficient Array.method to use for iterating with the least memory usage?
<FromGitter>
<jrei:matrix.org> why 0.35.1?
<FromGitter>
<vectorselector> still on it
<FromGitter>
<vectorselector> is this a known bug/fix?
<FromGitter>
<jrei:matrix.org> you was able to reproduce the issue with a small code?
<FromGitter>
<jrei:matrix.org> but sure, map is no efficient
<FromGitter>
<jrei:matrix.org> it created intermediary arrays
<FromGitter>
<jrei:matrix.org> you could use `map` at first, then `map!` to mutate the copied array
<FromGitter>
<vectorselector> no, it's a cumulative effect of much bloat on the same page. this particular code-block is perhaps the part that pushes me over the edge, ⏎ ah ok, so map makes a copy, interesting. so I see that map! mutates the copy, but is it still a copy right?
<FromGitter>
<jrei:matrix.org> it mutates the left hand object, in this case the copy done by `#map`
<FromGitter>
<vectorselector> ok! thank you.
<FromGitter>
<vectorselector> so, if i start with original array, and only use map! I will have zero copies?
<FromGitter>
<jrei:matrix.org> in your example it will "just" prevent one copy vs 2, so I doubt it will makes much difference
<FromGitter>
<jrei:matrix.org> one cool thing I recommend you also is to click on [source] in the API docs
<FromGitter>
<vectorselector> i mean, not possible to Array.map!{|item| item["category"].map!{|cat| list_of_cat_ids << cat["id"] }}
<FromGitter>
<jrei:matrix.org> if you want to mutate `Array`
<FromGitter>
<jrei:matrix.org> (the variable)
<FromGitter>
<jrei:matrix.org> why not use `#each`?
<FromGitter>
<jrei:matrix.org> also, not sure to understand the code
<FromGitter>
<vectorselector> 1) i was confused by each_combination and permutations etc... not sure what it did exactly ⏎ 2) I thought each was alias for map, and it's not in 0.35.1 apparently... https://crystal-lang.org/api/0.35.1/Array.html ⏎ but what is the difference between each and map, please?
<FromGitter>
<jrei:matrix.org> map was never an alais to each
<FromGitter>
<jrei:matrix.org> I mean, you can see the underlying code and the API docs comments
<FromGitter>
<vectorselector> ah! thank you. I see each in Enumerable, not in Array.
<FromGitter>
<jrei:matrix.org> using #map without assigning to a variable is definitely a waste
<FromGitter>
<vectorselector> got it, I was ready to try a for-loop, lol
<FromGitter>
<vectorselector> thank you J8r
<FromGitter>
<jrei:matrix.org> anyway in your case, you've already an existing array: each can be used
<FromGitter>
<jrei:matrix.org> #each is like a for loop
<FromGitter>
<vectorselector> excellent!
<FromGitter>
<vectorselector> thank you
<FromGitter>
<jrei:matrix.org> no problem, glad to help
<FromGitter>
<vectorselector> that solved the issue. i'm not overflowing my memory anymore. boom.
daemonwrangler has joined #crystal-lang
alexherbo27 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 265 seconds]
alexherbo27 is now known as alexherbo2
<postmodern>
is there a short hand for zeroing out a StaticArray?