<FromGitter>
<JDsnyke> Hi guys I'm new, and running into the error ```no overload matches 'Slice(UInt8)#+' with type Slice(UInt8)``` with the code here - https://play.crystal-lang.org/#/r/88gp Any ideas on what I did wrong?
<FromGitter>
<tenebrousedge> `+` seems like it takes an int
<watzon>
Doesn't read_bytes just read the bytes as an Int?
<watzon>
There's also read_fully and such, but they read the bytes __into__ a Slice
<watzon>
I thought for sure File had a to_slice method, but it doesn't
<FromGitter>
<Blacksmoke16> :shrug:
<watzon>
I guess there's `gets_to_end` and then `to_slice`
<watzon>
Not really ideal, but I guess it works
<FromGitter>
<Blacksmoke16> isnt that what to_slice on file would do internally?
<FromGitter>
<Blacksmoke16> since the contents are just a string
<watzon>
I feel like `to_slice` usually just returns a pointer to the internal buffer, but idk
Vexatos has quit [Quit: ZNC Quit]
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 252 seconds]
_whitelogger has joined #crystal-lang
ur5us_ has quit [Ping timeout: 260 seconds]
_whitelogger has joined #crystal-lang
commavir has quit [Ping timeout: 248 seconds]
commavir has joined #crystal-lang
lvmbdv has joined #crystal-lang
ht_ has joined #crystal-lang
lvmbdv_ has joined #crystal-lang
lvmbdv has quit [Ping timeout: 260 seconds]
lvmbdv_ has quit [Read error: Connection reset by peer]
lvmbdv has joined #crystal-lang
ht_ has quit [Quit: ht_]
lvmbdv_ has joined #crystal-lang
lvmbdv has quit [Ping timeout: 258 seconds]
lvmbdv_ has quit [Quit: Leaving]
lvmbdv has joined #crystal-lang
lvmbdv has quit [Quit: Leaving]
lvmbdv has joined #crystal-lang
lvmbdv has quit [Read error: Connection reset by peer]
lvmbdv has joined #crystal-lang
DTZUZO has quit [Ping timeout: 248 seconds]
lvmbdv has quit [Quit: Leaving]
DTZUZO has joined #crystal-lang
tr0yb1t has quit [Ping timeout: 258 seconds]
watzon has quit [Remote host closed the connection]
<FromGitter>
<sclee15> Can a objects converted to Hash?
watzon has joined #crystal-lang
alexherbo2 has joined #crystal-lang
lvmbdv has joined #crystal-lang
lvmbdv_ has joined #crystal-lang
alexherbo24 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
lvmbdv_ has quit [Client Quit]
lvmbdv has quit [Ping timeout: 258 seconds]
<Yxhuvud>
Well, what kind of object do you want to transform to a hash?
Vexatos has joined #crystal-lang
alexherbo245 has joined #crystal-lang
alexherbo24 has quit [Ping timeout: 240 seconds]
<FromGitter>
<j8r> if there is `to_h`, you can, else you have to do it yourself
<FromGitter>
<j8r> for instance with a macro iterating over the ivars
<Yxhuvud>
I have no idea why you'd want to introduce macros as an answer to that question oO
<FromGitter>
<Daniel-Worrall> I know you can call methods on yielded arguments with a 1 liner like `[1,2,3].map(&.**) # => [2,4,9]`, but can I do something like using them as a parameter in a method call like if I have ⏎ ⏎ ```[1,2,3].map do |x| ⏎ my_method(x) ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5dfcb1c5c0c8ef301be3dc75]
<FromGitter>
<sclee15> @j8r Thank you.
<FromGitter>
<j8r> macros because I suppose you would like to have ivars of an objects represented as a Hash of key values?
<FromGitter>
<j8r> That's a big high assumption on my part
<FromGitter>
<Daniel-Worrall> You can just define to_h without macros depending on your need a
<FromGitter>
<j8r> of course
<FromGitter>
<Blacksmoke16> main benefit of the macro is you wouldnt have to update `#to_h` every time you add/remove a new ivar
<FromGitter>
<tenebrousedge> @Daniel-Worrall yes, use `&->obj.method(ArgClassName)`
<FromGitter>
<randiaz95> I am looking for the benefits of heredoc in the docs but it seems like its good for formatted strings like xml, json, or to put methods on multiline data
<FromGitter>
<randiaz95> I like less characters in my code lol
<FromGitter>
<Blacksmoke16> and thats not a formatted string? :p
<FromGitter>
<randiaz95> lol I handformated it
<FromGitter>
<tenebrousedge> I wonder how you would write that programmatically
<FromGitter>
<tenebrousedge> instead of hand-formatting
<FromGitter>
<Blacksmoke16> maybe thing of it as a matrix?
<FromGitter>
<randiaz95> Well, you would probably need to pass in a string "crystal"
<FromGitter>
<randiaz95> and have a hash with char to big letter
<FromGitter>
<thetrung> @tenebrousedge remind me of how I implemented asmrb gem :D
<FromGitter>
<thetrung> fun and easy
<FromGitter>
<tenebrousedge> nice 😄 when I started the Forth exercise I thought, "This is crazy, how can they expect people to do this?" but it's actually pretty simple at the core
HumanGeek has quit [Quit: Leaving]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
<FromGitter>
<christopherzimmerman> Since set is built on hash, can it be assumed that sets are also insertion ordered?
<FromGitter>
<tenebrousedge> yes
<FromGitter>
<Blacksmoke16> no
<FromGitter>
<tenebrousedge> why not?
<FromGitter>
<Blacksmoke16> because a set is a list of unordered values
<FromGitter>
<Blacksmoke16> just because the current implementation is ordered, you shouldn't reply upon that
<FromGitter>
<Blacksmoke16> as if the implementation changes to not use Hash your stuff would break
<FromGitter>
<Blacksmoke16> would be better to always assume a Set is unordered
<FromGitter>
<tenebrousedge> there are no plans to do that, however
<FromGitter>
<Blacksmoke16> no, but still better than having code based on false assumptions
<FromGitter>
<Blacksmoke16> that could change in the future, which would most likely be hard to fix
<FromGitter>
<tenebrousedge> no, it wouldn't be hard to fix. You could just switch to `Hash(T, nil)`
<FromGitter>
<tenebrousedge> the current `Set` implementation is not terribly complex
<FromGitter>
<Blacksmoke16> so just do that from the beginning and avoid having to fix anything in the first place if insertion order is needed
<FromGitter>
<Blacksmoke16> i just dont like the idea of relying on the private implementation of something that can be changed at anytime, breaking the code
<FromGitter>
<tenebrousedge> worrying about things that have a small likelihood of changing in the future is a distraction
ur5us_ has joined #crystal-lang
<FromGitter>
<tenebrousedge> any number of things can and will break in the future, that shouldn't stop you from writing code today
<FromGitter>
<Blacksmoke16> right but those would be marked as breaking, if the implementation of `Set` changes to not maintain insertion order it would not be breaking since the idea of a Set is things are not ordered in the first place
ur5us_ has quit [Read error: Connection reset by peer]
<FromGitter>
<Blacksmoke16> i agree that this case probably isnt that big of a deal, but why put a time bomb in your code when it could be easily avoided
<FromGitter>
<tenebrousedge> because there's no reason to believe that this will ever turn into a time bomb
<FromGitter>
<Blacksmoke16> if you say so
hightower4 has quit [Ping timeout: 240 seconds]
<FromGitter>
<kinxer> Also, a set as a concept is unordered, so you should write code that properly uses that concept. If you need ordering, you shouldn't use a set, because someone (even you) reading your code who sees a `Set` should be able to assume that its order doesn't matter simply due to the name.
<FromGitter>
<randiaz95> Right
<FromGitter>
<randiaz95> Array would be an ordered list of elements
DTZUZO has quit [Ping timeout: 265 seconds]
DTZUZO_ has joined #crystal-lang
<FromGitter>
<j8r> But `Hash` is meant to stay ordered, from what I ve read
<FromGitter>
<Blacksmoke16> correct
<FromGitter>
<Blacksmoke16> but just because `Set` uses `Hash` doesn't mean you should consider a `Set` to be ordered
<FromGitter>
<j8r> Too bad, what's wrong with an ordered Set
<FromGitter>
<Blacksmoke16> use a hash or an array then
<FromGitter>
<j8r> If one want an ordered set of unique values?
<FromGitter>
<watzon> I don't believe so because it's not constant unless you explicitly define what type the block is returning
livcd_ has quit [Quit: Lost terminal]
<FromGitter>
<randiaz95> Hey Black, when creating an empty text file in Crystal.. ⏎ ⏎ Do we need to explicitly put mode in File.new("example.txt", mode="w")? or is there a better way
<FromGitter>
<watzon> @randiaz95 you could just do `File.write("example.txt", "")`
<FromGitter>
<watzon> `#write` sets the mode automatically
<FromGitter>
<randiaz95> ;) thanks!
<FromGitter>
<randiaz95> I knew there was a better way
<FromGitter>
<wontruefree> @watzon that is a bummer because it limits some methods
<FromGitter>
<wontruefree> I see after looking though enumerable there are existing limitations like this
<FromGitter>
<watzon> Yeah it's the type system at work
<FromGitter>
<wontruefree> its interesting I want the typing but this seems like a gap in the grammar feature set
<FromGitter>
<watzon> I can't say for sure, but it might
<FromGitter>
<christopherzimmerman> Wouldn't it just be `U`, not `typeof(U)`?
<FromGitter>
<watzon> You're right, it would be haha
<FromGitter>
<watzon> Fixed
<FromGitter>
<christopherzimmerman> If you can search chat by users, Ary responded to a similar question I had about determining block return type.
<FromGitter>
<christopherzimmerman> I believe it was around 2 weeks ago
<FromGitter>
<watzon> I've had some cases where `forall` doesn't work as expected, so I can't guarantee results here. But it's the only way I can see it being possible right now.