jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.28.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> <girng> crystal.cr ⏎ Your domain is available! ⏎ ⏎ 1) 99 USD [https://gitter.im/crystal-lang/crystal?at=5cd36dcd5a1d435d460b7bdc]
<FromGitter> <kevinelliott> @mwlang HAHA
<beepdog> Good luck @mwatzon!
<FromGitter> <girng> @watzon Damn no kidding eh
<FromGitter> <kevinelliott> Yeah, would be sweet if `.cr` were cheaper and then our shards could get more official websites ;)
<FromGitter> <kevinelliott> $120 is a lot to spend on open source project domains
<FromGitter> <Blacksmoke16> only $10 a month
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <kevinelliott> ha
<FromGitter> <watzon> I just think that shards.cr would be awesome for a more Rubygems like site if crystal shards was to go that way
<FromGitter> <kevinelliott> I have hundreds of domains. Highest I'm paying is $45 for a domain. I couldn't fathom $120.
<FromGitter> <kevinelliott> @watzon We're building one on shardbox.org/shardbox.io
<FromGitter> <kevinelliott> But yeah, `shards.cr` would be sweet.
return0e has joined #crystal-lang
<FromGitter> <watzon> Will shardbox be like rubygems and npmjs? Like with a central repo and everything?
waheedi has quit [Quit: waheedi]
<FromGitter> <watzon> @kevinelliott
<FromGitter> <kevinelliott> @watzon Starting off to be like ruby-toolbox.com
<FromGitter> <kevinelliott> But could easily grow to be a repo too. We'll see.
<FromGitter> <watzon> Sounds awesome
return0e has quit [Ping timeout: 255 seconds]
alexherbo200 has joined #crystal-lang
alexherbo20 has quit [Ping timeout: 258 seconds]
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6vlq
<FromGitter> <Blacksmoke16> should it not know this is a valid type?
<FromGitter> <dscottboggs_gitlab> Nope
<FromGitter> <dscottboggs_gitlab> wait
<FromGitter> <dscottboggs_gitlab> yeah
<FromGitter> <dscottboggs_gitlab> https://play.crystal-lang.org/#/r/6vlr
<FromGitter> <Blacksmoke16> thats a bit annoying
<FromGitter> <Blacksmoke16> i fixed it
<FromGitter> <Blacksmoke16> ` alias LogContext = Hash(String, ContextType)`
<FromGitter> <Blacksmoke16> then just `LogContext{"user" => 99}`
<FromGitter> <Blacksmoke16> works for me :shrug:
laaron- has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> can you render an ECR string from a constant?
<FromGitter> <Blacksmoke16> the answer is no ^ rip
mps has quit [Ping timeout: 248 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <watzon> I really wish `String#gsub!` existed in Crystal
<FromGitter> <watzon> It's the little things
<FromGitter> <yxhuvud> Well, strings are immutable, so it is out.
<FromGitter> <watzon> Yeah I know, it just makes things a little easier sometimes
<FromGitter> <watzon> Oh well lol
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
waheedi has joined #crystal-lang
<FromGitter> <bew> @watzon cool news ;)
rohitpaulk has joined #crystal-lang
return0e has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
mps has joined #crystal-lang
return0e has quit [Remote host closed the connection]
return0e has joined #crystal-lang
<FromGitter> <vladfaust> I always forget to bump version in `shard.yml` on minor releases. So disturbing =(
<FromGitter> <waghanza> with ⏎ ~~~crystal ⏎ Onyx::HTTP.on "/user" do |r| ⏎ r.get "/:id", IDEndpoint ⏎ r.post "/", EmptyEndpoint ... [https://gitter.im/crystal-lang/crystal?at=5cd3f9738fcdb05d47a5a17f]
<FromGitter> <waghanza> on `0.4.2`
<FromGitter> <waghanza> Have I to explicitly define methods ?
woodruffw has quit [Ping timeout: 268 seconds]
woodruffw has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cd417388fcdb05d47a685ba]
<FromGitter> <Blacksmoke16> kinda a misleading error message :p
alexherbo2007 has joined #crystal-lang
alexherbo200 has quit [Ping timeout: 268 seconds]
waheedi has quit [Quit: waheedi]
<FromGitter> <j8r> Path is kinda useless :(
<FromGitter> <j8r> instead of `File.basename(File.dirname("a/b/c"))`, we can now do `Path[Path["a/b/c"].dirname].basename`... yeah
<FromGitter> <j8r> `Path#dirname` will better return a `Path`, not `String`
<FromGitter> <j8r> `Path` helps mainly for documentation for now, and that's a good start
laaron- has joined #crystal-lang
laaron has quit [Remote host closed the connection]
<FromGitter> <j8r> What's also annoying is to `.to_s` everywhere :(
<FromGitter> <mwlang> oh, nice find today. Attempting to check if a JSON::Any (which is a parsed response from API endpoint) has a particular key. I'm fumbling around trying has_key?, failing that, attempting to convert Hash and try has_key? etc...and then....I notice it....#[]? in the docs. Such a tiny thing, my eyes kept skipping over it, and I thought, no way! but sure enough, data["lastUpdateId"]? instead of
<FromGitter> ... data.has_key?("lastUpdatedId") works! And so much nicer than Ruby's.
<FromGitter> <mwlang> I'll take a 28x performance boost with a sprinkling of .to_s any day!
<FromGitter> <j8r> If you just want to know if the key exists, has_key is better
<FromGitter> <mwlang> well, I put it to work, too.
<FromGitter> <mwlang> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cd4308f0f381d0a7687f897]
<FromGitter> <j8r> It doesn't fetch the value
<FromGitter> <j8r> in this case yes, `#[]?` is perfect
<FromGitter> <j8r> unless for the second line
<FromGitter> <j8r> the performance diff can be considered as negligible, though
<FromGitter> <mwlang> 99% of the time spent waiting on server response anyway.
<FromGitter> <Blacksmoke16> wouldnt be better to use JSON::Serialziable?
<FromGitter> <Blacksmoke16> vs dealing with json any
<FromGitter> <mwlang> I dunno. How would I use that?
<FromGitter> <mwlang> I hit the server, get a JSON response, I parse it with JSON.parse to get a JSON::Any
<FromGitter> <Blacksmoke16> define a struct with the properties, then do like `MyClass.from_json(response.body)`
<FromGitter> <Blacksmoke16> then you have an instance of `MyClass` to use
<FromGitter> <Blacksmoke16> and can have defaults/methods and such on the obj
<FromGitter> <mwlang> well, the server returns three different code signatures.
<FromGitter> <Blacksmoke16> got an example/
<FromGitter> <mwlang> {code: String, msg: String}
<FromGitter> <Blacksmoke16> yea thats easily doable
<FromGitter> <Blacksmoke16> it supports nested objs as well
<FromGitter> <mwlang> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cd431be8fcdb05d47a76b93]
<FromGitter> <mwlang> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cd431cef52a237516019e64]
<FromGitter> <mwlang> so those are the three possible responses I get from the server.
<FromGitter> <Blacksmoke16> interesting
<FromGitter> <Blacksmoke16> hows that work if the same endpoint returns diff objs?
<FromGitter> <Blacksmoke16> or are they diff endpoints, that would make more sense
<FromGitter> <mwlang> actually, I'm slightly wrong...it's a two step process. The first call is made RESTfully. That gets me the first one described. The subsequent calls are the Websocket with only diffs streamed.
<FromGitter> <mwlang> that's the bottom one.
<FromGitter> <mwlang> both websocket and rest endpoints can alternatively return the code and message in case of an error.
<FromGitter> <Blacksmoke16> gotcha, should work the same assuming both are just strings
<FromGitter> <mwlang> yeah, I'm reading...it's an interesting approach you suggested. I wasn't aware that Serializable stuff existed.
<FromGitter> <Blacksmoke16> i can make an example if you need
<FromGitter> <mwlang> here's what I have...is it worth the refactor? https://gist.github.com/mwlang/f5446a497afa46de2783c96d58e99ae7
<FromGitter> <mwlang> if there's a big performance improvement to refactor this, then yeah, it's worth refactoring.
<FromGitter> <mwlang> but if it's "about the same" I'll probably roll with this as it's not *ugly*
<FromGitter> <mwlang> I've got more to go, like tracking if the order books have expired and forcing a refresh RESTfully and restarting the websocket
<FromGitter> <j8r> the main point is to validate the schema early
<FromGitter> <mwlang> now that's a valid point, too.
<FromGitter> <mwlang> ok, that's actually a very good point and worth the refactor.
<FromGitter> <Blacksmoke16> it wouldnt be much change
<FromGitter> <r00ster91> Is it good practice to use a named tuple when the keys will never change but the keys? (I can update using `merge`)
<FromGitter> <j8r> use a record?
<FromGitter> <j8r> depends of the use case
<FromGitter> <j8r> not a record, a custom struct with properties
<FromGitter> <r00ster91> you are right! I could just fine use a struct. thank you
<FromGitter> <Blacksmoke16> @mwlang would also allow you to add like psudo getters for those values in the 2d array
<FromGitter> <Blacksmoke16> since you dealing with objects now
<FromGitter> <Blacksmoke16> would have to add some annotations to some properties to make them read the correct keys, since they are diff
<FromGitter> <mwlang> I think the way I'd handle the REST and WS endpoints is with two different structs
<FromGitter> <mwlang> I probably needlessly combined things since I wasn't thinking in terms of schema validation as part of the processing up front.
<FromGitter> <Blacksmoke16> well yea
<FromGitter> <Blacksmoke16> each obj would have to be its own
<FromGitter> <Blacksmoke16> otherwise it would get messy
<FromGitter> <mwlang> can you mock one up for me -- I'm trying to go through the docs and figure it out, but admittedly scratching my head w/o concrete example.
<FromGitter> <Blacksmoke16> sec
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6vp4
<FromGitter> <Blacksmoke16> to give you an idea
<FromGitter> <mwlang> ok, great. but how does that handle the case when a code and message is returned instead of the expected structure?
<FromGitter> <Blacksmoke16> id assume that gets returned when there is a server error?
<FromGitter> <Blacksmoke16> ie. non 200
<FromGitter> <mwlang> good question! I hadn't thought to check status code returned, but you're probably right.
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <mwlang> so we can just skip the handoff if status != 200
<FromGitter> <Blacksmoke16> yea or serialize it into some `Error` struct
<FromGitter> <Blacksmoke16> if you need to do stuff with it
<FromGitter> <mwlang> ok, I got this. thanks for your help.
<FromGitter> <Blacksmoke16> np
<FromGitter> <MrSorcus> `passing Void return value of lib fun call has no effect` ⏎ What must i do with this error? Replace `Void` with `Void*`?
ua_ has quit [Excess Flood]
ua_ has joined #crystal-lang
<FromGitter> <Blacksmoke16> whats the code?
ua_ has quit [Excess Flood]
waheedi has joined #crystal-lang
<FromGitter> <mwlang> @Blacksmoke16 in this line: ```getter bids : Array(Array(String))``` how would I expand that second array to be what it ultimately is, two floating point numbers? In this case, it should resolve to price and quantity
<FromGitter> <Blacksmoke16> but they come back from the api as strings/
<FromGitter> <mwlang> I thought to set up another json serializeable struct, but these two values (which are strings, yes), aren't keyed with a name.
<FromGitter> <Blacksmoke16> sec
<FromGitter> <mwlang> they'll just always be [ [1,2], [2,3], [3,4] ]
<FromGitter> <alex-lairan> So for me, it's not array of array of Thing. ⏎ ⏎ It's array of (Tuple | Struct) of Thing ⏎ ⏎ An array allow you to have 0, 1, 2, 3, ..., n data. You always get two. [https://gitter.im/crystal-lang/crystal?at=5cd44928da34620ff9118ea4]
<FromGitter> <Blacksmoke16> is the length static? or could it change?
<FromGitter> <Blacksmoke16> im assuming the latter
<FromGitter> <Blacksmoke16> im not super good with arrays and json pull parser, but basic would have a converter that converts the strings to floats and returns the array
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6vpt like this @mwlang
<FromGitter> <mwlang> length can be empty to N pairs.
<FromGitter> <mwlang> empty means "no changes"
<FromGitter> <Blacksmoke16> n pairs, gotcha
<FromGitter> <Blacksmoke16> let me update the converter
<FromGitter> <Blacksmoke16> why do they return them as strings :(
<FromGitter> <mwlang> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cd44cce252dbb75152a85e0]
<FromGitter> <mwlang> I dunno. I thought that was odd, too.
<FromGitter> <mwlang> my guess is to avoid floating point rounding errors, but that's just a wild swing in the dark.
<FromGitter> <Blacksmoke16> could be
<FromGitter> <Blacksmoke16> imo it might be easier to keep them as strings, but overload the getter to return floats?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6vq0 something like that
<FromGitter> <Blacksmoke16> :shrug:
laaron- has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
ua has joined #crystal-lang
devil_tux has joined #crystal-lang
alexherbo2007 has quit [Ping timeout: 268 seconds]
alexherbo2007 has joined #crystal-lang
rohitpaulk has joined #crystal-lang
alexherbo2007 has quit [Quit: The Lounge - https://thelounge.chat]
devil_tux has quit [Ping timeout: 246 seconds]
devil_tux has joined #crystal-lang
<FromGitter> <tenebrousedge> so if I have this: https://play.crystal-lang.org/#/r/6vqs ⏎ Is it possible to define the `isosceles?`, `equilateral?`, and `scalene?` methods based on a `Hash`?
<FromGitter> <Blacksmoke16> based on a hash?
<FromGitter> <tenebrousedge> yeah, something like `{:equilateral => "matching_sides == 3 "}`
<FromGitter> <Blacksmoke16> and what would you expect the response to be? true assuming `@matching_sides === 3`?
<FromGitter> <tenebrousedge> yes
<FromGitter> <Blacksmoke16> what benefit would that bring?
<FromGitter> <tenebrousedge> this is exercise code; I just want to know if this is possible. Ideally I would like to write https://play.crystal-lang.org/#/r/6vra
<FromGitter> <Blacksmoke16> oh ok
<FromGitter> <tenebrousedge> that doesn't work among other reasons because the `rule` is inserted as a string
<FromGitter> <tenebrousedge> I think it also complains about the lack of type hinting
<FromGitter> <Blacksmoke16> sec
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6vrj
<FromGitter> <tenebrousedge> hmm. That's a step further, but in this exercise equilateral triangles are also considered isosceles, so the test needs to be `>= 2`
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6vro
<FromGitter> <Blacksmoke16> something like that then, can adjust the rules, idk remember HS geometry xD
rohitpaulk has quit [Remote host closed the connection]
<FromGitter> <tenebrousedge> awesome. Works perfect https://play.crystal-lang.org/#/r/6vrq
<FromGitter> <tenebrousedge> but what is `id` supposed to be here?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.28.0/Crystal/Macros/ASTNode.html#id%3AMacroId-instance-method
<FromGitter> <tenebrousedge> huh. So it's basically, "treat this like literal code" ?
<FromGitter> <Blacksmoke16> yes
<FromGitter> <r00ster91> uh shouldn't this raise a compile time error? https://carc.in/#/r/6vs0 ⏎ `var` isn't even defined in the other `if`'s scope
<FromGitter> <Blacksmoke16> it does but its nil https://carc.in/#/r/6vs5
<FromGitter> <Blacksmoke16> https://carc.in/#/r/6vs7 seems like it picks it up from the other if
<FromGitter> <r00ster91> yes but the var isn't even defined in the other scope
<FromGitter> <Blacksmoke16> yea, looks like scope leak?
<FromGitter> <tenebrousedge> `if` doesn't change scope?
<FromGitter> <r00ster91> that's strange
<FromGitter> <r00ster91> here it's as expected but why not for an `if`? https://carc.in/#/r/6vse
<FromGitter> <tenebrousedge> I wouldn't really expect logical constructs to change scope
<FromGitter> <tenebrousedge> blocks, yes
<FromGitter> <asterite> only blocks and proc literals change scope
<FromGitter> <asterite> (and, well, methods)
<FromGitter> <tenebrousedge> @asterite and it's relatively accurate to say that a variable will be considered to be defined if it's ever on the left side of `=` inside the current scope?
devil_tux has quit [Ping timeout: 246 seconds]
devil_tux has joined #crystal-lang
devil_tux has quit [Ping timeout: 245 seconds]
<FromGitter> <tenebrousedge> do macros only support using `for` for iteration?
<FromGitter> <Blacksmoke16> yes
<FromGitter> <Blacksmoke16> and you cant do like `next` or `break`
<FromGitter> <tenebrousedge> is there an issue related to that which might offer some context?
<FromGitter> <tenebrousedge> I suppose this might count https://github.com/crystal-lang/crystal/issues/6644
<FromGitter> <tenebrousedge> @z64 thanks, that's very informative
<z64> yw
<FromGitter> <tenebrousedge> I don't think that not having e.g. `map` in metaprogramming is very consequential; the point is not really to create new values, so the return value of any metaprogramming iterator should not be important. Using `each` or `each_with_index` is more supportable, but those have obvious workarounds. I think I might add a note to the documentation, though
<z64> the macro API actually has several "ports" of Enumerable methods. check out https://crystal-lang.org/api/0.28.0/Crystal/Macros/ArrayLiteral.html and ctrl+f for "Similar to Enumerable"
<z64> map, select, find, reject, etc.
<FromGitter> <r00ster91> `NoReturn`? Is this a bug? https://carc.in/#/r/6vss
<FromGitter> <tenebrousedge> huh, I guess just not `HashLiteral#each`
<FromGitter> <tenebrousedge> man, this is weird
<FromGitter> <r00ster91> ah yes this is definitely a bug
devil_tux has joined #crystal-lang
_whitelogger has joined #crystal-lang
<z64> pretty sure the complier has just statically deduced that variable2 will never be set, so its invalidated after `exit`
<FromGitter> <bew> Yes, i don't see a bug here..
<z64> @bew see the issue/pr, i guess; https://github.com/crystal-lang/crystal/issues/7760 detail was left out about named args
<FromGitter> <nsuchy> Did the developers of Crystal invent Union Types? Or does it exist in other languages?
<FromGitter> <Blacksmoke16> exists in typescript
DTZUZO has quit [Ping timeout: 258 seconds]
DTZUZO has joined #crystal-lang
devil_tux has quit [Ping timeout: 246 seconds]
waheedi has quit [Quit: waheedi]
mntmn has quit [Ping timeout: 258 seconds]
mntmn has joined #crystal-lang
<FromGitter> <jwoertink> It exists in C
<FromGitter> <asterite> they also exits in Julia, Pony, and algebraic data types are a generalization of union types (like found in Haskell or Rust)
devil_tux has joined #crystal-lang
<FromGitter> <Blacksmoke16> is there no way to do something similar to this? Or am i forgetting something?
<FromGitter> <tenebrousedge> did you forget to include Taggable in Type2 ?
<FromGitter> <Blacksmoke16> no the point is it shouldn't error imo since compiler should know it would only get executed if type includes that module