RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.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
<FromGitter> <dscottboggs_gitlab> @Blacksmoke16 my drunk ass was trying to instantiate an abstract class last night lol
<FromGitter> <sam0x17> is there a primer available somewhere on annotations? I can't seem to find anything
<FromGitter> <dscottboggs_gitlab> I'm not sure if there is
<FromGitter> <dscottboggs_gitlab> I should add something to the book on them
<FromGitter> <dscottboggs_gitlab> this might help you some in the meantime https://github.com/crystal-lang/crystal-book/issues/292
<FromGitter> <Blacksmoke16> @dscottboggs_gitlab well done :p
<FromGitter> <dscottboggs_gitlab> yeah that'll show me
jemc has quit [Ping timeout: 245 seconds]
<FromGitter> <sam0x17> thanks @dscottboggs_gitlab
<FromGitter> <dscottboggs_gitlab> np
DTZUZO has quit [Ping timeout: 240 seconds]
<FromGitter> <Blacksmoke16> @sam0x17 I can help as well
<FromGitter> <dscottboggs_gitlab> yes @Blacksmoke16 regularly works with annotations
<FromGitter> <Blacksmoke16> I'm pretty familiar with them if you have questions
<FromGitter> <Blacksmoke16> a quick tl;dr would be they can be applied to classes/structs/methods and ivars
<FromGitter> <Blacksmoke16> they can then be read at compile time
<FromGitter> <Blacksmoke16> currently there isnt a way to get an array of X annotated with Y
<FromGitter> <Blacksmoke16> like
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/64ru
<FromGitter> <Blacksmoke16> can get access to list of ivars like
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/64rw
<FromGitter> <Blacksmoke16> the `instance_vars` is the main way of accessing ivar annotations, i.e. that you could iterate over them, and build out stuff based on the annotations along the way
<FromGitter> <Blacksmoke16> example of that would the the `to_json/yaml` implementations
<FromGitter> <sam0x17> thanks I appreciate it
Yxhuvud has quit [Ping timeout: 264 seconds]
<FromGitter> <Blacksmoke16> Np
jemc has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> ` undefined method 'new'` I'm not drunk this time I swear
<FromGitter> <Blacksmoke16> Link?
<FromGitter> <dscottboggs_gitlab> ah, I didn't commit yet, hang on
<FromGitter> <dscottboggs_gitlab> I tried it with `self.new` as well
<FromGitter> <Blacksmoke16> When
<FromGitter> <Blacksmoke16> Oops
<FromGitter> <Blacksmoke16> Wouldn't self.dup be good enough
<FromGitter> <dscottboggs_gitlab> no I need to deep clone it in this case unfortunately
<FromGitter> <dscottboggs_gitlab> because it's a recursive structure and I'm making changes a level or two down
<FromGitter> <Blacksmoke16> But not sure why that wouldn't work at a glance
<FromGitter> <dscottboggs_gitlab> https://play.crystal-lang.org/#/r/64ry
moei has quit [Ping timeout: 250 seconds]
<FromGitter> <dscottboggs_gitlab> alright what the hell is going on here? https://play.crystal-lang.org/#/r/64s5
<FromGitter> <girng> go to the main crystal website, stare at the animated polyhedron and tild your head to the left very slowly. the crystal text moves O_O
<FromGitter> <dscottboggs_gitlab> #7349
<DeBot> https://github.com/crystal-lang/crystal/issues/7349 (Undefined method `new` for Klass // undefined local variable or method 'new')
Vexatos has quit [Quit: ZNC Quit]
Vexatos has joined #crystal-lang
DTZUZO has joined #crystal-lang
riceandbeans has quit [Quit: leaving]
jemc has quit [Ping timeout: 245 seconds]
shmibs has quit [Quit: leaving =o]
shmibs has joined #crystal-lang
shmibs has quit [Quit: leaving =o]
shmibs has joined #crystal-lang
shmibs has quit [Client Quit]
shmibs has joined #crystal-lang
Yxhuvud has joined #crystal-lang
jemc has joined #crystal-lang
jemc has quit [Ping timeout: 240 seconds]
<FromGitter> <j8r> What about using a struct?
<FromGitter> <sdogruyol> @girng that's quite an observation
jemc has joined #crystal-lang
jemc has quit [Ping timeout: 245 seconds]
mps has quit [Ping timeout: 250 seconds]
ashirase has quit [Ping timeout: 240 seconds]
ashirase has joined #crystal-lang
mps has joined #crystal-lang
<FromGitter> <drum445> Hi guys, the following macro ⏎ ⏎ ```{{obj}}.{{attr}}``` ⏎ ⏎ but get the following: ... [https://gitter.im/crystal-lang/crystal?at=5c52d7f7454aad4df7d00c41]
<FromGitter> <drum445> anyone know how to fix that please?
<FromGitter> <r00ster91> put `.id` after `attr`
<FromGitter> <drum445> Thanks a lot mate !
<FromGitter> <j8r> Does someone used CirrusCI? https://cirrus-ci.org/faq/
<FromGitter> <j8r> I am still searching a CI that supports ARM...
DTZUZO has quit [Ping timeout: 240 seconds]
jemc has joined #crystal-lang
<FromGitter> <waghanza> @j8r travis could do so => https://www.tomaz.me/2013/12/02/running-travis-ci-tests-on-arm.html ⏎ (disclaimer : I've never used this feature from travis)
jemc has quit [Quit: WeeChat 2.2]
jemc has joined #crystal-lang
<FromGitter> <j8r> @waghanza no, not natively
<FromGitter> <j8r> it's using qemu, this can be done in other places too
<FromGitter> <j8r> On local I use https://github.com/multiarch/qemu-user-static
DTZUZO has joined #crystal-lang
Dreamer3 has quit [Quit: Computer has gone to sleep.]
<FromGitter> <simenge> Any macro wizards in the house? I'm trying to implement some pattern matching in the most natural-looking way as a macro. This is what I got so far: https://gist.github.com/simenge/fa5101689093acdf915c0f3e72463fcf
<FromGitter> <simenge> But I'm having trouble extending it to support Arrays. I want to be able to do something like case [:x, y.as(Int)] to match [:x, <random int>]
<FromGitter> <j8r> @simenge It's possible this is already possible in the language
<FromGitter> <simenge> If so, I have no idea how. But I don't think so. I don't think there's a way to match *and bind new variables* to substructures
<FromGitter> <j8r> you can you tell me the end-user API you wan't to implement, and an example?
<FromGitter> <j8r> you can do this https://carc.in/#/r/64ub
<FromGitter> <j8r> not sure it's what you're aiming for
<FromGitter> <simenge> You can do that, but you can't bind new variables to parts of an array that satisfy particular types. I'm writing a compiler, and this sort of pattern-matching is trivial in a language like Haskell or ML. Here's an example: https://gist.github.com/simenge/0beb472a9ddf29f7aa2695a7320ab373 Note that the particular syntax here isn't so important, but I think the example shows what I'm trying to do even if it will
<FromGitter> ... look somewhat different
<jokke> j8r: doen't gitlab-runner run on arm?
<jokke> *doesn't
<jokke> gitlab-ci is the greatest ci i've ever seen :)
<jokke> i build everything there now
<FromGitter> <j8r> @simenge that's because it's an array, why not having /converting to a Tuple
<FromGitter> <j8r> if it match, you can add an element to the tuple to create a new one
<FromGitter> <simenge> @j8r I don't know the types at compile-type. The array may be of arbitrary size and each position may be any of a number of types depending on the AST it represents. Also, your example doesn't bind new variables to particular tuple elements if and only if they match particular types
<FromGitter> <j8r> else you can iterate over the array, with a case;whens
<FromGitter> <j8r> like we do in typical parser
sagax has quit [Ping timeout: 272 seconds]
<FromGitter> <j8r> it's longer, but more optimized and configurable
<FromGitter> <simenge> That's what I currently do, and it works, but it quickly gets complex and the cognitive load is exponentially higher
<FromGitter> <simenge> This sort of symbolic transformation of deeply nested data structures is like THE killer app for pattern matching. If there's no way to do it, I guess I'll just give it up, but I was hoping I could get something working with macros
<FromGitter> <aemadrid> anybody know of JSON::Schema in Crystal? can’t find anything
<FromGitter> <Blacksmoke16> @aemadrid to do what? to handle serialization/deserialization? or?
<FromGitter> <aemadrid> not so much but to make sure a payload is valid
<FromGitter> <aemadrid> serialization would be a nice to have too
<FromGitter> <Blacksmoke16> https://github.com/Blacksmoke16/CrSerializer/tree/master/docs i have a shard for that :)
<FromGitter> <aemadrid> what I’m looking forward is a shard that at least can tell me given a JSON payload and a JSON schema that the payload is valid
<FromGitter> <aemadrid> according to https://json-schema.org/
<FromGitter> <aemadrid> so instead of defining the schema in Crystal I’d define the schema in JSON
<Yxhuvud> that would be nice to have indeed
<FromGitter> <Blacksmoke16> valid in regards that the payload is valid JSON?
<FromGitter> <aemadrid> it fully validates types, formats, required/optional, etc
<FromGitter> <aemadrid> JSON Schema has quite a lot of things it can validate
<FromGitter> <Blacksmoke16> you could probably make a macro that given a structured json string, build out properites and stuff
<FromGitter> <Blacksmoke16> similar to how the stdlib `JSON.mapping` works
<FromGitter> <aemadrid> en example: ```schema = { ⏎ "type" => "object", ⏎ "required" => ["a"], ⏎ "properties" => { ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5c532debca428b064532471b]
<FromGitter> <j8r> It will always be more efficient to define the schema in the app
<FromGitter> <aemadrid> my use case is not about speed/efficiency but sharing data between multiple services in multiple languages
<FromGitter> <Blacksmoke16> benefit of that would be since its based on a standard spec, could be used no matter the lang
<FromGitter> <Blacksmoke16> ^ :p
<FromGitter> <j8r> @aemadrid or, it can be possible in a macro
<FromGitter> <aemadrid> that’s why JSON::Schema is appealing to me
<FromGitter> <j8r> a macro that reads the file at compile time
<FromGitter> <Blacksmoke16> yea, thats doable now
<FromGitter> <aemadrid> in my case the schemas will come live
<robacarp> there's always protobuf or the apache thing
<FromGitter> <aemadrid> so I would need to validate payloads against schemas online
<robacarp> thrift?
<FromGitter> <j8r> msgpack :°
<FromGitter> <j8r> it's compatible with JSON
<robacarp> yeah, msgpack
sagax has joined #crystal-lang
<FromGitter> <aemadrid> I like msgpack but my team likes JSON much better
<FromGitter> <aemadrid> for inter services communication
<robacarp> I don't think you're going to be able to get away from a central queryable schema though...it's hard to ensure that everything stays in sync without it
<robacarp> you'll also need to have object versions
<FromGitter> <aemadrid> I’d like to build a central json schema store with Crystal in short
<FromGitter> <aemadrid> without json schema suport I’d need to build it in Ruby
<FromGitter> <Blacksmoke16> prob wouldnt be too hard to write something that generates the schema for a given class
<FromGitter> <Blacksmoke16> based on ivar types and stuff
<FromGitter> <Blacksmoke16> and the reverse would also prob be doable, given a string use a macro to build out a class with those properties/types
<FromGitter> <Blacksmoke16> but thats not something that exists atm afaik
<FromGitter> <aemadrid> cool, just checking
<FromGitter> <Blacksmoke16> assuming that example you posted is the desired output?
<FromGitter> <Blacksmoke16> `{ "type" => "object", "required" => ["a"], "properties" => { "a" => {"type" => "integer"} } }` but ofc in json
<FromGitter> <aemadrid> the desired result is given a json payload and a json schema I can validate it. Like ```begin ⏎ JSON::Validator.validate!(schema, { "a" => "taco" }) ⏎ rescue JSON::Schema::ValidationError => e ⏎ e.message ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5c533021454aad4df7d288a0]
<FromGitter> <aemadrid> so if it passes all good
<FromGitter> <aemadrid> if it doesn’t I get an exception with error messages
<FromGitter> <aemadrid> or a `JSON::Validator.validate` that returns success/failure and error messages
<FromGitter> <aemadrid> in other words, the schemas can come from an api
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/64x4
<FromGitter> <Blacksmoke16> would obs have to have a way to map crystal types to standard types
<FromGitter> <Blacksmoke16> challenge would be validating something given a string of json like that
<FromGitter> <Blacksmoke16> would be a neat project
<FromGitter> <jwoertink> Is there a better way to get the raw body in an HTTP POST than doing `@context.request.body.not_nil!.gets_to_end`?
<FromGitter> <jwoertink> I ran in to an unexpected error when doing this where my params were empty after calling this. I'm assuming body is an IO object that would have to rewind in this case
<FromGitter> <Blacksmoke16> prob better to check if the body exists
<FromGitter> <Blacksmoke16> like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c533c4e54f21a71a1d887d9]
<FromGitter> <Blacksmoke16> in the else block could throw an error/400 that its required as well
<FromGitter> <aemadrid> @Blacksmoke16 interesting
<FromGitter> <jwoertink> I was just doing it for logging purposes, so I didn't really need any logic. But I guess if I can set it to a separate variable, then I don't have to worry about rewinding the main object
<FromGitter> <Blacksmoke16> i dont have any ideas on how you would go about doing the validation atm. Main pain point would be if you didnt deserialize the json string into an object, you would be dealing with `JSON::Any` which would kinda be a pain to work with
<FromGitter> <Blacksmoke16> esp if you have nested structures and stuff
return0e has quit [Remote host closed the connection]
return0e has joined #crystal-lang
return0e has quit [Remote host closed the connection]
return0e has joined #crystal-lang
sagax has quit [Ping timeout: 268 seconds]
bmcginty has joined #crystal-lang
bmcginty has quit [Quit: leaving]
jemc has quit [Ping timeout: 250 seconds]
jemc has joined #crystal-lang
marmotini_ has joined #crystal-lang
marmotini_ has quit [Ping timeout: 246 seconds]
marmotini_ has joined #crystal-lang
marmotini_ has quit [Ping timeout: 240 seconds]
<FromGitter> <girng> @sdogruyol thanks. was pretty bored last night lolz.
g- has quit [Quit: leaving]