ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.34.0 | 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
deavmi has quit [Ping timeout: 258 seconds]
<FromGitter> <Blacksmoke16> another new DI feature:
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed83acc2c49c45f5abf3962]
<FromGitter> <Blacksmoke16> can now type bindings, so multiple bindings with the same name can exist with different type restrictions
<FromGitter> <Blacksmoke16> and will be resolved correctly based on name (+ type if given)
deavmi has joined #crystal-lang
<FromGitter> <evvo> @Blacksmoke16 , I think that `.allocate` might work for these classes as it seems to initialize the object with default values
<FromGitter> <Blacksmoke16> Oh? I'd doubt it
<FromGitter> <evvo> I'm not sure exactly what it does
<FromGitter> <Blacksmoke16> It allocates the memory for the type, but leaves the ivars uninitialized afaik
<FromGitter> <evvo> So, they are not nil, but without a default value either ?
<FromGitter> <evvo> https://play.crystal-lang.org/#/r/97d5 - it does not like it
<FromGitter> <Blacksmoke16> right, its prob pointing to random memory
<FromGitter> <Blacksmoke16> https://crystal-lang.org/reference/syntax_and_semantics/declare_var.html essentially are doing this
<FromGitter> <evvo> Is there anything similar to `allocate` that initializes the non-nillable variables with default values ?
<FromGitter> <Blacksmoke16> no, crystal doesnt have default values like Go
<FromGitter> <Blacksmoke16> unless you provide them
<FromGitter> <Blacksmoke16> or make it nilable
<FromGitter> <evvo> hmm
<FromGitter> <evvo> So allocate will initialize all properties with `uninitialized [Type]` ?
<FromGitter> <evvo> So, that should be generally safe ? ⏎ https://play.crystal-lang.org/#/r/97d8
<FromGitter> <Blacksmoke16> Afaik?
<FromGitter> <Blacksmoke16> No, not safe
<FromGitter> <Blacksmoke16> If you try to access them before setting it'll segfault like you saw before
<FromGitter> <evvo> Yes, sorry - I meant that it will be generally safe if all variables are set before accessing them
<FromGitter> <Blacksmoke16> I suppose
<FromGitter> <evvo> Works perfectly for my use case, it seems, however that segfault "around the corner" is quite a burden
<FromGitter> <Blacksmoke16> Indeed
<FromGitter> <watzon> Is there something like `Enumerable#in_groups_of`, but that doesn't ensure the returned array contains exactly N items?
<FromGitter> <watzon> Because `in_groups_of` will fill the remaining slots with something, like nil values, if there aren't enough items left
renich has joined #crystal-lang
<ryanprior> watzon: you can cast an enumerable to an iterator with `.each` and then call `.first(N)` until `.empty?` is true, collecting the results.
renich_ has joined #crystal-lang
renich has quit [Ping timeout: 272 seconds]
renich_ is now known as renich
nowhereFast has joined #crystal-lang
<nowhereFast> https://play.crystal-lang.org/#/r/97dj on ln:17 a Hash is turned into a String representing Json, then into a JSON::Any. Is there a more direct way to cast Hash to JSON::Any?
<FromGitter> <Blacksmoke16> whats the reasoning for wanting to store it as `JSON::Any` in the first place?
<FromGitter> <Blacksmoke16> normally you want a smaller union, not a bigger one
<nowhereFast> the source could be externally provided JSON, or internally generated data. In the example, include JSON::Serializable is used to define a DTO that unifies both. Is there a more fitting way of modelling this?
<nowhereFast> when externally provided, we're just carrying it along, when internally provided (and the content of the blob here could vary), we'd like it to go along with the dto.
<nowhereFast> the dto ends up getting turned back to json and passed on to a different destination
<FromGitter> <Blacksmoke16> is the structure of the data the same?
<FromGitter> <Blacksmoke16> just can be generated in two places?
<nowhereFast> no, the structure is not, which is what led me down the path of trying to leverage JSON::Any for this
<FromGitter> <Blacksmoke16> could you just generate a JSON string instead of a hash
<FromGitter> <Blacksmoke16> then `.from_json` would work for both cases
<FromGitter> <Blacksmoke16> if the structure is dynamic it'll be hard to use types to model the data
<nowhereFast> That could be done with the hash, but I'm thinking of using named tuples for the internally generated variants for the benefit of having types while it flows through the system
<FromGitter> <Blacksmoke16> if thats an option it would be better, but those cannot be built at runtime
<FromGitter> <Blacksmoke16> could possibly use a generic type, like `Container.new internal_data`
<FromGitter> <Blacksmoke16> where its
<FromGitter> <Blacksmoke16> ```record Container(T), data : T```
<FromGitter> <Blacksmoke16> idk, i dont really understand the situation enough
<nowhereFast> the internally generated blobs can be defined as named tuples, there would be a few different variants, which we care about to the point that they get added to the DTO
<FromGitter> <Blacksmoke16> do you know what type it'll be before hand?
<FromGitter> <Blacksmoke16> because you could have multiple ivars on the dto, then assign the internal data to the correct one based on the variant it is
<FromGitter> <Blacksmoke16> is the structure the same for each variant? Or is it totally different every time?
<nowhereFast> well, you've given me record and ivar to look into
<nowhereFast> the variants could be totally different
<FromGitter> <Blacksmoke16> alright, so deff not modelable via `JSON::Serializable`
<nowhereFast> I don't need them to be by the time they get to the DTO
<FromGitter> <Blacksmoke16> i dont suppose you could share what the data looks like?
<nowhereFast> it's Keys and values, no nesting, with no consistency across keys or value types
<FromGitter> <Blacksmoke16> i mean like cant even say the keys/values are all either a string, bool, or number?
<nowhereFast> per case yes, but not across cases
<FromGitter> <Blacksmoke16> if there's not nesting, what other options would there be?
<FromGitter> <Blacksmoke16> like arrays or?
<nowhereFast> values could be number, string, bool, arrays of the same might be a possibility
<FromGitter> <Blacksmoke16> because you could create a hash of that type
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed86220225dc25f54c53e85]
<nowhereFast> over using JSON::Any, a Hash containing all possibilies
<FromGitter> <Blacksmoke16> prob could also do something like
<nowhereFast> that could get pretty busy
<nowhereFast> If types mattered at DTO level, perhaps that would be useful
<nowhereFast> but in this case, it's right at the boundary of the app
<nowhereFast> I suppose what I'm after is a way of holding a Hash of any type, so that when to_json is called on the DTO, it behaves as expected.
<FromGitter> <Blacksmoke16> thats what that big unioned hash would get you
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/97dp
<nowhereFast> yup, but as the make up of that union changes, it would have to be updated
<FromGitter> <Blacksmoke16> i mean unless you introduce nested hashes/arrays what else could be added?
<nowhereFast> where JSON::Any says we don't really care at this point
<FromGitter> <Blacksmoke16> best bet would be that example then
<FromGitter> <Blacksmoke16> oo
<FromGitter> <Blacksmoke16> if possible, if you build a `Hash(String, JSON::Any)` internally you can just pass that directly to `JSON::Any.new`
<FromGitter> <Blacksmoke16> i.e. when building your hash, do like `hash["foo"] = JSON::Any.new value`
<nowhereFast> that might do
<nowhereFast> I was hoping for a hash.as(JSON::Any) or something to that effect
<FromGitter> <Blacksmoke16> naw, they're not the same type
<nowhereFast> considering that JSON::Any can #as_h, I expected the other way around to exist too
<FromGitter> <Blacksmoke16> where you see that?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/97ds
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed867477da67d06faee98de]
<nowhereFast> s/#to_h/#as_h
<FromGitter> <Blacksmoke16> yea thats not the same thing
<FromGitter> <Blacksmoke16> `.as_h` is used to resolve the union into a `Hash`
<FromGitter> <Blacksmoke16> since `JSON::Any` internally is represented by a big union
<nowhereFast> is it not casting to a different type?
<FromGitter> <Blacksmoke16> no, its reducing the size of the union to a hash
<FromGitter> <Blacksmoke16> sec
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/97dw
<FromGitter> <Blacksmoke16> its not really any diff than like
<FromGitter> <Blacksmoke16> ```val = 1 || 0 ⏎ val.as(Int32)``` [https://gitter.im/crystal-lang/crystal?at=5ed868217da67d06faee9ab9]
<FromGitter> <Blacksmoke16> `val = 1 || nil`
<FromGitter> <Blacksmoke16> my bad
<nowhereFast> okay, but if it exists as a convenience for going to hash, going from hash to the larger union of JSON::Any was my initial assumption
<nowhereFast> assumptions :)
<FromGitter> <Blacksmoke16> normally you want to avoid larger unions like this, or JSON::Any
<FromGitter> <Blacksmoke16> as you lose type safety. prob easier to do this in ruby
<nowhereFast> yup, boundaries of an app are interesting places under certain constraints
nowhereFast has quit [Ping timeout: 246 seconds]
sz0 has quit [Quit: Connection closed for inactivity]
renich has quit [Quit: renich]
_ht has joined #crystal-lang
alexherbo2 has joined #crystal-lang
woodruffw has quit [Ping timeout: 260 seconds]
woodruffw has joined #crystal-lang
woodruffw has quit [Ping timeout: 256 seconds]
woodruffw has joined #crystal-lang
alexherbo20 has joined #crystal-lang
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 264 seconds]
alexherbo20 is now known as alexherbo2
zorp_ has joined #crystal-lang
HumanGeek has joined #crystal-lang
Human_G33k has quit [Read error: Connection reset by peer]
Mikaela6 has joined #crystal-lang
Mikaela has quit [Quit: Ping timeout (120 seconds)]
Mikaela6 is now known as Mikaela
masterdonx2 has joined #crystal-lang
MasterdonX has quit [Ping timeout: 265 seconds]
Mikaela has left #crystal-lang [#crystal-lang]
zorp_ has quit [Ping timeout: 256 seconds]
alexherbo23 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 272 seconds]
alexherbo23 is now known as alexherbo2
ua has quit [Ping timeout: 256 seconds]
sz0 has joined #crystal-lang
ua has joined #crystal-lang
alexherbo28 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 264 seconds]
alexherbo28 is now known as alexherbo2
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
lvmbdv1 has joined #crystal-lang
Flipez9 has joined #crystal-lang
justinmcp has joined #crystal-lang
woodruffw has quit [Ping timeout: 246 seconds]
lvmbdv has quit [Ping timeout: 246 seconds]
lvmbdv1 is now known as lvmbdv
Flipez has quit [Ping timeout: 264 seconds]
justinmcp_ has quit [Ping timeout: 264 seconds]
Flipez9 is now known as Flipez
woodruffw has joined #crystal-lang
mjblack has joined #crystal-lang
<FromGitter> <Blacksmoke16> what does building/running with `--no-codegen` actually mean in practice?
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
<FromGitter> <naqvis> I think its like running the validation check without going through whole fuss
<FromGitter> <naqvis> it will display warnings/errors if there are
<FromGitter> <Blacksmoke16> but like doesnt generate the related code? wouldnt that be required for it to run?
<FromGitter> <naqvis> it won't generate the binary, but does go through lexer/parser/AST etc
<FromGitter> <Blacksmoke16> ahh that makes more sense
<FromGitter> <Blacksmoke16> thanks
<FromGitter> <naqvis> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed8fe4a7da67d06faf0153e]
<FromGitter> <Blacksmoke16> then does using it with `crystal run` even make sense, since it wouldnt generate something to build?
<FromGitter> <Blacksmoke16> to run*&
<FromGitter> <naqvis> yeah
<FromGitter> <naqvis> good to use when doing a syntax/validation check
<FromGitter> <naqvis> to avoid code-gen/linking steps
<FromGitter> <Blacksmoke16> gotcha
<FromGitter> <naqvis> just to ensure whole code-base is in compilable state
zorp_ has joined #crystal-lang
<straight-shoota> --no-codegen does full semantic analysis, but doesn't generate any code (as the name suggests)
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <evvo> Does someone knows if there is any way for extracting macro logic to another macro ? ⏎ For example: ⏎ ⏎ ```code paste, see link``` ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5ed90dbd3ffa6106f1f4b393]
<FromGitter> <Blacksmoke16> https://github.com/crystal-lang/crystal/pull/9091 wont be till after `1.0.0` tho
<FromGitter> <evvo> @Blacksmoke16 , so, from what I read in the GitHub issue, currently there is no way for this to be done ?
<FromGitter> <Blacksmoke16> correct
<FromGitter> <evvo> In that case, how to prevent writing a lot of code in certain macros ? Some macros might reach 100+ lines easily if code is not extracted ?
<FromGitter> <Blacksmoke16> you cant
<FromGitter> <Blacksmoke16> just have to deal with it
<FromGitter> <Blacksmoke16> you can use variables and stuff, but currently cant extract common logic, so you would have to duplicate it
<FromGitter> <Blacksmoke16> not ideal but :shrug:
<FromGitter> <Blacksmoke16> oh wait
<FromGitter> <Blacksmoke16> to be clear your example is fine and would work i think
<FromGitter> <Blacksmoke16> the problem that PR is trying to address is sharing macro logic within other macros. In your case you're just using a macro to place down another macro within the generated code
<FromGitter> <evvo> It does not work - here is a more detailed example: ⏎ https://play.crystal-lang.org/#/r/97gp
<FromGitter> <Blacksmoke16> mm
<FromGitter> <evvo> I actually don't need a full reuse for sharing the macro code - even just inserting a block of code will be fine for now - something like: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed911d6778fad0b1347f48e]
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/97h5
<FromGitter> <Blacksmoke16> just pass the name/type/value to the other macro, versus the actual ivar
ht_ has joined #crystal-lang
_ht has quit [Ping timeout: 256 seconds]
ht_ is now known as _ht
<FromGitter> <evvo> https://play.crystal-lang.org/#/r/97ho - it works, however it seems that there is a problem with union types
<FromGitter> <evvo> Maybe related to this ? https://github.com/crystal-lang/crystal/issues/5258
<FromGitter> <Blacksmoke16> hm, rip
<FromGitter> <Blacksmoke16> prob easier at this point to just have it all in one macro then
<FromGitter> <evvo> I actually found a workaround just a few seconds ago :)
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <evvo> ```{% if ivar_type.includes?("Nil") %} ⏎ ...``` [https://gitter.im/crystal-lang/crystal?at=5ed923eedaf4cf366edffe37]
mntmn_ has quit [Quit: WeeChat 1.6]
<FromGitter> <Blacksmoke16> wont handle `String?`
<FromGitter> <Blacksmoke16> unless at macro time that gets expanded to `String | Nil`
<FromGitter> <evvo> It will be expanded, yes
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <evvo> And that returns an Expression
<FromGitter> <evvo> Hopefully no one creates a class with name `SomeNil`
<FromGitter> <evvo> Maybe `.includes?("| Nil")` will work better
<FromGitter> <Blacksmoke16> assuming its never `Nil | String`
<FromGitter> <evvo> I see that usually Nil is the last in the list of unions
<FromGitter> <evvo> I'm not sure if that is always the case ?
<FromGitter> <Blacksmoke16> dunno
<FromGitter> <evvo> I ended up returning the macros back, as there were more workarounds that I had to apply, which will make the code even more complex, instead of cleaning it :)
<FromGitter> <Blacksmoke16> 👍
kerframil has joined #crystal-lang
ua has quit [Ping timeout: 260 seconds]
alexherbo2 has quit [Read error: Connection reset by peer]
alexherbo2 has joined #crystal-lang
ua has joined #crystal-lang
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#842caa9 (ci/update-next - Temp: Simulate next gen): The build is still failing. https://travis-ci.org/crystal-lang/crystal/builds/694776573
travis-ci has left #crystal-lang [#crystal-lang]
zorp_ has quit [Ping timeout: 260 seconds]
<FromGitter> <watzon> I have to say, the ability to have optional dependencies would be really nice
<jhass> just don't declare and only document them?
<jhass> and then have a second require to include the functionality
<jhass> maybe add them as dev dependencies for working on the shard
<FromGitter> <Blacksmoke16> composer has https://getcomposer.org/doc/04-schema.md#suggest
<FromGitter> <Blacksmoke16> takes more of an informational approach, versus adding extra resolving logic into shards or whatever
<jhass> not disagreeing, just pointing out workarounds
<jhass> but I can't say I see it as tooo important either
<jhass> it seems like a rare thing
<FromGitter> <Blacksmoke16> it'll be pretty common for how i been building out some athena stuff
<FromGitter> <Blacksmoke16> since some of the shards are optional
<FromGitter> <Blacksmoke16> which im just setting up like, install the shard, then do a `require "athena/ext/serializer"`
<FromGitter> <Blacksmoke16> or something along those lines, tbd
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
_ht has quit [Quit: _ht]
Human_G33k has joined #crystal-lang
HumanGeek has quit [Ping timeout: 256 seconds]
issyl0 has quit [Ping timeout: 272 seconds]
jetpack_joe has quit [Ping timeout: 260 seconds]
melthelesbian has quit [Ping timeout: 246 seconds]
kevinsjoberg has quit [Ping timeout: 246 seconds]
kevinsjoberg has joined #crystal-lang
Liothen has quit [Ping timeout: 260 seconds]
melthelesbian has joined #crystal-lang
sz0 has quit [Ping timeout: 256 seconds]
OvermindDL1 has quit [Ping timeout: 260 seconds]
jetpack_joe has joined #crystal-lang
OvermindDL1 has joined #crystal-lang
Liothen has joined #crystal-lang
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#f324905 (master - Tidy up Makefile and crystal env output (#9423)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/694826035
travis-ci has left #crystal-lang [#crystal-lang]
<DeBot> https://github.com/crystal-lang/crystal/pull/9423 (Tidy up Makefile and crystal env output)
issyl0 has joined #crystal-lang
sz0 has joined #crystal-lang
<FromGitter> <codenoid> how you doin crystal folks
<FromGitter> <Blacksmoke16> o/
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#7ad381a (ci/update - Temp: Update distribution-scripts): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/694837370
travis-ci has left #crystal-lang [#crystal-lang]
<FromGitter> <Blacksmoke16> hm, is it expected that `obj.responds_to? :private_method` returns true?
<FromGitter> <watzon> What's up @codenoid \o/