RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.25.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
akaiiro has quit [Ping timeout: 256 seconds]
wontruefree has quit [Quit: bye]
abm has quit [Quit: Leaving]
<FromGitter> <asterite> university in san macros sounds like a perfect fit for crystal
Raimondi has quit [Read error: No route to host]
Raimondi has joined #crystal-lang
renzhi has quit [Quit: WeeChat 2.1]
renzhi has joined #crystal-lang
akaiiro has joined #crystal-lang
<FromGitter> <drinkmorewaters> Does it matter if you use p or puts? I am learning by copying go and translating it into Crystal. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b59442932d98c2ed2b62387]
<FromGitter> <robacarp> @drinkmorewaters chances are you want puts, but check out what each does here: https://github.com/crystal-lang/crystal/blob/master/src/kernel.cr
<FromGitter> <drinkmorewaters> Also in go, assigning a type seems easy, how do i assign a type this simply in Crystal? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b594679d2f0934551d0d63a]
akaiiro has quit [Ping timeout: 244 seconds]
<FromGitter> <drinkmorewaters> @robacarp @icyleaf Thanks!
<FromGitter> <bew> @asterite ahahah well I thought about it, but I didn't do any class about programming languages and the few people I talked to who did it, weren't interested in the subject.. Too bad i guess..
akaiiro has joined #crystal-lang
<FromGitter> <drinkmorewaters> Is there a better way for gets.chomp in Crystal or does to_i work? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b594eaa32d98c2ed2b636a7]
<FromGitter> <bew> @drinkmorewaters well, `gets` can return nil or a String, and `to_i` is for the String
<FromGitter> <bew> so you have to handle the case where the result of `gets` is `nil`
<FromGitter> <drinkmorewaters> @bew Problem with gets is that it thinks its a string so i cannot do multiplication.
<FromGitter> <bew> what? it IS a String (or nil)
<FromGitter> <drinkmorewaters> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b594f4e5301255724c6ee62]
<FromGitter> <bew> so yes, you have to convert the string to a number by calling `to_i`
<FromGitter> <drinkmorewaters> I mean, the gets should have a user input an integer, so i guess i need to tell that gets.to_i
<FromGitter> <drinkmorewaters> I do to_i but get an error ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b594f93c0fa8016e739b7eb]
<FromGitter> <bew> but `gets` could also return `nil`, and `to_i` doesn't exist for nil (and doesn't make sense either)
<FromGitter> <bew> that's the exact error, if you read it: `undefined method 'to_i' for Nil`
<FromGitter> <bew> so you have to handle the case where it's nil, either by interrupting the program, or giving a default value, or somthing else
<FromGitter> <bew> for exemple you could do `some_var = gets.try(&.to_i) || 0`
<FromGitter> <bew> so here, if `gets` returns nil, it'll just be 0. And if `gets` returns a String, it'll call `to_i` on it, and return that result
<FromGitter> <drinkmorewaters> Ok, so that's way over my head and way more complex than Ruby, thus i can't translate its use
<FromGitter> <bew> try to experiment around that
<FromGitter> <drinkmorewaters> That works for getting input, fails if a string is input, but i got no idea how it works compared to gets.chomp, or gets.to_i
<FromGitter> <bew> yeah, you have to deal with types here! But I promise it'll help you a lot (in any languages) to consider the real types of things that you're manipulating, and what could happen in this or this case
<FromGitter> <drinkmorewaters> I know it will help, but it's definitely a much harder learning curve. I don't know why but i'm finding working with types in go much simpler. But that's maybe because i have no idea what i'm doing.
<FromGitter> <bew> I don't understand what you mean by "got no idea how it works compared to gets.chomp, or gets.to_i"
<FromGitter> <drinkmorewaters> Compared to ruby's version of things. I don't understand this gets.try(&.to_i) || 0
<FromGitter> <bew> yeah the type system in Crystal is quite different than go
<FromGitter> <drinkmorewaters> gets method? .try another method? (&.to_i) "no idea || or 0
<FromGitter> <bew> ok, basically `gets` can return 2 kind of things: `nil` if there is no input (e.g: the user did Ctrl-D in the terminal). Or it can return a `String` object with the input data
<FromGitter> <bew> so we say that the return type of `gets` is `String | Nil` (meaning: the String OR Nil type)
<FromGitter> <bew> side note: `Nil` is a type, `nil` is a value. And `nil` is the only possible value that has a `Nil` type (ok maybe I lost you here...)
<FromGitter> <drinkmorewaters> Oh god
<FromGitter> <drinkmorewaters> That last part is long lost on me for now
<FromGitter> <bew> in Crystal you have to handle the case where a value can be `nil`, so if `gets` returns `nil` you'll probably want to do something different than if the user entered actual real data
<FromGitter> <bew> yeah don't worry, it's not important for now ^^
<FromGitter> <drinkmorewaters> I think i get the first part. Gets can return a 2 things, value of nil which is like 0 or nothing? and an object of String. But because we want an integer, we get the string and change it to an integer.
<FromGitter> <bew> `nil` is like "nothing"
<FromGitter> <drinkmorewaters> &. is what?
<FromGitter> <drinkmorewaters> .try is a method?
<FromGitter> <bew> yes, `try` is a method
<FromGitter> <bew> do you know blocks (like in ruby) ?
<FromGitter> <drinkmorewaters> Negative, know nothing. I will look up blocks in ruby. I am learning both in parallel, with Go just learn one concept and try to do it in another language to understand it's core principle. Might be the wrong way to do things.
<FromGitter> <bew> which language(s) do you know (well or mid-well) ?
<FromGitter> <drinkmorewaters> I started 4 days ago haha
<FromGitter> <drinkmorewaters> Goes like this, Go i can read it and seems to be focus on simplicity, ruby is simpler than Crystal only because i can google anything, Crystal i am most keen on as it's a logical speed + expression.
<FromGitter> <bew> @drinkmorewaters https://carc.in/#/r/4lxh
<FromGitter> <bew> here you can see the types
<FromGitter> <drinkmorewaters> @bew Ok i'll take a look, thanks.
jokke1 has quit [Ping timeout: 260 seconds]
<FromGitter> <bew> so `try` is a method that exists for every types, so you can always call it, its reason of existence is that it'll execute the given block, only if the type it's called on is not `Nil`.
<FromGitter> <bew> note: writing `something.try(&.to_i)` is the same as writing `something.try { |x| x.to_i }`, just shorter
<FromGitter> <bew> you can read about blocks here: https://crystal-lang.org/docs/syntax_and_semantics/blocks_and_procs.html
<FromGitter> <drinkmorewaters> The docs for me are written for professional programmers, so they're nearly useless to me at this point in time.
<FromGitter> <bew> hmm yes we have some improvements to do about that, maybe start with Ruby's block then, and come back later?
jokke1 has joined #crystal-lang
<FromGitter> <drinkmorewaters> Yeah, think that's becoming very clear to me at this point, that i'll need to focus on go or ruby or a similar other language with a lot more beginners material. Which i understand takes uptake and time.
alex`` has joined #crystal-lang
<FromGitter> <sam0x17> @drinkmorewaters you will get a lot of mileage out of first googling "how to do x in ruby", and then use the ruby-specific x terminology to find how to do x in crystal. For every difference between ruby and crystal there is some issue in github where someone is asking about it
alex`` has quit [Ping timeout: 264 seconds]
renzhi has quit [Quit: WeeChat 2.1]
<FromGitter> <drinkmorewaters> @sam0x17 I am currently doing that, trying to digest and translate as much as i can, but then things like user input there are no stackoverflow posts, blogs or tutorials so the help from @bew just isn't documented anywhere for inputs. Without his help i would not have ever figured out the solution. ⏎ ⏎ ```B = gets.try(&.to_i) || 0``` [https://gitter.im/crystal
<FromGitter> ... -lang/crystal?at=5b5969ae1be9bb57bcc46635]
<FromGitter> <drinkmorewaters> I will post more of my questions in stack overflow as there needs to be more of these questions asked and answered to help lots of programmers. ⏎ ⏎ I have made a question for user input or gets.chomp in Crystal
<FromGitter> <icyleaf> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b596e50ee7b230b446a1cc0]
<FromGitter> <drinkmorewaters> @icyleaf if you're on stackoverflow please post, i am sure there are heaps of beginners trying to learn the same things but don't ask or give up.
renzhi has joined #crystal-lang
<FromGitter> <drinkmorewaters> Lol who downvoted it? Very inclusive community
flaviodesousa has joined #crystal-lang
davic has quit [Excess Flood]
davic has joined #crystal-lang
alex`` has joined #crystal-lang
<FromGitter> <sam0x17> @drinkmorewaters if you truly only want an int, a common pattern is to do a loop where you ask for the int, read whatever the user enters, try converting it to an int, and if you get a valid int break out of the loop, otherwise keep looping until you get a valid int. That will probably give you the behavior you want
<FromGitter> <sam0x17> that approach is used in practically every programming language that deals with user input
<FromGitter> <sam0x17> @drinkmorewaters ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b5983efc0fa8016e73a43d9]
<FromGitter> <sam0x17> I also added that as an answer on the stackoverflow
<FromGitter> <sam0x17> note: the `next` is not necessary it was due to some edits i made so you can remove that line
<FromGitter> <sam0x17> looks like you are all set though because the non-rough approach the other guy did is basically this
<FromGitter> <sam0x17> I canceled out the downvotes as well
alex`` has quit [Quit: WeeChat 2.1]
alex`` has joined #crystal-lang
literal has quit [Ping timeout: 256 seconds]
<FromGitter> <drinkmorewaters> @sam0x17 Thanks for that, the downvotes pissed me off for a good hour there. Down voters on all answers doesn't help. As both your answer and @icyleaf answer were both super helpful in seperate ways!
literal has joined #crystal-lang
<FromGitter> <drinkmorewaters> i also created https://gitter.im/crystal-beginners/Lobby if anyone cares to moderate or join it. As the main Crystal thread seems to annoy the 'senior' devs.
Ven`` has joined #crystal-lang
<FromGitter> <straight-shoota> @drinkmorewaters I'm not a member of the core team but I'd advise against opening a new place for Crystal talk. This chat room is hardly over flooded and I don't think beginner questions annoy anyone here. And it's better to have people come here where there are many people around to answer questions.
<FromGitter> <drinkmorewaters> @straight-shoota I've definitely noticed a sense of hostility in many places around Crystal (not massively), so my thought would be to take some of the focus off the main channel. Comparing this to the Elixir community it's strikingly different. I can close the chacnnel if it's better though. But i put a question on stack-overflow and the first thing is, no answers, down votes, then i get an answer and
<FromGitter> ... his answer, downvotes. I've seen frameworks around Crystal on Github see hostile answers in their issues threads. So it's bothering me.
<FromGitter> <straight-shoota> Well, SO and Github issues isn't Gitter =)
<FromGitter> <straight-shoota> I don't see such hostility, but if it is there, then that's a bigger problem then could be solved by opening a new beginners channel.
<FromGitter> <drinkmorewaters> It's not there for you because you're not a beginner.
jokke1 has quit [Ping timeout: 256 seconds]
jokke1 has joined #crystal-lang
return0e_ has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi
<FromGitter> <icyleaf> Anyone was the beginner who learn Crystal at first, include me :)
<FromGitter> <drinkmorewaters> @icyleaf 谢谢。Your answer was very helpful before.
_whitelogger has joined #crystal-lang
<FromGitter> <sangamcse> Hey, is https://dist.crystal-lang.org/apt working?
<FromGitter> <sangamcse> It is not working for me. Tell me if there is any alternative for this.
<FromGitter> <Blacksmoke16> well i dont think you are supposed to visit them in a browser
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b59b0c307be4357bdef54f7]
<FromGitter> <sangamcse> Oh, thank you. I am trying with above link. 😄
<FromGitter> <Blacksmoke16> np
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
TCZ has joined #crystal-lang
<FromGitter> <Grabli66> Compiler, you are drunk, go home. :) https://play.crystal-lang.org/#/r/4m2h
TCZ has quit [Quit: Leaving]
<crystal-gh> [crystal] Sija opened pull request #6448: Use named arguments for JSON/YAML serialization (master...fix-6405) https://git.io/fNEaJ
Ven`` has joined #crystal-lang
<FromGitter> <j8r> @asterite do you know how to solve this https://carc.in/#/r/4m4i (working on https://github.com/crystal-lang/crystal/issues/6083#issuecomment-387872883)
<FromGitter> <asterite> Just `require "compiler/crystal/**"`
Ven`` has quit [Ping timeout: 268 seconds]
<jokke> how can i build a binary which will run specs of my project?
<jokke> i have a segfault and need to debug it
<jokke> so i'll need a binary
Ven`` has joined #crystal-lang
<FromGitter> <j8r> Thanks @asterite , this works on an empty program.
<FromGitter> <j8r> But when including this in `playground/server.cr`: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b59cf8c32d98c2ed2b7b736]
<FromGitter> <j8r> I have ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b59cfacdb8bd24550b4015f]
<FromGitter> <asterite> That last snippet you sent compiles file for me. But anyway, I don't have time for this, sorry
<FromGitter> <j8r> BTW thank you 😄
<FromGitter> <rishavs> @drinkmorewaters hang in there. I am an absolute beginner as well. But the community has been super helpful so far. There has never been the case that i was scared of asking something just because it seemed too basic. I just make sure that I have tried something by myself before I ask the question, so I am better able to understand the answers.
<FromGitter> <bew> @jokke you can do `crystal build <your_spec_file.cr>`
rohitpaulk has joined #crystal-lang
<FromGitter> <yorci> how to set time zone globally?
duane has joined #crystal-lang
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <straight-shoota> jokke, `crystal spec` doesn't do anything special. It's the same as `crystal run` with globbing for spec files
<FromGitter> <straight-shoota> all the specific runtime behaviour happens by `require "spec"`
<FromGitter> <straight-shoota> @yorci programmatically, you can do `Time::Location.local = Time::Location.load("Europe/Berlin")`
<FromGitter> <straight-shoota> otherwise `Time::Location.local` can also read `TZ` environment variable
Ven`` has joined #crystal-lang
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rohitpaulk has quit [Ping timeout: 248 seconds]
flaviodesousa has quit [Quit: KVIrc 4.2.0 Equilibrium http://www.kvirc.net/]
alex`` has quit [Quit: WeeChat 2.1]
wontruefree has joined #crystal-lang
<FromGitter> <hugoabonizio> have you guys seen this project? https://github.com/omarroth/invidious
<wontruefree> is invidious scrapping youtube and reddit?
<FromGitter> <fridgerator> it uses the youtube api I believe
<robacarp> this is interesting: https://github.com/omarroth/jager
rohitpaulk has joined #crystal-lang
literal has quit [Ping timeout: 265 seconds]
literal has joined #crystal-lang
return0e_ has quit [Ping timeout: 264 seconds]
<FromGitter> <jwoertink> I love invidious. It's been my go-to site for a while now.
<FromGitter> <jwoertink> What does the percent do in front of variables when in a macro? Like in `%objs = Array(self).new` or `def self.from_rs(%rs : ::DB::ResultSet)`
<FromGitter> <r00ster91> They are called fresh variables: https://crystal-lang.org/docs/syntax_and_semantics/macros/fresh_variables.html
<FromGitter> <jwoertink> ah! sweet. Thanks. I didn't know they had a special name.
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 256 seconds]
DTZUZU has quit [Quit: WeeChat 1.9]
DTZUZU has joined #crystal-lang
wontruefree has quit [Quit: bye]
jetpack_joe has quit []
jetpack_joe has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 256 seconds]
Ven`` has joined #crystal-lang
rohitpaulk has joined #crystal-lang
return0e has joined #crystal-lang
alex`` has joined #crystal-lang
wontruefree has joined #crystal-lang
wontruefree has quit [Client Quit]
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
wontruefree has joined #crystal-lang
<crystal-gh> [crystal] straight-shoota opened pull request #6450: Add Fiber#cancel (master...jm/feature/fiber-cancel) https://git.io/fNuIN
<FromGitter> <kazzkiq> Just out of curiosity: If you have a collection of files with reusable functions across your app. Do you put them in a folder called "utils" or "helpers"?
rohitpaulk has quit [Ping timeout: 248 seconds]
<z64> @kazzkiq i've seen "helpers" more often in the wild, as a semantic in specs ("spec helpers") or in MVC web frameworks
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
Ven`` has joined #crystal-lang
duane has quit [Quit: leaving]
Ven`` has quit [Ping timeout: 248 seconds]
<FromGitter> <bararchy> @straight-shoota thanks for putting us one step closer to multi-threading
<FromGitter> <straight-shoota> Cancelling a fiber doesn't have much to do with multi-threading
<FromGitter> <straight-shoota> And it might needs some tweaks for cancelling a fiber that is currently running
<FromGitter> <bew> If ever possible/sane to do
<FromGitter> <talbergs> Hey https://play.crystal-lang.org/#/r/4m7l
<FromGitter> <talbergs> I remember this should work, but the spawn again thinks that may be nil again?
<FromGitter> <talbergs> ps, may we add some vim mode to "play.crystal-lang" ? really many times I pressed `esc` and had to white again ^^
<FromGitter> <talbergs> nvm - I figured https://play.crystal-lang.org/#/r/4m7n ^^
<FromGitter> <bew> note: is still break if you try to use `ss` after https://play.crystal-lang.org/#/r/4m7o
<FromGitter> <talbergs> yeah, that's clear on scoping. Thou, why compiler expects the `s` might change after `if` in the `spawn` block? ⏎ ⏎ I guess, because it's reference. So any obj may become nil.
<FromGitter> <bew> that ^ couldn't find it >< @asterite what about having a way to capture a block that copies all local vars it references?
<FromGitter> <talbergs> In jabbascript variables get's coppied and bound into closure scope
<FromGitter> <talbergs> What a waste ^^
<FromGitter> <talbergs> But here I see compiler just looks one block level deep, maybe that's it right there?
return0e has quit [Quit: Leaving...]
<FromGitter> <bew> @talbergs checkout https://play.crystal-lang.org/#/r/4m7u the spawn's block is not executed right away
<FromGitter> <bew> maybe not the example though
<FromGitter> <talbergs> No no .. inpecting..
<FromGitter> <talbergs> this clearly illustates the implied type is not passed into the declaration of that new fiber (spawn) instead original type is "passed in"
<FromGitter> <talbergs> the reason why so, is still not clear... could really an object (at same address) become nil (with pointer?) and then at some moment of concurrency become object again?
<FromGitter> <talbergs> Im sure not! But that reasoning seems to be implied by this behaviour.
<FromGitter> <bew> well that example exactly shows you that it's possible
<FromGitter> <bew> in the spawns block, the variable is nil
<FromGitter> <talbergs> oh, ok then, moving on. ^^ thanx!
<FromGitter> <bew> when you use a variable in a block, it is the same variable as outside of it, and as the compiler doesn't know when that block will be executed, the variable can be anything (its type is not impacted by the `if`)
<FromGitter> <talbergs> Ok, I finally got it.
<FromGitter> <talbergs> No, rly :)
<FromGitter> <talbergs> Im not a computer scientist, so it's a common thing that `nil` is a value stored at address (reference/variable) instead of just representing a "no value and no address to look at"?
<FromGitter> <bew> this has nothing to do with `nil`, I could have use a `String` and a `Int32`
<FromGitter> <talbergs> So the address remains taken with a nil.
<FromGitter> <talbergs> Ah yeah .. im changing subject.
<FromGitter> <bew> ah it's another question?
<FromGitter> <talbergs> ^^ just sayin
duane has joined #crystal-lang
duane has quit [Ping timeout: 268 seconds]
duane has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 264 seconds]
Raimondii is now known as Raimondi
return0e has joined #crystal-lang
johndescs_ has joined #crystal-lang
johndescs has quit [Ping timeout: 260 seconds]
johndescs_ is now known as johndescs
duane has quit [Ping timeout: 240 seconds]
alex`` has quit [Ping timeout: 260 seconds]
wontruefree has quit [Quit: bye]
<FromGitter> <Blacksmoke16> how would you define a custom `to_json` for an array of objects
<FromGitter> <Blacksmoke16> vs just one obj
<crystal-gh> [crystal] asterite opened pull request #6452: Compiler: missing `request_value` in `not` call (master...bug/6451-not-missing-request-value) https://git.io/fNuub