RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.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
cremes has joined #crystal-lang
bijan_ has quit [Quit: System has gone to sleep. ZZZzzz…]
<FromGitter> <xfbs> Is there an implementation for diff3 or another diffing algorithm in crystal?
<FromGitter> <xfbs> I saw crystal-diff (https://github.com/MakeNowJust/crystal-diff) but it doesn't seem to work for me :/
<FromGitter> <bew> what doesn't work?
<FromGitter> <xfbs> Well, basically I got a bunch of errors when compiling crystal-diff, so I fixed them (was related to type declarations of instance variables), and then it just failed
<FromGitter> <bew> I just tried to clone and run the specs of this shards, and all specs passes (I'm using Crystal v0.24.1)
<FromGitter> <xfbs> So do I.. that's weird
<FromGitter> <xfbs> okay wait
<FromGitter> <xfbs> Okay that's odd, works for me as well
<railgun> xfbs: does the usage example work for you? just tried and it worked for me, no changes needed
<FromGitter> <bew> @xfbs then your errors comes probably from the code that is using the shard
<FromGitter> <xfbs> Okay, got it compiled without error, usage example works for me standalone
greengriminal has joined #crystal-lang
<FromGitter> <xfbs> Okay this is super weird
<FromGitter> <xfbs> When I clone the shard, run `crystal spec`, all is fine.
<FromGitter> <xfbs> When I add the shard to my project, `require "diff"`, and use `Diff.diff` somewhere in my code, I get:
<FromGitter> <xfbs> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a7e4538e217167e2c65d9a2]
<FromGitter> <bew> are you sure you have the lastest version of it?
<FromGitter> <bew> In the version I just cloned, the initialize looks like `def initialize(@a : A, @b : B)`
<FromGitter> <bew> not `def initialize(@a, @b)`
<FromGitter> <xfbs> Yeah, wait, something is fishy here.
<FromGitter> <xfbs> I think I know why, shards is using v1.0.0, whereas the version I cloned uses `master`
<FromGitter> <bew> maybe you have a shards.lock file, which is blocking the versions?
<FromGitter> <bew> or use `branch: master` in your shards.yml
<FromGitter> <xfbs> Yep, that fixed it! I deleted `shards.lock` and put `branch: master` into the shards file. 👍
<FromGitter> <bew> I think this is because shards uses the last tagged version of the shards you're using, and @MakeNowJust didn't add a tag for the last version. I think you open an issue on his repository to fix this
<FromGitter> <bew> I'm glad it worked ;)
<railgun> xfbs: instead of deleting the shards.lock file you can always use shards update iirc
<FromGitter> <xfbs> Gotcha. :)
cremes has quit [Quit: cremes]
<FromGitter> <bew> @xfbs are you going to create an issue to fix the tag of that shard? (else I'll do it)
<FromGitter> <xfbs> Sure, why not :)
hightower4 has quit [Ping timeout: 265 seconds]
<FromGitter> <xfbs> Alright, all done, git commit -a -m "wip" and off to bed!
<FromGitter> <bew> don't forget the push :p
alex`` has joined #crystal-lang
<watzon> Does anyone know why I'd be getting the error `undefined method 'mapping' for JSON:Module`?
<FromGitter> <bew> how and where are you calling it?
<FromGitter> <bew> note: it's a macro, not a method, so something is wrong with how you call it I think that make the compiler think that you're trying to call a module-method
<watzon> Yeah I figured the issue out. I was putting a space between the key and the type
<watzon> So I guess it thought it was a method
<FromGitter> <bew> Cool! "I was putting a space between the key and the type" I don't see what you mean, can you give an example?
* watzon sent a long message: watzon_2018-02-10_02:12:13.txt <https://matrix.org/_matrix/media/v1/download/matrix.org/okHAFUUqvhGGVAGbwcxiduMQ>
<watzon> So instead of named arguments they were interpreted as a method definition or something
greengriminal has quit [Quit: This computer has gone to sleep]
<FromGitter> <bew> oh tricky typo
<watzon> Definitely haha
<FromGitter> <bew> ok, that's weird https://carc.in/#/r/3jqy
<watzon> Yeah, I feel like that shouldn't happen
<FromGitter> <bew> yep, me too, 'gonna report this
<watzon> This is more what I'd expect
<FromGitter> <bew> yes, the `a : Type` syntax has been introduced not long ago to restrict the possible types of `a`, but it's usually not recommended to use iirc
alex`` has quit [Ping timeout: 256 seconds]
duane has joined #crystal-lang
<FromGitter> <bew> @watzon I've open #5700 on this
<DeBot> https://github.com/crystal-lang/crystal/issues/5700 (`a : Bool` can be read before assignement)
<FromGitter> <bew> I think it describe the problem, what do you think?
<watzon> Yup seems to do the trick
duane has quit [Ping timeout: 240 seconds]
duane has joined #crystal-lang
railgun has left #crystal-lang ["Leaving"]
duane has quit [Ping timeout: 248 seconds]
duane has joined #crystal-lang
faustinoaq has joined #crystal-lang
<FromGitter> <aisrael> Hmmn. So it’s easy to get confused between `a : Type’ and `a: method`. Out of curiousity, why wasn’t the `Type a: method_or_value` syntax considered?
<FromGitter> <aisrael> (And why won’t the Gitter iOS client let me edit or delete messages!?!)
<FromGitter> <bew> (try to double tap the message for edit)
<FromGitter> <aisrael> (I keep trying to. It’s not saving my edit it seems.)
faustinoaq has quit [Quit: IRC client terminated!]
<FromGitter> <bew> @aisrael I think it's because the type is optionnal, and maybe it's hard to tell when there's a type and when not without using a specific syntax like ` : Type`
<FromGitter> <bew> and also, where `a : Type` is used, `a: method` is not used and vice & versa.. `a : Type` is usually used (or not as it's optionnal) in method definition, and `a: method` is used when calling the method
<FromGitter> <bew> like: `def some_method(arg : Bool); end` and calling it: `some_method arg: true`
<FromGitter> <aisrael> Right! In general `a : Type` is used in method declarations, whereas `a: method` is used when calling the method, except in very narrow edge cases (e.g. passing a `Class` as a named parameter or hash).
<FromGitter> <bew> even when passing a class to a method: `method_accepting_class arg: Int32`
<FromGitter> <aisrael> (Was just thinking the `Type a` prefix restriction could still be optional, but then it’d also clash with the `def foo : Type` post-fix declaration style.)
<FromGitter> <bew> you're right
<FromGitter> <aisrael> @bew Yeah I think that’s what sometimes gives even me some confusion. A single space can throw you off
<FromGitter> <bew> the specific cases where you can have things like this: `some_macro a : Bool` is with macros
<FromGitter> <bew> because macros can take anything as parameter, even class/method/etc.. declaration
<FromGitter> <bew> but that's another story... :)
cremes has joined #crystal-lang
cremes has quit [Client Quit]
snsei has joined #crystal-lang
<FromGitter> <Qwerp-Derp> @straight-shoota I guess
<FromGitter> <Qwerp-Derp> I think I'm blaming him too much, in which case I'm sorry
<FromGitter> <Qwerp-Derp> I'm going to start my separate branch of libui anyway
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei_ has joined #crystal-lang
snsei has quit [Ping timeout: 256 seconds]
duane has quit [Ping timeout: 256 seconds]
duane has joined #crystal-lang
* watzon sent a long message: watzon_2018-02-10_06:04:24.txt <https://matrix.org/_matrix/media/v1/download/matrix.org/btVLoscUJYToDElOWMCcmCRF>
<watzon> Am I missing something, or is it already possible to do this?
<watzon> I guess you can technically use a named tuple, right?
<FromGitter> <bew> This is totally possible
<FromGitter> <bew> see the example here: https://crystal-lang.org/api/0.24.1/JSON.html#mapping(_properties_%2Cstrict%3Dfalse)-macro
<watzon> That example is exactly what I'm talking about avoiding though. You have to create two classes and then compose class B into class A, even if that's the only time you're ever going to use class B.
<FromGitter> <bew> ah misread the first line, why `without create multiple classes`
<FromGitter> <bew> ?
<watzon> It's just a little more verbose than I like
<watzon> Especially for large JSON objects
<watzon> I have to go create a class for each and every sub-object
<FromGitter> <bew> then no, there no way to do that, you'll have to create a class (or a struct?) for every sub objects
<FromGitter> <bew> note, if you don't want to have all classes at the same scoping level, you can put all the sub object' classes inside the parent class
<watzon> That's what I thought. It would be nice if we could find a way to change that behaviour
<FromGitter> <bew> another way would be to not use the JSON.mapping macro, and write your mappings manually
<FromGitter> <bew> this is not that hard
<watzon> You mean by just making `to_json` and `from_json` methods?
<FromGitter> <bew> you can look at the code generated by the macro to see exactly how things works
<watzon> That's kinda going in the opposite direction though. Making things more difficult instead of easier ^.^
<FromGitter> <bew> the `from_json` is in fact a `initialize(pull : JSON::PullParser)` (iirc)
<FromGitter> <bew> well, if you find a better way to do this we can see if it's worth adding to the stdlib
<watzon> Wouldn't it be possible to have the macro accept a named tuple as a possible option and then have that named tuple create a struct automatically? Basically the key would be upcased and become the name of the class, and then it would get its own JSON.mapping.
* watzon sent a long message: watzon_2018-02-10_06:17:16.txt <https://matrix.org/_matrix/media/v1/download/matrix.org/UgaXhjxpGEhKqIzySdXvQKFS>
<FromGitter> <bew> not this way
<watzon> Which would generate a Chapters class and a Characters class each with their respective mapping?
<watzon> Why not?
<FromGitter> <bew> because the use of `JSON.mapping a: Type` is already a shortcut to the real: `JSON.mapping a: {type: Type}`, and this nested namedtuple allows you to specify options for the field
<watzon> Ahh right
<FromGitter> <bew> those options are documented in the link I gave you earlier
<watzon> Right, I forgot about that
<watzon> What about nested JSON.mappings?
<FromGitter> <bew> like what?
* watzon sent a long message: watzon_2018-02-10_06:21:33.txt <https://matrix.org/_matrix/media/v1/download/matrix.org/ySweQdGeVJbDajCDXybQpOgI>
<watzon> I feel like I already know the problems with this though
<FromGitter> <bew> yes but no, the nested JSON.mapping are not macros here, and won't be expanded
<watzon> Oh can you not have nested macros? Or is it because they don't expand to anything valid?
<FromGitter> <bew> the arguments you give to a macro can only be descriptive, it is not dynamic, macro calls won't be expanded, it will jus be sent as 'a call to a method JSON.mapping' with this, this and that param
<FromGitter> <bew> to handle this syntax, the JSON.mapping could detect the `JSON.mapping` call, and rewrite it to be expanded later, or something like this, but I feel that it will just not work, or you will hit limitations from the current macro system while trying to do that
<FromGitter> <aisrael> Yeah the lack of nesting in macros does indeed impose a strong limitation on what you can do with them
<FromGitter> <bew> well, you can have macros in macros
<FromGitter> <bew> but you can't expand a macro and directly give the result to another macro
<watzon> I see. Hmm.
<watzon> Really we just need a better system anyway. Personally I like the idea of decorators or metadata tags, but I don't know how that would solve this problem , unless you decorated a class or struct inside of another class or struct.
<watzon> But that is still basically the same issue. Go just has a very elegant way of doing serialization.
<FromGitter> <bew> the metadata is in discussion since quite a long time now, but this will still require you many classes for the many sub objects
kochev has joined #crystal-lang
snsei_ has quit [Remote host closed the connection]
kochev has quit [Ping timeout: 260 seconds]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 276 seconds]
<crystal-gh> [crystal] r00ster91 opened pull request #5701: Use double quotes in html_renderer.cr, begin_code (master...patch-2) https://git.io/vALMi
alex`` has joined #crystal-lang
Ven`` has joined #crystal-lang
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ven`` has joined #crystal-lang
olbat has quit [Ping timeout: 248 seconds]
hightower4 has joined #crystal-lang
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 255 seconds]
<crystal-gh> [crystal] asterite closed pull request #5675: Support BigDecimal comparison with and initialization from BigRational (master...bigdecimal-with-bigrational) https://git.io/vNAIv
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 255 seconds]
<travis-ci> crystal-lang/crystal#ee271d8 (master - Support BigDecimal comparison with and initialization from BigRational): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/339799797
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 276 seconds]
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
bijan_ has joined #crystal-lang
kochev has joined #crystal-lang
hightower2 has joined #crystal-lang
hightower3 has quit [Ping timeout: 276 seconds]
bijan_ is now known as bijan_awaaaay
bijan_awaaaay has quit [Quit: System has gone to sleep. ZZZzzz…]
bijan_ has joined #crystal-lang
bijan_ is now known as bijan_awaaaay
bijan_awaaaay is now known as bijan_
bijan_ is now known as bijan_awaaaay
bijan_awaaaay has quit [Quit: System has gone to sleep. ZZZzzz…]
kochev has quit [Ping timeout: 276 seconds]
<FromGitter> <xfbs> Is there anything like `File.split("/usr/bin/env") => ["usr", "bin", "env"]` in crystal?
olbat has joined #crystal-lang
olbat has quit [Changing host]
olbat has joined #crystal-lang
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 265 seconds]
<FromGitter> <straight-shoota> Not excactly, no
<FromGitter> <straight-shoota> you can do something like "`/usr/bin/env".split(File::SEPARATOR)`
<FromGitter> <xfbs> Alright, that's what I'm doing right now. Is there a reason that File.split(path) doesn't exist tho?
<FromGitter> <straight-shoota> #5635 might add this
<DeBot> https://github.com/crystal-lang/crystal/pull/5635 ([WIP] Implement Path type)
<FromGitter> <straight-shoota> but I don't really know why you would need that
<FromGitter> <straight-shoota> what are you doing?
<FromGitter> <xfbs> It's just semantically cleaner to write `File.split(path)` than `path.split(File::SEPARATOR)` I think
<FromGitter> <straight-shoota> yeah, but why do you need the individual path components?
<FromGitter> <straight-shoota> if there's a use case, sure it would be better to have a method for this to be able to handle different path flavours (windows/posix) transparently
<FromGitter> <xfbs> I need to swap "/some/path/a/to/file" to "/some/path/b/to/file"
<FromGitter> <straight-shoota> So you actually want to traverse the parents of a path?
<FromGitter> <xfbs> Not really traverse, just replace the second parent of a file with another
<FromGitter> <straight-shoota> yeah, you want to go up two levels and then down in a different tree
<FromGitter> <xfbs> Basically, yeah. :)
<FromGitter> <straight-shoota> #5635 has Path#parent and Path#basename
<DeBot> https://github.com/crystal-lang/crystal/pull/5635 ([WIP] Implement Path type)
cremes has joined #crystal-lang
<FromGitter> <xfbs> Ahh, damn, that's sweet! Much cleaner
<FromGitter> <straight-shoota> So you could do it like this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a7eededf283b8e54643ec91]
<FromGitter> <straight-shoota> maybe this could even be `orig.parent(2).sibling("b").join(orig.basename(2))
<FromGitter> <xfbs> I'll try out and see if it does what I need :)
bijan_ has joined #crystal-lang
bijan_ is now known as bijan_awaaaay
bijan_awaaaay has quit [Client Quit]
ua has quit [Ping timeout: 260 seconds]
ua has joined #crystal-lang
<FromGitter> <straight-shoota> Please make sure to leave a comment on that PR with your findings
<crystal-gh> [crystal] RX14 closed pull request #5699: Fix YAML::Core parse float with leading 0 or . (master...jm/fix/5698) https://git.io/vAL8q
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 276 seconds]
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 240 seconds]
<travis-ci> crystal-lang/crystal#b30a9cc (master - Fix YAML::Core parse float with leading 0 or . (#5699)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/339839681
<DeBot> https://github.com/crystal-lang/crystal/pull/5699 (Fix YAML::Core parse float with leading 0 or .)
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 276 seconds]
faustinoaq has joined #crystal-lang
moei has joined #crystal-lang
Ven`` has joined #crystal-lang
cremes has quit [Quit: cremes]
cremes has joined #crystal-lang
<FromGitter> <stevensonmt> Think I just figured out a fundamental error I have been making with crystal. In ruby, `nil` is treated as `falsy` but in crystal it is treated as an exception. For instance ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ would execute the else block in ruby but not crystal. Is this right? [https://gitter.im/crystal-lang/crystal?at=5a7f0b9418f388e62687a080]
<Yxhuvud> if you want the ruby behaviour, use []?
<FromGitter> <stevensonmt> what do you mean?
<FromGitter> <stevensonmt> like `myHash[]`?
<FromGitter> <stevensonmt> according to https://crystal-lang.org/docs/syntax_and_semantics/truthy_and_falsey_values.html the conditional in my example should execute but it does not.
<Yxhuvud> no it shouldn't, because Hash#[] raises on not finding the key, whereas Hash#[]? doesn't
<FromGitter> <stevensonmt> Oh, `Hash#[]?` not `Hash#[]`? :)
<FromGitter> <stevensonmt> Thanks.
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 256 seconds]
snsei has joined #crystal-lang
duane has quit [Ping timeout: 248 seconds]
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei_ has joined #crystal-lang
snsei has quit [Ping timeout: 240 seconds]
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ven`` has joined #crystal-lang
faustinoaq has quit [Ping timeout: 240 seconds]
Ven`` has quit [Client Quit]
Ven`` has joined #crystal-lang
cremes has quit [Quit: cremes]
dragonkh has quit [Ping timeout: 268 seconds]
snsei_ has quit [Remote host closed the connection]
cremes has joined #crystal-lang
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 240 seconds]
qard has joined #crystal-lang
qard has quit [Remote host closed the connection]
qard has joined #crystal-lang
qard has quit [Remote host closed the connection]
qard has joined #crystal-lang
qard has quit [Remote host closed the connection]
qard has joined #crystal-lang
qard has quit [Remote host closed the connection]
qard has joined #crystal-lang
qard has quit [Remote host closed the connection]
qard has joined #crystal-lang
qard has quit [Remote host closed the connection]
qard has joined #crystal-lang
qard has quit [Remote host closed the connection]
qard has joined #crystal-lang
qard has quit [Read error: Connection reset by peer]
qard has joined #crystal-lang
qard has quit [Remote host closed the connection]
qard has joined #crystal-lang
qard has quit [Remote host closed the connection]
qard has joined #crystal-lang
qard has quit [Remote host closed the connection]
cremes has quit [Quit: cremes]
cremes has joined #crystal-lang
faustinoaq has joined #crystal-lang
paleorange_h has quit [Ping timeout: 260 seconds]
<greenbigfrog> If I have sth like `@sth = Set(UInt64).new`, how can @sth still be nil?
<greenbigfrog> Eg. I'm getting `undefined method 'empty?' for Nil (compile-time type is (Set(UInt64) | Nil))`
maattdd has joined #crystal-lang
<FromGitter> <bew> where did you set `@sth` ?
cremes has quit [Quit: cremes]
duane has joined #crystal-lang
<jokke> is there a similar literal to %w[ ... ] for string tuples?
<Papierkorb> no
<jokke> hm :(
hightower4 has quit [Ping timeout: 240 seconds]
<greenbigfrog> inside a initialize
<greenbigfrog> bew ping
<FromGitter> <bew> weird then, can you share a reproductible example?
hightower4 has joined #crystal-lang
<greenbigfrog> I could push the code, but haven't been able to find a reproducable example
maattdd has quit [Ping timeout: 240 seconds]
maattdd has joined #crystal-lang
<FromGitter> <straight-shoota> you could add `@sth : Set(UInt64)` to the type body
<FromGitter> <straight-shoota> the compiler should complain if it could be nil someplace
<FromGitter> <straight-shoota> helps you identify the issue
maattdd has quit [Ping timeout: 256 seconds]
cremes has joined #crystal-lang
<greenbigfrog> good idea :)
<greenbigfrog> Can someone ellaborate what `instance variable '@available_guilds' of DiscordBot was not initialized directly in all of the 'initialize' methods, rendering it nilable. Indirect initialization is not supported.` means?
<FromGitter> <straight-shoota> you have an initializer which doesn't set this instance variable
<FromGitter> <straight-shoota> that's what I expected to be the reason why it could be nil
cremes has quit [Client Quit]
<FromGitter> <bew> thanks @straight-shoota 🙏 I had no idea how to make this more clear 😄
maattdd has joined #crystal-lang
maattdd has quit [Ping timeout: 260 seconds]
<greenbigfrog> hm.. weird...
<greenbigfrog> gonna do some digging :) Thanks
<greenbigfrog> oops... yes... I actually was outside the initializer... gonna have to restructure this...
<greenbigfrog> weird...
<FromGitter> <straight-shoota> 👍
<greenbigfrog> pushing code
<greenbigfrog> Getting: `Error in src/discordtipbot/discordbot.cr:10: instance variable '@available_guilds' of DiscordBot was not initialized directly in all of the 'initialize' methods, rendering it nilable. Indirect initialization is not supported.`
cremes has joined #crystal-lang
maattdd has joined #crystal-lang
<FromGitter> <straight-shoota> whoa that's a huge constructor :D
<FromGitter> <straight-shoota> have you tried removing all non-essential pieces from the constructor?
<FromGitter> <straight-shoota> another idea:
maattdd has quit [Ping timeout: 240 seconds]
<FromGitter> <straight-shoota> since the initializers don't really do anything, you might just put `@unavailable_guilds = Set(UInt64).new` in the type context where you already have the type declaration
<greenbigfrog> oh. right...
<greenbigfrog> thanks. that worked :)
<FromGitter> <xfbs> Say I'm implementing a DSL in crystal for the first time and I don't really know how to go about it. I want the interface to be something like this: ⏎ ⏎ ```def self.message(regex, &block) ⏎ @handlers[regex] = block ⏎ end``` ⏎ ⏎ Then it won't compile, will it, because useful_method is an instance method but the proc is being evaluated in a class method context, right?
<FromGitter> <xfbs> So basically, is there a way for a proc to be evaluated in a specific context (bindings) or like, how does one do this?
<FromGitter> <bew> make it an instance method
<FromGitter> <straight-shoota> you might take a look at kemal
<FromGitter> <bew> and outside the class, or in the initialize (not sure about this) call `message`
<FromGitter> <xfbs> Well, I guess I could do it in the initialize, but then it's not as pretty :(
<FromGitter> <straight-shoota> or rather my stale PR... especially this class https://github.com/kemalcr/kemal/pull/378/files#diff-8eff4c3fbe452fa1e2a1e5d3a650fbc2R87
<FromGitter> <bew> another way would be to 'generate' the initialize, but it's getting macro-heavy here.. probably not the way to go
maattdd has joined #crystal-lang
<FromGitter> <straight-shoota> using macro, it defines a method and adds that methods name to a static list. when an object of the class is initialized, all methods in this list are added or executed or whatever
<FromGitter> <bew> yes good point @straight-shoota (note: you have a bad indent here https://github.com/kemalcr/kemal/pull/378/files#diff-8eff4c3fbe452fa1e2a1e5d3a650fbc2R128)
<FromGitter> <straight-shoota> :P
<FromGitter> <straight-shoota> this could certainly work without macros, depending on what you need
<FromGitter> <xfbs> How could I make this work without macros?
<FromGitter> <xfbs> I'd like a nice clean interface but I don't want to overcomplicate things :p
<FromGitter> <bew> this is the hardest balance to find :P
maattdd has quit [Ping timeout: 240 seconds]
<FromGitter> <straight-shoota> well, without macros you can't simply execute the block in the context of the instance, that won't work as far as I know.
<FromGitter> <straight-shoota> but you could pass the instance as an parameter to the block
<FromGitter> <straight-shoota> https://carc.in/#/r/3jxo
maattdd has joined #crystal-lang
cremes has quit [Quit: cremes]
ogotai has quit [Remote host closed the connection]
maattdd has quit [Ping timeout: 264 seconds]
<FromGitter> <straight-shoota> or with macros: https://carc.in/#/r/3jy9
maattdd has joined #crystal-lang
<FromGitter> <xfbs> Damn, the macros solution isn't the bad actually
<FromGitter> <xfbs> *that
maattdd has quit [Ping timeout: 240 seconds]
maattdd has joined #crystal-lang
maattdd has quit [Ping timeout: 268 seconds]
maattdd has joined #crystal-lang
alex`` has quit [Quit: WeeChat 2.0.1]
maattdd has quit [Ping timeout: 265 seconds]
alex`` has joined #crystal-lang
sandelius has joined #crystal-lang
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
maattdd has joined #crystal-lang
maattdd has quit [Ping timeout: 252 seconds]
cremes has joined #crystal-lang
maattdd has joined #crystal-lang
maattdd has quit [Ping timeout: 248 seconds]
maattdd has joined #crystal-lang
maattdd has quit [Ping timeout: 240 seconds]
<greenbigfrog> Somehow I've got the feeling there's a much nicer and simpler way to write this: https://github.com/greenbigfrog/discordtipbot/blob/653616f64187598b7bed646dc4279ad38b9a39fa/src/discordtipbot/statistics.cr
<FromGitter> <bew> for example for tips, you can do `getter tips : BigDecimal?`
<FromGitter> <bew> this will generate the line `@tips : BigDecimal?` then create a getter
<greenbigfrog> ah. cool. totally an answer that I somehow expected ;)
<FromGitter> <bew> for last, you can do `getter last = Time.utc_now`
<FromGitter> <bew> and simplify the other that looks similar, for the rest I don't think you can do better
<oprypin> greenbigfrog, why is everything '?'
<greenbigfrog> because it can be nil in theory. (or wait... it would be 0)
<oprypin> ...
* greenbigfrog is stupid
<oprypin> on the other hand, you may have some trouble initializing them
<oprypin> unless you just write =0
<greenbigfrog> yep... `instance variable '@transactions' of Statistics was not initialized directly in all of the 'initialize' methods, rendering it nilable. Indirect initialization is not supported.`
maattdd has joined #crystal-lang
* greenbigfrog made the query's none nilable but left the instance variables be
Ven`` has joined #crystal-lang
qard has joined #crystal-lang
maattdd has quit [Ping timeout: 240 seconds]
qard has quit [Client Quit]
return0e has quit [*.net *.split]
juni0r has quit [*.net *.split]
knight_ has quit [*.net *.split]
Guest34371 has quit [*.net *.split]
danzilio has quit [*.net *.split]
gewo has quit [*.net *.split]
kp666[m] has quit [*.net *.split]
pta2002 has quit [*.net *.split]
hmans has quit [*.net *.split]
olbat has quit [*.net *.split]
manveru has quit [*.net *.split]
olbat[m] has quit [*.net *.split]
watzon has quit [*.net *.split]
dyreshark has quit [*.net *.split]
Ven`` has quit [Ping timeout: 240 seconds]
dyreshark has joined #crystal-lang
watzon has joined #crystal-lang
olbat[m] has joined #crystal-lang
manveru has joined #crystal-lang
olbat has joined #crystal-lang
Ven`` has joined #crystal-lang
fifr[m] has quit [Ping timeout: 248 seconds]
desdeux[m] has quit [Ping timeout: 248 seconds]
pta2002 has joined #crystal-lang
knight_ has joined #crystal-lang
danzilio has joined #crystal-lang
return0e has joined #crystal-lang
gewo has joined #crystal-lang
juni0r has joined #crystal-lang
hmans has joined #crystal-lang
kp666[m] has joined #crystal-lang
Guest34371 has joined #crystal-lang
galstar[m] has quit [Ping timeout: 240 seconds]
byteflame has quit [Ping timeout: 240 seconds]
braidn[m] has quit [Ping timeout: 252 seconds]
cptaffe has quit [Ping timeout: 252 seconds]
Renich has quit [Ping timeout: 255 seconds]
kp666[m] has quit [Ping timeout: 255 seconds]
olbat[m] has quit [Ping timeout: 256 seconds]
watzon has quit [Ping timeout: 256 seconds]
<FromGitter> <jwoertink> Hey, is there anyone around that can help me out with something here? https://play.crystal-lang.org/#/r/3jz2
crse[m] has quit [Ping timeout: 276 seconds]
logen[m] has quit [Ping timeout: 276 seconds]
<FromGitter> <jwoertink> I'm not sure what I'm missing here. I think it's because I'm instantiating the hash with a default array. Maybe that's not sticking like I think it should?
maattdd has joined #crystal-lang
greengriminal has joined #crystal-lang
<oprypin> jwoertink, i dont think hash[key] is supposed to add anything to it
<FromGitter> <jwoertink> hmmm
maattdd has quit [Ping timeout: 255 seconds]
<FromGitter> <jwoertink> yeah, if I change this up to
<FromGitter> <jwoertink> ```c.props["one"] = [] of String ⏎ c.props["one"].push("test")``` [https://gitter.im/crystal-lang/crystal?at=5a7f69e318f388e626895ecd]
<FromGitter> <jwoertink> then this works, but then that makes the initialization pointless
greengriminal has quit [Quit: Leaving]
<oprypin> you're just misunderstanding what default means
<oprypin> it should be removed from the language btw
<oprypin> nvm it works https://carc.in/#/r/3jzb
<FromGitter> <jwoertink> yeah ^ that's what I would expect to happen
<FromGitter> <jwoertink> but same with the default array
<FromGitter> <jwoertink> I can use it this way https://play.crystal-lang.org/#/r/3jzd
<FromGitter> <jwoertink> but would that be a bug?
maattdd has joined #crystal-lang
<FromGitter> <jwoertink> So did that ^ work the way you expected?
<oprypin> no
<FromGitter> <jwoertink> Yeah, so it seems to work with integers, just not arrays lol
<oprypin> jwoertink, does this answer your question? https://bpaste.net/show/8b4e4a130b63
<oprypin> it works with integers because i applied a fundamentally different operation to it
<Papierkorb> jwoertink, it's not really surprising once you know how References work. A block returns a new reference each time, while passing a reference into the constructor will always return that reference
<oprypin> jwoertink, https://carc.in/#/r/3jzp
<oprypin> Papierkorb, no, you are saying irrelevant infomation
<oprypin> I would advise to ignore that to avoid confusion
bijan_ has joined #crystal-lang
<Papierkorb> Ah well, then have fun.
bijan_ is now known as bijan_awaaaay
<FromGitter> <jwoertink> hmm
<FromGitter> <jwoertink> What about this one? https://carc.in/#/r/3jzq
maattdd has quit [Ping timeout: 256 seconds]
<FromGitter> <jwoertink> Yeah, I don't think I really understand references
<oprypin> that's irrelevant
bijan_awaaaay has quit [Client Quit]
<oprypin> well, the latest example is actually caused by problems with references
<oprypin> jwoertink, note https://carc.in/#/r/3jzr
<oprypin> you say, when there is a missing key, return this particular instance of array
<FromGitter> <jwoertink> ok, so that actually works the same in ruby. weird.
<oprypin> it does
<oprypin> you get to that particular instance through the default behavior and add something to it
<oprypin> and then again, you get to that particular instance through the default behavior and print it
<oprypin> note that none of this affects the original Hash in any way
<oprypin> basically, until you use `[]=` the Hash doesnt change
<FromGitter> <jwoertink> Cool. Thanks for the explanation.
bijan_awaaaay has joined #crystal-lang
bijan_awaaaay has quit [Client Quit]
maattdd has joined #crystal-lang
qard has joined #crystal-lang
jokke has quit [Quit: WeeChat 2.0.1]
maattdd has quit [Ping timeout: 260 seconds]
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jokke has joined #crystal-lang
bijan_ has joined #crystal-lang
maattdd has joined #crystal-lang
qard has quit [Quit: qard]
maattdd has quit [Ping timeout: 255 seconds]
sandelius has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ven`` has joined #crystal-lang
maattdd has joined #crystal-lang
bijan_ has quit [Quit: Shutting Down Interwebs...Done.]
bijan_ has joined #crystal-lang
cremes has quit [Quit: cremes]
maattdd has quit [Ping timeout: 255 seconds]
<FromGitter> <ezrast> @jwoertink fyi https://play.crystal-lang.org/#/r/3k0t
bijan_ has quit [Quit: System has gone to sleep. ZZZzzz…]
cremes has joined #crystal-lang
<FromGitter> <jwoertink> oh! I didn't even think about doing that in a block
<FromGitter> <jwoertink> Thanks @ezrast!
<FromGitter> <jwoertink> That might be cleaner than how I'm doing it now
olbat[m] has joined #crystal-lang
<FromGitter> <ezrast> just beware that you risk littering empty arrays all over your hash if you rely on that behavior to check for nonexistant keys
maattdd has joined #crystal-lang
maattdd has quit [Ping timeout: 276 seconds]
cremes has quit [Quit: cremes]
<FromGitter> <ezrast> i.e. https://play.crystal-lang.org/#/r/3k0x
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
moei has quit [Quit: Leaving...]
maattdd has joined #crystal-lang
hightower4 has quit [Ping timeout: 256 seconds]
maattdd has quit [Ping timeout: 255 seconds]
<FromGitter> <aisrael> Yeah. The whole “return a new Array as default value” for a Hash gotcha/trick works the same in Ruby
<FromGitter> <xfbs> Is there a way to include members of an enum? Or do I have to manually make aliases? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a7f8319d74ee9f50dab7e74]
<FromGitter> <bew> add `alias` before each
<FromGitter> <bew> Yeah alias
<FromGitter> <bew> Oh you mean do sth like `include SomeEnum`?
<FromGitter> <xfbs> Yeah something like that, basically there are like 15 items in the enum
<FromGitter> <xfbs> I don't want to have to type out `Some::Other::Class::ItemName`
<FromGitter> <xfbs> But I also don't want to have 15 lines of `ItemName = Some::Other::Class::ItemName`
<FromGitter> <xfbs> And I check and it seems like `MyEnum = Some::Other::Class` and then using `MyEnum::ItemName` doesn't seem to work either :(
<FromGitter> <xfbs> Ahh nevermind, using `alias MyEnum = Some::Other::Class::Enum` worked! merci :)
kp666[m] has joined #crystal-lang
fifr[m] has joined #crystal-lang
byteflame has joined #crystal-lang
braidn[m] has joined #crystal-lang
crse[m] has joined #crystal-lang
Renich has joined #crystal-lang
watzon has joined #crystal-lang
galstar[m] has joined #crystal-lang
logen[m] has joined #crystal-lang
cptaffe has joined #crystal-lang
desdeux[m] has joined #crystal-lang