<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>
<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>
<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> 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>
<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> 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> 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.