ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
<FromGitter> <riffraff169> the skills are static based on stats....as far as i know the information hasnt changed in years....but people play the game and use this program to calculate values rather than do it by hand
<FromGitter> <riffraff169> there is a version in java that i have
<FromGitter> <riffraff169> im converting to crystal for 2 reasons at least.....native linux version i guess, and crystall programming experience
<FromGitter> <riffraff169> a programming project for me....i havent done any real serios programming for a hobby in years, too busy doing more infrastructure stuff
<FromGitter> <riffraff169> that works great, thanks...i see where i went wrong
<FromGitter> <riffraff169> i might just have a bunch of constants with that, like `Activities["VS"] = blah` and another line with another key...unless there is a better way
hendursa1 has joined #crystal-lang
<FromGitter> <tenebrousedge> I think you need named tuples
<FromGitter> <tenebrousedge> or to just make the key part of your yaml data
chachasmooth has quit [Ping timeout: 260 seconds]
chachasmooth has joined #crystal-lang
chachasmooth has quit [Ping timeout: 245 seconds]
chachasmooth has joined #crystal-lang
postmodern has quit [Quit: Leaving]
hendursa1 has quit [Ping timeout: 240 seconds]
hendursa1 has joined #crystal-lang
_ht has joined #crystal-lang
<FromGitter> <rishavs> What does `def lines(chomp = true)` do? The documentation on it is missing. ⏎ I need to get the first line in a large string and was wondering if I should use this or just go with partition
<FromGitter> <naqvis> @rishavs this returns array of lines, `chomp` to flag whether to remove newline character or not
<FromGitter> <rishavs> Thanks as usual, Ali!
<FromGitter> <naqvis> 👍
<FromGitter> <naqvis> > I need to get the first line in a large string and was wondering if I should use this or just go with partition ⏎ ⏎ better go with `each_line(chomp = true)` to get the iterator for lazy loading
<FromGitter> <naqvis> as `lines` will load all lines even if you just care for 1st line
<FromGitter> <rishavs> ❤️
<straight-shoota> @naqvis: Most efficient is probably `string.byteslice(0..string.index("\n"))`
<FromGitter> <naqvis> Thanks straight-shoota and totally agree with your recommendation. My recommendation was based on the context of `lines` or the context which I understood from the original question
<FromGitter> <zorgon_peterson:matrix.org> hi does crystal lang have `include` to include module functions into class like ruby?
<FromGitter> <erdnaxeli:cervoi.se> Yes
<FromGitter> <zorgon_peterson:matrix.org> is it not defined on all objects? I tried to use it in this line to dynamically include functions from different module, but I got an error ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=6086a89a06e2e024e87834db]
<FromGitter> <naqvis> Crystal ain't ruby, so there is no dynamic inclusion
<FromGitter> <naqvis> things need to be known at compile time
<FromGitter> <naqvis> if you have defined `module A` with some methods then you should do a `include A` in respective Module/Class/Struct to get the mixin
<FromGitter> <zorgon_peterson:matrix.org> sorry, don't mean to assume that. I came to get a better idea on the behavior because it doesn't seem to be documented anywhere. For context, i was trying to port over a webscrapping tool used at work to see if it would perform better. In our framework the `Proto::Net::Message` object is constructed with a `mode` parameter to determine if it will include reading or writing functions. i see
<FromGitter> ... this is not possible without dynamic inclusion. thanks for your information!
<FromGitter> <Sija> any1 can figure out what’s the reason for this compile-time error: https://github.com/mint-lang/mint/pull/406/checks?check_run_id=2438027037#step:6:772 ?
<FromGitter> <Sija> as far as I can see in https://github.com/mint-lang/mint/pull/406/files there’s no way of *memo* becoming `Array(Exception)`
<straight-shoota> Yes, in the exception handler
<straight-shoota> `errors < ex` returns `Array(exception)` and that gets assigned to `memo`
<FromGitter> <Sija> Spot on @straight-shoota, thanks! 🙏 👀
<FromGitter> <naqvis> > sorry, don't mean to assume that. I came to get a better idea on the behavior because it doesn't seem to be documented anywhere. For context, i was trying to port over a webscrapping tool used at work to see if it would perform better. In our framework the `Proto::Net::Message` object is constructed with a `mode` parameter to determine if it will include reading or writing functions. i see this is not possible
<FromGitter> ... without dynamic inclusion. thanks for your information! ⏎ ⏎ Sorry, didn't mean to offend. Though Crystal is heavily influenced by Ruby and some portion of code will run as is in Crystal, but it is advised to re-think and re-design existing code to take advantage of Crystal features. If portion of code is returning diff ... [https://gitter.im/crystal-lang/crystal?at=6086b1d2dc24646812e4dad3]
<FromGitter> <Blacksmoke16> https://github.com/watzon/arachnid might be helpful
<FromGitter> <zorgon_peterson:matrix.org> @naqvis: thank you very much for the advise to use Union!! This works perfectly for what we are doing with this object
<FromGitter> <naqvis> 👍
<_ht> Are constants initialized when declared, or when first accessed?
<_ht> I have created my own enum-type class (I know there is an enum type, but I want something more powerfull), and want to define the elements of the enum as a constant on a class.
<_ht> However, the side effects of creating these constants don't run untill I first access them
<FromGitter> <Blacksmoke16> what do you want to do that an enum type cant?
<_ht> Extend it, add methods, and have any string as value
<_ht> I've got an example: https://play.crystal-lang.org/#/r/azin
<FromGitter> <Blacksmoke16> if you can have any string as an enum member is it really an enum?
<_ht> Well, the set of strings is limited to whatever you set as values in the class
<_ht> But I was just surprised that my constants were not initialized upon declaration
<FromGitter> <Blacksmoke16> if they're never used they might just be removed from the binary
<_ht> Ah, that would be bad :-(
<_ht> They could be used at run-time, say based on user input
<_ht> Then I've to look for a different way
<_ht> But maybe this behavior of constants that are not initialized or even removed from the binary needs to be documented at https://crystal-lang.org/reference/syntax_and_semantics/constants.html because this is quite unexpected behavior to me
<FromGitter> <Blacksmoke16> this is the behavior for anything, methods, classes, etc
<_ht> So, it might be to others as well
<FromGitter> <erdnaxeli:cervoi.se> what is your code? because crystal only remove code that is NEVER used, so it should never be a problem.
<FromGitter> <Blacksmoke16> why dont you just do like `item One, "Do the first thing"`
<_ht> That's also possible. I just liked "CONST = item value" for my DSL
<_ht> But if that's not possible, I will look at alternative solutions
<FromGitter> <Blacksmoke16> or fwiw, just do this
<FromGitter> <erdnaxeli:cervoi.se> but in your code there is no problem
<FromGitter> <erdnaxeli:cervoi.se> as soon as any code use Phrases::ONE, the constant will be there
<_ht> erdnaxeli:cervoi.se Yes, but my code elsewhere assumed that all these constants have been defined and initialized, for use with user input
<FromGitter> <erdnaxeli:cervoi.se> if you have use case where you never use it but still want it in `.values`, maybe you need another design
<_ht> Certainly! I just was surprised
<FromGitter> <erdnaxeli:cervoi.se> yeah it is suprising in your case because the assignement has compilation time side effects, et the assignement is removed if not used, so your macro don't run
<FromGitter> <erdnaxeli:cervoi.se> I can understand the suprise ^^
<_ht> Anyway, thanks for look at it.
<_ht> I'll see if I can find another way that would be nice for my DSL
<FromGitter> <Blacksmoke16> `item ONE = "Do the first thing"`
<FromGitter> <Blacksmoke16> type of the macro var would be https://crystal-lang.org/api/master/Crystal/Macros/Assign.html, so can get both things
<FromGitter> <naqvis> _ht https://play.crystal-lang.org/#/r/azj4
<FromGitter> <Blacksmoke16> could just do `@@consts : Array(self)? = \{{@type.constants}}`, no need to map over it given its already an array
<FromGitter> <naqvis> yay
<FromGitter> <Blacksmoke16> `Array(self)` as it'll just be empty
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <naqvis> ❤️
<FromGitter> <naqvis> this is still a hack as it will break when descendant class don't have any constant ⏎ `class variable '@@consts' of Bar must be (Array(Bar) | Nil), not Array(NoReturn)`
<FromGitter> <Blacksmoke16> oof
<FromGitter> <Blacksmoke16> `@type.constants.empty? ? "Array(self).new".id : @type.constants`
<FromGitter> <Blacksmoke16> workaround for that
<FromGitter> <naqvis> 👍
<FromGitter> <Blacksmoke16> *ht btw your `to_s` method is wrong
<FromGitter> <Blacksmoke16> you'd want ⏎ ⏎ ``` def to_s(io : IO) : Nil ⏎ io << @str ⏎ end ``` [https://gitter.im/crystal-lang/crystal?at=6086eb4b46a93d4a19ed9f27]
<FromGitter> <naqvis> yeah, he didn't override that method
<FromGitter> <naqvis> updated that as well ⏎ https://play.crystal-lang.org/#/r/azjr
<FromGitter> <roduquen> Hey guys, how will it work with bintray stopping is activity ?
<FromGitter> <Blacksmoke16> https://github.com/crystal-lang/crystal/issues/10626 needs to be figured out
<FromGitter> <roduquen> thanks
<_ht> Blacksmoke16 et al: Thanks!
<_ht> Now that I have read all your changes and ideas, also a special thanks to naqvis!
<_ht> Very neat solution, and a clear sign I need to study the power of macros way more to become a Crytal wizard like you all!
hendursa1 has quit [Ping timeout: 240 seconds]
hendursa1 has joined #crystal-lang
<FromGitter> <will> Are the yum repos broken right now? This used to work for me, but started to fail today (the gpg key is saved in a file instead, and appears to not be different from the url one in doc sample) ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=60870e54a9dd556843015974]
<FromGitter> <will> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60870e65c60826673bc7fcb3]
<FromGitter> <will> oh nevermind, just saw all the bintray… stuff
Stephanie is now known as Stephie
<FromGitter> <fdr> @straight-shoota I saw you were messing around with Crystal on the Open Build Service...thought you might appreciate the reminder that someone had a seemingly working copr for crystal (w/spec file) https://github.com/crystal-lang/crystal/issues/9833#issuecomment-712428217
<FromGitter> <riffraff169> hmm, no more rpm repo? i could probably build from source and create my own rpms...
<straight-shoota> @fdr thanks, I didn't recall that
_ht has quit [Remote host closed the connection]
lolollolololol has joined #crystal-lang
<straight-shoota> I can't find the spec file source anywhere, though
<lolollolololol> Hi guys. I'm new with Crystal. I came to ask how well does it perform, and is it any better than it's competition, for e.g: C.
<FromGitter> <rishavs> How can I use a salt for password generation? The docs are missing for the salt capability. ⏎ Here is a quick example code https://play.crystal-lang.org/#/r/aznl
<FromGitter> <RespiteSage> @lol It's not going to outperform optimized C in terms of program speed, but it will probably outperform C in terms of readability, development speed, maintainability, and especially developer happiness.
<FromGitter> <Blacksmoke16> @rishavs im pretty sure `Bcrypt` uses built in salts, which is based on the `cost` arg
<lolollolololol> You have a fair point. Screw all that pain with C when I can use Crystal.
<FromGitter> <RespiteSage> One really nice thing with Crystal if you're considering using it instead of C is that it interoperates with C really easily.
<FromGitter> <Blacksmoke16> https://stackoverflow.com/a/6833165
<FromGitter> <RespiteSage> It's very straightforward to make C bindings in Crystal.
<lolollolololol> That's pretty much with any language, though. Isn't it? It's silly to compare anything with C. And yup, I saw this. Was what attracted me.
<straight-shoota> @rishavs that `Crypto::Bcrypt::Password` constructor generates a salt value automatically
<straight-shoota> If you want more control, use `Crypto::Bcrypt`
<lolollolololol> Question: Crystal handles socket programming very well I would guess?
<FromGitter> <rishavs> Thanks @Blacksmoke16 and @straight-shoota
<straight-shoota> lolollolololol, yeah. It pretty much exposes the BSD socket API
<straight-shoota> it's not very pretty though, but it works
<lolollolololol> So definitely is performant?
<lolollolololol> I was willing to use Go, but on the other hand, I don't want to. Crystal's syntax seems pretty straight forward. It's what makes me want to do some socket stuff in it.
<straight-shoota> yes, in terms of concurrency, performance is pretty good
<straight-shoota> should be on par with Go
<lolollolololol> Supports asynchronous I/O as well, I suppose?
<lolollolololol> So I can do stuff like non-blocking sockets.
<straight-shoota> yes, all IO is asycn
<lolollolololol> What does it use by default? epoll? kqueue (guessing this since you mentioned BSD)
<straight-shoota> libevent
<lolollolololol> I see.
<lolollolololol> Thanks for the info :)
<straight-shoota> Ah, great. Thanks
<straight-shoota> Are you by any chance familiar with OBS and package management workflows? :D
<FromGitter> <fdr> uhhh I touched them once like, a long time ago
<FromGitter> <fdr> but when I saw you needed multiplatform builds I kinda remembered they specialized in that and so I thought to search first, and, there you were
<FromGitter> <fdr> I think I messed around with it a bit and decided that, for many, many frustrations, Launchpad was superior, but I don't remember why.
<straight-shoota> okay
<straight-shoota> b/c I'm having a hard time even getting started with that :D
<FromGitter> <fdr> do they have a command line client?
<FromGitter> <fdr> I think this may have had something to do with my frustration.
<straight-shoota> yes, osc
<straight-shoota> it's a bit of a mutant, combining a subversion CLI, build system and remote API
<straight-shoota> and I couldn't get a local build environment set up, neither with Ubuntu nor openSUSE
<FromGitter> <fdr> huh. Maybe I'll play with it a tiny bit and see what I can see...
<straight-shoota> I've resorted to pushing all edits to the server and let it run there
<straight-shoota> making some progress at least
Human_G33k has quit [Remote host closed the connection]
Human_G33k has joined #crystal-lang
<FromGitter> <fdr> yeah, that's what I did back in the day. Had a staging project to iterate on some stuff and a real one, when I needed a closer model than what debootstrap could provide (back when I did stuff on Debian mostly)
<straight-shoota> yeah, so far I have no idea how I'm going to do the Debian packages. Documentation is really scarce. Or not in a way to understand while familiarizing with the whole system.
lolollolololol has quit [Quit: Connection closed]
mteverst has joined #crystal-lang
<mteverst> Are TCP sockets in crystal non-blocking by default?
<FromGitter> <riffraff169> what is the best way to create an array of records as a constant?
<FromGitter> <riffraff169> just something like: ```
<FromGitter> <tenebrousedge> `CONSTANT = file.read("xxx").each_line do`
<FromGitter> <riffraff169> ```ARR = Array of MyRec ⏎ ARR["A"] = MyRec.new(1,2,3)``` [https://gitter.im/crystal-lang/crystal?at=60875149bdc0bc32e61ddc3d]
<FromGitter> <tenebrousedge> that's not an array
<FromGitter> <riffraff169> you are right...its supposed to be a hash, sorry
<FromGitter> <tenebrousedge> you probably want named tuples instead of a hash
<FromGitter> <riffraff169> ```HASH = Hash of MyRec ⏎ HASH["A"] = MyRec.new(1,2,3)``` [https://gitter.im/crystal-lang/crystal?at=6087517dc1a9210b3c21f436]
<FromGitter> <tenebrousedge> ```alias Label = String ⏎ record MyRecord ⏎ HASH = Hash(Label, MyRecord)``` [https://gitter.im/crystal-lang/crystal?at=608751c0d24b2904978677af]
<FromGitter> <tenebrousedge> `.new` obvs
<FromGitter> <riffraff169> that could be done at the module level, i presume, and then a class/object could reference it
<FromGitter> <tenebrousedge> yup
<FromGitter> <riffraff169> one thing thats been hard for me to get used to coming from c, code outside of a function/method...because it is all code, even class/module/struct/whatever def
<FromGitter> <tenebrousedge> it's also not a terrible idea to do like `HASH = db_setup_method`
<FromGitter> <tenebrousedge> or `HASH = db_setup_method("myfile.yaml")`
<FromGitter> <riffraff169> yeah, but that just really moves the initialization from top level into a function, but still have to init the same
<FromGitter> <tenebrousedge> yes but it's easier to test in a method
<FromGitter> <riffraff169> unfortunately trying to keep the data static in the binary
<FromGitter> <riffraff169> so when distributing there is only one file, not the binary plus a whole data directory
<FromGitter> <tenebrousedge> ah right, you're using a macro to do this
<FromGitter> <tenebrousedge> but you can still write a macro that takes the YAML file as an argument
<FromGitter> <riffraff169> yeah, i mentioned this yesterday, basically just a bunch of constants used to perform calculations...
<FromGitter> <tenebrousedge> yes, I remember
<FromGitter> <riffraff169> so.....when building it reads the yaml into the src, which is then baked into the binary
<FromGitter> <tenebrousedge> yee
<FromGitter> <riffraff169> i get the idea, im just not sure how to implement that
<FromGitter> <riffraff169> still learning
<FromGitter> <tenebrousedge> you want the macro section of the book
<FromGitter> <riffraff169> plus in the reading, i would want to convert the data from YAML::Any to the proper type so i dont have to do that conversion in the code
<FromGitter> <riffraff169> ok, ill read up on macros
<FromGitter> <riffraff169> so i would create a macro method, then call the method ....but, and here is where my understanding kind of ends, how do you keep the call to the method from happening normally, and only run at compile time?
<FromGitter> <tenebrousedge> https://crystal-lang.org/api/1.0.0/Crystal/Macros.html#read_file(filename):StringLiteral-instance-method
<FromGitter> <tenebrousedge> macros *only* execute at compile time