<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>
<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?
<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
<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>
<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]
<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>
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>
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
<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
<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>
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>
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>
<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>
<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
<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
<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
<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