ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.31.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> <tenebrousedge> is there a GitHub issue related to the absence of `match?` that I'm not finding?
Nekka has quit [Ping timeout: 265 seconds]
Nekka has joined #crystal-lang
gangstacat has quit [Ping timeout: 245 seconds]
gangstacat has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <tenebrousedge> @asterite ?
alex``` has quit [Quit: The Lounge - https://thelounge.chat]
<FromGitter> <watzon> @tenebrousedge you mean adding it to `Regex` and `String`?
<FromGitter> <tenebrousedge> yes
<FromGitter> <tenebrousedge> it seems like there should be prior discussion
<FromGitter> <watzon> What would be the point? Just returning a bool instead of a `Regex::MatchData?`
<FromGitter> <tenebrousedge> yes, and avoiding setting the pseudo-globals
<FromGitter> <watzon> Hmm that does make sense
<FromGitter> <tenebrousedge> sometimes one needs to test if an element is present in a string, but the match itself is not used
<FromGitter> <tenebrousedge> Ruby added it in 2.4 I believe
<FromGitter> <tenebrousedge> the downside of course is that you then have `=~`, `match?`, `match`, and `===`
return0e_ has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
ht_ has joined #crystal-lang
ht_ has quit [Quit: ht_]
ua has quit [Ping timeout: 240 seconds]
alexherbo2 has joined #crystal-lang
alexherbo2 is now known as alex```
ua has joined #crystal-lang
duane has quit [Ping timeout: 240 seconds]
sagax has quit [Quit: Konversation terminated!]
duane has joined #crystal-lang
<FromGitter> <asterite> yes, `match?` would be good to have. Probably `matches?`, though
<FromGitter> <tenebrousedge> has there been previous discussion of this?
<FromGitter> <yxhuvud> could it be handled by escape analysis if that is ever implemented? or is the issue that it sets $-variables which wouldn't escape?
<FromGitter> <yxhuvud> (or which *would* escape? Never can remember which way it is)
HumanG33k has joined #crystal-lang
duane has quit [Ping timeout: 252 seconds]
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
duane has joined #crystal-lang
DTZUZO has quit [Ping timeout: 250 seconds]
<FromGitter> <kinxer> Are other people able to navigate to https://forum.crystal-lang.org/t/crystal-in-possible-wasm-everywhere-future/1383?
<FromGitter> <tenebrousedge> it doesn't seem to be loading
<FromGitter> <kinxer> I'm getting a "Corrupted Content Error" in Firefox.
<FromGitter> <tenebrousedge> yes
<FromGitter> <kinxer> It seems to be happening for me for any URL in https://forum.crystal-lang.org. https://crystal-lang.org works, though.
<FromGitter> <tenebrousedge> clearly it has borkens
return0e has joined #crystal-lang
return0e_ has quit [Ping timeout: 240 seconds]
<FromGitter> <wontruefree> is forum.crystal-lang.org down? It is keeps timing out on my computer
<FromGitter> <tenebrousedge> seems to be, yes
<FromGitter> <wontruefree> wonder if it is discourse or us
<FromGitter> <christopherzimmerman> @kinxer took your advice and started working a lot more on documentation now that I have most of the core functionality worked out. Would definitely appreciate feedback on the quickstart guide (https://crystal-data.github.io/bottle/user/quickstart.html).
ht_ has joined #crystal-lang
DTZUZO has joined #crystal-lang
DTZUZO has quit [Quit: WeeChat 2.0]
alex``` has quit [Ping timeout: 265 seconds]
alex``` has joined #crystal-lang
duane has quit [Ping timeout: 276 seconds]
ht_ has quit [Remote host closed the connection]
ht_ has joined #crystal-lang
alex```5 has joined #crystal-lang
alex``` has quit [Ping timeout: 240 seconds]
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
alex```59 has joined #crystal-lang
alex```5 has quit [Ping timeout: 252 seconds]
<FromGitter> <Daniel-Worrall> what does `--prelude` do in crystal docs?
<FromGitter> <Daniel-Worrall> I went looking if there's an option to be able to have inline source for docs (maybe expandable box)
<FromGitter> <Blacksmoke16> it controls like what stuff is required by default
<FromGitter> <Daniel-Worrall> What kind of method do I need to use `@foo ||= bar` where bar is a method that can return either true or false and `@foo` is instantiated with `nil`
<FromGitter> <Daniel-Worrall> I want to cache the bool at runtime on request
<FromGitter> <Blacksmoke16> prob could do `getter foo : Bool { bar }`
<FromGitter> <tenebrousedge> ^
<FromGitter> <Blacksmoke16> would be lazily set the first time its called
<FromGitter> <tenebrousedge> or `getter?`
<FromGitter> <tenebrousedge> if it's a bool I'd do the predicate
<FromGitter> <Daniel-Worrall> yeah, I'll be using `getter?`
<FromGitter> <Blacksmoke16> `getter foo : Bool { bar }` then
<FromGitter> <Daniel-Worrall> I just didn't put the `?` for the question
<FromGitter> <Daniel-Worrall> abstract foo and bar and such
<FromGitter> <Daniel-Worrall> ty guys
<FromGitter> <tenebrousedge> np
<FromGitter> <Daniel-Worrall> okay, strictly API structuring question. The method to fetch the output should be called what? `private_foo?`? `fetch_foo?`?
<FromGitter> <Daniel-Worrall> I would call it `foo?` if I could have public and private methods named the same
<FromGitter> <Daniel-Worrall> `parse_foo?`?
<FromGitter> <tenebrousedge> you could have `foo` and `foo?`
<FromGitter> <tenebrousedge> or `get_foo`
<FromGitter> <Daniel-Worrall> How would you do it?
<FromGitter> <tenebrousedge> maybe `_foo`, if we allow initial underscores in method names
<FromGitter> <tenebrousedge> which looks like a thing
<FromGitter> <Daniel-Worrall> hm, do you think `_foo` or `_foo?`
<FromGitter> <Daniel-Worrall> I do like the `_` idea
<FromGitter> <tenebrousedge> `_foo?` seems reasonable
DTZUZO has joined #crystal-lang
<FromGitter> <Daniel-Worrall> Hmm, what happens when you `pp` an instance with lazy loaded properties
<FromGitter> <Daniel-Worrall> Do they load
<FromGitter> <Daniel-Worrall> I guess they would
<FromGitter> <Daniel-Worrall> Nope, they just output `nil`
<Xeago> Is there a documentation page somewhere how to integrate crystal compilation units into another language?
<Xeago> Would I be able to get the intermediate c code, and put that in `extern c`?
<FromGitter> <tenebrousedge> there is no intermediate C code
<FromGitter> <tenebrousedge> Crystal -> llvm-ir -> machine code
<FromGitter> <Daniel-Worrall> does `not_nil!` need any processing? Is it something I should be lazily loading?
<FromGitter> <Daniel-Worrall> "should"/"could"
<FromGitter> <Blacksmoke16> example?
<FromGitter> <Daniel-Worrall> `@message.tags.not_nil!["mod"].not_nil! == "1"`
<FromGitter> <Blacksmoke16> only if you're 100% sure they wont be nil
<FromGitter> <Daniel-Worrall> In my example, I'll be using tags anywhere from 1-5 times
<FromGitter> <Daniel-Worrall> 100%
<FromGitter> <Daniel-Worrall> According to the API I'm using
<FromGitter> <Daniel-Worrall> If they're nil, I have much bigger problems
<FromGitter> <Daniel-Worrall> idk if it'd be worse to be storing a pointer than calling it each time
<FromGitter> <Daniel-Worrall> seems like a memory impact vs cpu impact question
<FromGitter> <tenebrousedge> is that likely to be a big performance difference in your app?
<FromGitter> <Daniel-Worrall> I guess that's my question
<FromGitter> <Daniel-Worrall> Performance is the top priority
<FromGitter> <tenebrousedge> unless you have some reason to believe otherwise, assume that the answer is that performance differences are negligible. Write clear code first, then profile it to find hotspots
<FromGitter> <Daniel-Worrall> what sort of difference to memory does having extra properties and pointers have
<FromGitter> <Daniel-Worrall> yeah, let's not bog myself down with details
<FromGitter> <Daniel-Worrall> They are going to be extremely short lived instances so we'll probably take the memory hit
<FromGitter> <Daniel-Worrall> Pog, I can use private getters too
<FromGitter> <Daniel-Worrall> Oh, I just realised since I'm using a single line of code in the private methods, I can just put them in the lazy load block
* FromGitter * tenebrousedge nods
<FromGitter> <Daniel-Worrall> all the macro deliciousness
<FromGitter> <Daniel-Worrall> Would `"#string"[1...]` be the right way to chop off the first char
<FromGitter> <tenebrousedge> `"string".lchop("s")`
<FromGitter> <tenebrousedge> note `"string".lchop("q") #=> "string"`
alex```59 has quit [Quit: The Lounge - https://thelounge.chat]
<Yxhuvud> Daniel-Worrall: I'd tend to refactor if I get chains of not_nil!. You can avoid them by wrapping things in if statements or in methods that you make certain will return only what you want.
alexherbo2 has joined #crystal-lang
Vexatos has quit [Remote host closed the connection]
Vexatos has joined #crystal-lang
<FromGitter> <Daniel-Worrall> Can I call private methods in a spec?
<FromGitter> <tenebrousedge> you can open the class and make them public
<FromGitter> <watzon> That's usually what you'd use `#send` for in Ruby
<FromGitter> <watzon> But Crystal doesn't have that built in
<FromGitter> <tenebrousedge> and won't
<FromGitter> <kinxer> Yeah, I generally just re-open the class in the `spec_helper.cr`
<FromGitter> <Daniel-Worrall> Right so how would I do that
<FromGitter> <kinxer> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dd45c865eb2e813db55a7f1]
<FromGitter> <watzon> Monkeypatch the class like this ^
<FromGitter> <Daniel-Worrall> ty
<FromGitter> <Daniel-Worrall> I didn't know about previous_def
<FromGitter> <Daniel-Worrall> Okay, so I had to define the args and type restrict them too
<FromGitter> <Daniel-Worrall> but this works ty
<FromGitter> <kinxer> So, absolutely do not use this in your non-spec code, but ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ https://play.crystal-lang.org/#/r/81p3 [https://gitter.im/crystal-lang/crystal?at=5dd4607cfd6fe41fc0b4f32e]
<FromGitter> <kinxer> That should help if you have a lot of re-opening to do.
<FromGitter> <Daniel-Worrall> don't you have to pass params
<FromGitter> <kinxer> Yeah, you're right. I didn't think of method parameters.
<FromGitter> <kinxer> Maybe ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dd46181c26e8923c4562a54]
ht_ has quit [Remote host closed the connection]
<FromGitter> <Daniel-Worrall> for the record, testing private methods is bad practice. I'm only using it to call them for testing other methods
<FromGitter> <kinxer> 👍
alexherbo25 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
<FromGitter> <tenebrousedge> @Daniel-Worrall you seem to have a good understanding of general coding principles; I figured you had a good reason for asking
<FromGitter> <Daniel-Worrall> well ty, I just struggle with some bits. :^)
<FromGitter> <Daniel-Worrall> The more I ask now, the less I ask later
<FromGitter> <Daniel-Worrall> I really do wish I had taken comp sci at uni though
<FromGitter> <tenebrousedge> oh?
<FromGitter> <Daniel-Worrall> would have given me a much broader understanding
<FromGitter> <Daniel-Worrall> Formal education has its benefits
<FromGitter> <tenebrousedge> have you gone through SCIP?
<FromGitter> <tenebrousedge> or *NAND to Tetris* ?
<FromGitter> <Daniel-Worrall> Not heard of either of those. Everything is "self-taught".
<FromGitter> <tenebrousedge> myself as well. There's a lot of MIT and Stanford coursework that's available online
<FromGitter> <tenebrousedge> https://xuanji.appspot.com/isicp/ this is an interactive version of the classic *Structure and Interpretation of Computer Programs*
<FromGitter> <tenebrousedge> *NAND to Tetris* is another good foundational course, sort of a more machine-oriented approach
<FromGitter> <TedTran15_twitter> Hey guys, can anybody here experienced in Crystal tell me what is 'uninitialized'? I'm reading https://crystal-lang.org/reference/syntax_and_semantics/declare_var.html
<FromGitter> <kinxer> @TedTran15_twitter What's your programming background?
<FromGitter> <kinxer> Just in general (no need for specifics).
<FromGitter> <TedTran15_twitter> Not too much, about a few months
<FromGitter> <TedTran15_twitter> In C and Ruby
<FromGitter> <TedTran15_twitter> I'm thinking it's a random garbage memory address that if you actually look at, it segfaults?
<FromGitter> <kinxer> An uninitialized variable allocates memory (as with C's `malloc`) but does not set that memory to anything.
<FromGitter> <watzon> Yeah it just allocates the memory, but doesn't actually initialize anything to use that memory
<FromGitter> <kinxer> The Crystal doc page about it (https://crystal-lang.org/reference/syntax_and_semantics/declare_var.html) mentions its use for allocating memory for `StaticArray`s without the performance penalty of setting the memory to certain values.
<FromGitter> <straight-shoota> It essentially says there is a value of type whatever is specified, but the value is actually garbage. So it must not be used until there is a proper value assigned. This is pretty low level stuff and usually meant for performance optimization. The alternative would be to make the variable nilable but then you'd have to have nil checks later.
<FromGitter> <tenebrousedge> it's also useful for recursive procs
<FromGitter> <kinxer> @tenebrousedge Interesting. Do you have an example?
<FromGitter> <TedTran15_twitter> I see, thanks guys. I was thinking about it in the wrong way after reading the docs, for some reason I was thinking it just gave it a random value that was of a certain type and I tried to use the uninitialized value and it resulted in a segfault
alexherbo25 has quit [Quit: The Lounge - https://thelounge.chat]
<FromGitter> <tenebrousedge> see the end of the answer
<FromGitter> <straight-shoota> In the minmax methods of #8490 it essentially reserves a space for storing the comparison value and the loop branch for `i == 0` makes sure that on the first iteration an actual value is assigned and the variable will only be read afterwards (in the second iteration or after the loop).
<DeBot> https://github.com/crystal-lang/crystal/pull/8490 (Issue 8440: Inconsistent `Enumerable#minmax`)
alexherbo2 has joined #crystal-lang
<FromGitter> <kinxer> @tenebrousedge Oh, cool. So you use it to have a defined proc that you can then call in the proc's actual definition?
<FromGitter> <tenebrousedge> yes
<FromGitter> <Daniel-Worrall> does tool format skip over macros?
<FromGitter> <Daniel-Worrall> I swear it's ignoring the tabs
<FromGitter> <watzon> I believe it does
<FromGitter> <Daniel-Worrall> that's inconvenient. I commited bad tabbing by accident because of that
<FromGitter> <kinxer> An update to my (perhaps ill-advised) `publicize` macro from earlier: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dd479a25eb2e813db5686ab]
<FromGitter> <tenebrousedge> I wouldn't say ill-advised. More like "highly situational"
<FromGitter> <kinxer> That's a fair point, though that sounds a bit like a positive spin on it. I'm also not sure if there are more concise ways of expressing what the macro is doing, since this is one of my first real forays into macros.
<FromGitter> <jwoertink> With json, I can do `JSON::Any.new({} of String => JSON::Any)` to create just an empty JSON::Any
<FromGitter> <jwoertink> what's the equivalent for an array of hashes?
<FromGitter> <jwoertink> `JSON::Any.new([] of Hash(String, String))`
<FromGitter> <jwoertink> that doesn't compile
<FromGitter> <tenebrousedge> `Array(Hash(String, String)).new` maybe?
<FromGitter> <tenebrousedge> the `of` syntax sometimes fails
<FromGitter> <jwoertink> hmm nope.
<FromGitter> <jwoertink> > Error: no overload matches 'JSON::Any.new' with type Array(Hash(String, String))
<FromGitter> <jwoertink> looks like `[] of JSON::Any` works...
<FromGitter> <jwoertink> that might be ok
<FromGitter> <jwoertink> not quite what I was hoping for, but I can probably make due with that
<FromGitter> <tenebrousedge> isn't part of `Type` `Array(Any)` ?
<FromGitter> <tenebrousedge> looks like it
<FromGitter> <jwoertink> yeah, so I could do `JSON::Any.new(Array(JSON::Any).new)`
<FromGitter> <tenebrousedge> or `JSON::Any(JSON::Type.new)`, if that's a thing
dwdv_ has joined #crystal-lang