ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.32.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
<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
<FromGitter> <tenebrousedge> Overloads are: ⏎ ⏎ 1) Slice(T)#+(offset : Int)
ur5us_ has quit [Ping timeout: 260 seconds]
<FromGitter> <JDsnyke> @tenebrousedge Thanks. How would I go about resolving the error though? Any ideas? Using an int instead of a string gives me ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dfc2626cf771f7708fa0963]
<FromGitter> <Blacksmoke16> as the error says, there isnt a method `to_slice` on `Int32`, meaning try just not calling `to_slice`?
<FromGitter> <Blacksmoke16> is the goal here just to encrypt/decrypt a password or something?
<FromGitter> <tenebrousedge> looks like it's not their code that's calling `to_slice`
<FromGitter> <JDsnyke> This is from openssl.cr
<FromGitter> <tenebrousedge> I'm feeling the need for a Crystal OpenSSL encryption/decryption tutorial <__<
<FromGitter> <JDsnyke> @Blacksmoke16 encrypt / decrypt a string
<FromGitter> <Blacksmoke16> its deff quite low level atm
<FromGitter> <Blacksmoke16> it could use an abstraction to have a more friendly api thats for sure
ur5us_ has joined #crystal-lang
watzon has joined #crystal-lang
<watzon> Wow is there really no simple, built in way to open a file as a Bytes instance?
<watzon> I thought there was
<FromGitter> <Blacksmoke16> well if you open the file you have access to IO methods
<FromGitter> <Blacksmoke16> so could do https://crystal-lang.org/api/master/IO.html#read_bytes(type,format:IO::ByteFormat=IO::ByteFormat::SystemEndian)-instance-method ?
<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> <tenebrousedge> ```[1, 2, 3].map(&->puts(Int32))```
<FromGitter> <tenebrousedge> but at last check it has some open bugs
<FromGitter> <tenebrousedge> ```a = 15 ⏎ [3, 5, 7].map(&->a.divisble_by?(Int32)) ⏎ #=> non-deterministic behavior``` [https://gitter.im/crystal-lang/crystal?at=5dfcd2a6cf771f7708fe7ac7]
alexherbo2453 has joined #crystal-lang
alexherbo245 has quit [Ping timeout: 268 seconds]
<FromGitter> <randiaz95> Im doing Introduction to Programming with Java by Daniel Liang in Crystal ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dfcdc69e0131f50c97829c9]
<FromGitter> <randiaz95> Going to be fun lol
<FromGitter> <Blacksmoke16> prob better to use a heredoc for that
<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> <randiaz95> ```CCCCC ⏎ C ⏎ CCCCC ⏎ "`````` [https://gitter.im/crystal-lang/crystal?at=5dfcde0dc5a23938b4516c3c]
<FromGitter> <tenebrousedge> a matrix, probably. Maybe there's some way to compress it, too
<FromGitter> <randiaz95> Guys, why do we have proc as a clojure if we use |x| x+x for inline lambda type function
<FromGitter> <tenebrousedge> because sometimes you don't want to use the proc in-line
<FromGitter> <tenebrousedge> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dfcdecec0c8ef301be51ac5]
<FromGitter> <randiaz95> you can use |x| x*x as a hash value?
lvmbdv has joined #crystal-lang
<FromGitter> <tenebrousedge> you can write it as `Proc(Stack, Stack).new {|s| ... }` if you like
<FromGitter> <tenebrousedge> but yes
alexherbo24531 has joined #crystal-lang
alexherbo2453 has quit [Ping timeout: 265 seconds]
<FromGitter> <randiaz95> coolio
duane has quit [Ping timeout: 268 seconds]
duane has joined #crystal-lang
<FromGitter> <absolutejam_gitlab> @randiaz95 Procs and blocks aren't equivalent either
<FromGitter> <absolutejam_gitlab> https://www.youtube.com/watch?v=5rpZOtcCHtk
return0__ has joined #crystal-lang
return0e_ has quit [Ping timeout: 268 seconds]
duane has quit [Ping timeout: 260 seconds]
ht_ has joined #crystal-lang
duane has joined #crystal-lang
<FromGitter> <tenebrousedge> good to know
lvmbdv has quit [Quit: Leaving]
<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> <Blacksmoke16> im not saying there's anything wrong with an ordered set, im saying what @kinxer said ☝️ December 20, 2019 2:15 PM (https://gitter.im/crystal-lang/crystal?at=5dfd1decd2dadb38934e57e4)
<FromGitter> <j8r> ha ok
<FromGitter> <Blacksmoke16> i.e. if it should be ordered you shouldn't use the `Set` type in the first place
<FromGitter> <j8r> so having potentially a `OrderedSet` object doesn't make sense
<FromGitter> <j8r> Usually `Array` do the job.
<FromGitter> <Blacksmoke16> `arr << value unless arr.includes? value`
<FromGitter> <j8r> I had a case that there shouldn't have any duplicates, but if there is one it is not a big deal
<FromGitter> <Blacksmoke16> prob not as fast as hash lookups tho
<FromGitter> <tenebrousedge> I would just do `alias OrderedSet = Set` for the moment and change the implementation if `Set` ever changes its behavior
return0__ has quit [Remote host closed the connection]
return0e has joined #crystal-lang
duane has quit [Ping timeout: 258 seconds]
<FromGitter> <randiaz95> Hi guys, is there a non-os specific way to join path?
<FromGitter> <randiaz95> for example in python: os.path.join("dir1", "dir2"..)
duane has joined #crystal-lang
<FromGitter> <randiaz95> Seems like new is for *nix systems
<FromGitter> <randiaz95> but that's fine.. I am on a mac
<FromGitter> <Blacksmoke16> it knows what OS you're on to use
duane has quit [Ping timeout: 268 seconds]
<FromGitter> <Blacksmoke16> that it was compiled for at least
<FromGitter> <randiaz95> Ah.. interesting, so if I push my code into a linux server but I was on a mac, I would need to recompile my code?
<FromGitter> <Blacksmoke16> no it should work
<FromGitter> <randiaz95> 1) o cool
<FromGitter> <Blacksmoke16> i think
<FromGitter> <tenebrousedge> linux and mac both use the same (POSIX) path scheme
alexherbo24531 has quit [Quit: The Lounge - https://thelounge.chat]
sagax has quit [Ping timeout: 265 seconds]
sagax has joined #crystal-lang
<FromGitter> <watzon> @jemc do you happen to be in here?
<FromGitter> <jemc> I don't often log into gitter, but since you requested it in the crystal-pegmatite issue ticket, I hopped on :D
<FromGitter> <jemc> @watzon ^
<FromGitter> <watzon> Awesome haha. I'll send you a PM.
<FromGitter> <wontruefree> is there a way to get the return type form a block?
<FromGitter> <wontruefree> ```def foo(&block : Array(T) ->) ⏎ x = Array(typeof(&block.return_type)).new ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5dfd3bf0d2dadb38934f34a9]
<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
duane has joined #crystal-lang
sorcus has quit [Ping timeout: 252 seconds]
gangstacat has quit [Quit: Ĝis!]
<FromGitter> <watzon> Ahhh you know what might work @wontruefree? ⏎ ⏎ ```def foo(&block : Array(T) -> U) forall U ⏎ x = Array(typeof(U)).new ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5dfd4626c5a23938b4545a2f]
<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.
<FromGitter> <christopherzimmerman> Found the start of it (https://gitter.im/crystal-lang/crystal?at=5de27b1eb065c6433c12027f)
<FromGitter> <christopherzimmerman> Direct link to Ary's reply (https://gitter.im/crystal-lang/crystal?at=5de27b1eb065c6433c12027f)
sagax has quit [Ping timeout: 268 seconds]
<FromGitter> <wontruefree> awesome thanks :)
<FromGitter> <wontruefree> I dont think I really understood why that syntax was used but that makes so much more sense now
ht_ has quit [Quit: ht_]
gangstacat has joined #crystal-lang