ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
<FromGitter> <acook> > got an example? ⏎ ⏎ @Blacksmoke16 It didn't make it into a commit, so unfortunately I don't have a copy of it. I experimented with replicating it just now but couldn't. I wonder if the property I was calling was nilable and I just assumed it shouldn't be?
<FromGitter> <acook> Hmm. It's not. It was a File::Info object and I was calling info.type.
<FromGitter> <acook> The compiler would say that type could be nil when info wasn't nil, but that's not possible.
<FromGitter> <acook> As File::Info.type is a non-nillable property.
<FromGitter> <Blacksmoke16> Mmk, hard to help without reproducible code
<FromGitter> <Blacksmoke16> sure you werent doing like `File.info?()`?
<FromGitter> <oprypin:matrix.org> wow thanks matrix for the nice edit message
<FromGitter> <jrei:matrix.org> oprypin (https://matrix.to/#/@oprypin:matrix.org): you're designing an (http) router?
<FromGitter> <jrei:matrix.org> what feature will it bring compared to the others out there?
<FromGitter> <oprypin:matrix.org> params aren't forced to be at a slash boundary
<FromGitter> <jrei:matrix.org> for instance?
<FromGitter> <oprypin:matrix.org> `/foo/bar_#{id}/`
<FromGitter> <oprypin:matrix.org> no other router can match
<FromGitter> <oprypin:matrix.org> `/foo/#{id}.zip` would be a more popular example
<FromGitter> <oprypin:matrix.org> also no other router can do this
<straight-shoota> and that's actually pretty standard routes
<straight-shoota> string interpolation is soo nice =)
<straight-shoota> yeah that's not nice
<straight-shoota> named arguments maybe?
<FromGitter> <jrei:matrix.org> Hum, how can it be documented OpenAPI-wise?
<FromGitter> <jrei:matrix.org> It is nor a Path param nor a query one
<oprypin> straight-shoota, one can't write `#{foo: bar}` or anything like that
<straight-shoota> @[Retour::Get("/#{repo_owner}/#{repo_name}/runs/#{job_id}", job_id: /[0-9]+/)]
<FromGitter> <Blacksmoke16> what was the reasoning for switching to `#{}`?
<oprypin> Blacksmoke16, uhhhh syntax highlighting and also to have regex literals where i dont need to double-escape
<FromGitter> <Blacksmoke16> gotcha
<straight-shoota> also delegate work to the crystal parser =)
<oprypin> straight-shoota, now i need to write `job_id` 3 times :s
<straight-shoota> if you add more param validations and stuff, you'll have to write it even more often
<oprypin> jrei:matrix.org, i don't know but there are still sites that aren't APIs, u know :D
<FromGitter> <acook> @Blacksmoke16 I got it to replicate! Like I get why the level of indirection confuses the type checker, it just caught me offguard. Here's an example: https://play.crystal-lang.org/#/r/afsu
<FromGitter> <jrei:matrix.org> OpenAPI is Swagger docs
<oprypin> i think i'll have to revert the string interpolation stuff
<straight-shoota> y?
<FromGitter> <acook> (It turns out the culprit wasn't the nested if so much as the indirection of the property)
<FromGitter> <Blacksmoke16> @acook `c` is essentially defaulted to `nil` fwiw
<FromGitter> <Blacksmoke16> so this makes sense i think
<FromGitter> <jrei:matrix.org> oprypin: a use case is to have a route per file type. Why not, the casting could be done with a param converter so for me it lead to the same result
<FromGitter> <Blacksmoke16> like lucky does?
<FromGitter> <acook> @Blacksmoke16 Yes, but if c is nil, it's only because b is too, so the case will never get there. It's kinda why I set the local variables, so that it couldn't change in the meantime.
<FromGitter> <Blacksmoke16> would the compiler know that tho?
<FromGitter> <acook> It *could* know that, but the information I assume isn't passed along with the c variable since like you said it defaults to nil. It's much more expedient to assume that it could be a problem.
<oprypin> straight-shoota, adding the regex is too weird. also the fact that the interpolation is deferred is a trick rather than something to be proud of
<FromGitter> <acook> I'm not arguing that it *should*, mind you.
<FromGitter> <Blacksmoke16> @oprypin:matrix.org symfony does it like `"/blog/{page<\d+>}"`
<FromGitter> <Blacksmoke16> using `<>` to deliminate the regex if that helps at all
<straight-shoota> you could also use type declarations
<straight-shoota> `/foo/bar/#{param : Int32}`
<oprypin> straight-shoota, what to do with `: Time`
<FromGitter> <acook> Yeah if I don't set the local for `c = b.baz unless b` it works, since the property is non-nillable. It's introducing that extra local/unless that breaks the chain of type info.
<straight-shoota> well, don't use it :/
<oprypin> not being a web framework *and* being a compile-time thing, it's hard to add registration of converters
<straight-shoota> primitive types could have default regexes associated
<straight-shoota> and I suppose you could also use constants
<straight-shoota> like `#{param : MyTimeFormat}`
<oprypin> does a global registry work for these?
<FromGitter> <acook> It can be unfortunate if you expect the value to change during the course of a method call, you would have to add some unintuitive extra nil checks.
<straight-shoota> `MyTimeFormat = /\d{4}-\d{2}-\d{2}/`
<oprypin> straight-shoota, the type annotations will go into the method itself anyway :D
<straight-shoota> yeah, but there they have to be *actual* types
<oprypin> yes
<straight-shoota> in the macro formatted string interpolation it can be any constant
<FromGitter> <acook> So like even if I do a nil check on `c` I get a different completely preposterous error: https://play.crystal-lang.org/#/r/aft0
<FromGitter> <Blacksmoke16> fwiw given you're in macro land its prob possible to have semi invalid `TypeDeclaration` types
<FromGitter> <Blacksmoke16> like what if you did `some_var : SomeModule`, where that module defines interface to access more data about it
<straight-shoota> @Blacksmoke16 that's what I'm talking about
<FromGitter> <acook> (because the case has no `else` even though it is logically impossible to trigger said `else`)
<straight-shoota> `MyTimeFormat = /\d{4}-\d{2}-\d{2}/` + `@[Retour::Get("/archive/#{param : MyTimeFormat}")`
<oprypin> doesn't get me closer to converting it to an actual Time instance
<FromGitter> <Blacksmoke16> @oprypin:matrix.org you need a https://athenaframework.org/Routing/TimeConverter/#Athena::Routing::TimeConverter, more specifically 😉
<oprypin> i do believe that the annotations should stay in the method and then a type can forward its own regex, not the other way around
<straight-shoota> yeah, probably better that way
<FromGitter> <Blacksmoke16> while we're all on this subject. What are your thoughts on this:
<FromGitter> <acook> Wait, my second link was a bad example.
<oprypin> anyway, benchmarks look reasonable now https://gist.github.com/6706bf833a08af9d335222ec7f916646
<FromGitter> <Blacksmoke16> ```code paste, see link``` ⏎ ⏎ Should this be an allowed state? [https://gitter.im/crystal-lang/crystal?at=602f16f89403f11bb591032a]
<FromGitter> <Blacksmoke16> as by default `.to_i` strips whitespace
richbridger has joined #crystal-lang
<FromGitter> <Blacksmoke16> im unsure if it should be an error by default, or allow it by default and require the user to add a like `\d+` to make it more strict
<straight-shoota> I'd expect that to be strict
<straight-shoota> I don't really understand why String#to_i strips whitespace by default
<FromGitter> <oprypin:matrix.org> same
<straight-shoota> I guess in some contexts, it doesn't matter
<FromGitter> <oprypin:matrix.org> meanwhile https://news.ycombinator.com/item?id=%20%20%20%2022725829%20%20
aquijoule__ has quit [Ping timeout: 240 seconds]
<FromGitter> <Blacksmoke16> yea, i did some testing with some frameworks and stuff and most just seem to allow it :shrug:
<straight-shoota> it's just duplicate content
<straight-shoota> bad for caching
<FromGitter> <jrei:matrix.org> @oprypin it is 10month old O.o
<FromGitter> <oprypin> the point of the link isn't the content
<FromGitter> <oprypin> it's the link itself
<FromGitter> <jrei:matrix.org> Ha the id
<FromGitter> <jrei:matrix.org> I was thinking you were impliying to wait for 1.0
deavmi has quit [Ping timeout: 272 seconds]
<FromGitter> <Blacksmoke16> repo: that PR was merged. Will ofc need to upgrade to the new config stuff tho
<straight-shoota> hey, 1.0 is finally on its way :D
<FromGitter> <oprypin:matrix.org> 🙈
<FromGitter> <jrei:matrix.org> Or 0.37.0 (I troll :D)
<FromGitter> <Blacksmoke16> `0.36.2` :trollface:
<FromGitter> <jrei:matrix.org> By looking at https://github.com/crystal-lang/crystal/milestone/47, 1.0.0 is always being pushed more
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Float32.html#new!(value)-class-method, these should have `**args` that get passed to the underlying `to_f32!` call
<FromGitter> <jrei:matrix.org> Blocking issues are closed, that's great, but new ones get added :/
<FromGitter> <oprypin:matrix.org> @Blacksmoke16: hmm? but `to_f32!` has no args
<FromGitter> <Blacksmoke16> oh really?
<FromGitter> <Blacksmoke16> wait
<FromGitter> <oprypin:matrix.org> wait im dumb, this is just misleading linking in the docs :D
<FromGitter> <Blacksmoke16> oh sorry i meant `Float32.new value` one
<FromGitter> <oprypin:matrix.org> yea then String.to_f32 has args
<FromGitter> <Blacksmoke16> interestingly enough, `to_f32!`, and other`!` aren't defined on string so it fails
<straight-shoota> yeah because exclamation conversion methods are for wrapping behaviour
<straight-shoota> there's no wrapping when you parse a string
<FromGitter> <oprypin:matrix.org> this is intended for `Float32.new(1e300)`
<FromGitter> <Blacksmoke16> i use it for strings 😬
<FromGitter> <Blacksmoke16> because i can just do like ⏎ ⏎ ```def Number.from_parameter(value : String) : Number ⏎ new value ⏎ end``` ⏎ ⏎ and it works for them all [https://gitter.im/crystal-lang/crystal?at=602f1ac3dc108172e78743bc]
<FromGitter> <oprypin:matrix.org> i also think the "wrapping" comment is wrong
<FromGitter> <Blacksmoke16> but there isnt a way to do like `new value, whitespace: false` :(
zorp has quit [Ping timeout: 240 seconds]
<FromGitter> <oprypin:matrix.org> `Float32.new!(1e300)` -> Infinity
<straight-shoota> yeah those arguments should be forwarded for the string overload
<straight-shoota> >> Int8.new!(500)
<DeBot> straight-shoota: # => -12 - https://carc.in/#/r/aft8
<FromGitter> <Blacksmoke16> @straight-shoota actually would prob need to be a specific `.new(value : String) : self` overload since its only those ones that have the args
<straight-shoota> yes, that's what I meant with "string overload"
<FromGitter> <Blacksmoke16> i can grab that, be helpful for me :P
<FromGitter> <Blacksmoke16> 👍
<straight-shoota> I'll probably be looking into rounding behaviour for the number conversion methods :D
<FromGitter> <Blacksmoke16> like if you call `.to_f32` on a `Float64`? 😉
<straight-shoota> yeah any conversion from a float to a smaller float or int is rounded
<straight-shoota> >> Math::PI.to_f32
<DeBot> straight-shoota: # => 3.1415927 - https://carc.in/#/r/aftb
<straight-shoota> >> Math::PI
<DeBot> straight-shoota: # => 3.141592653589793 - https://carc.in/#/r/aftc
<FromGitter> <Blacksmoke16> was there a way to link to a specific overload in a doc comment w/o linking all its args?
<straight-shoota> probably not
<FromGitter> <Blacksmoke16> oh well, i wont bother linking to `String#to_i*` then, given it links to the block version :/
<straight-shoota> haha
<straight-shoota> time to hit the sack for me, bye
<FromGitter> <Blacksmoke16> this didnt work either :S
<FromGitter> <Blacksmoke16> o/
deavmi has joined #crystal-lang
teardown has quit [Ping timeout: 268 seconds]
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 265 seconds]
teardown has joined #crystal-lang
_whitelogger has joined #crystal-lang
repo has quit [*.net *.split]
repo has joined #crystal-lang
watzon has quit [Ping timeout: 244 seconds]
_ht has joined #crystal-lang
<FromGitter> <alexherbo2> How to check a program is in path?
<FromGitter> <alexherbo2> I would like to forward commands `kcr-fzf-files` as `kcr fzf edit` like Git
hamoko[m] has joined #crystal-lang
<FromGitter> <anapsix> @alexherbo2 this should do it.. ⏎ ⏎ ```Process.find_executable("ssh")``` [https://gitter.im/crystal-lang/crystal?at=602f9368a37fc1784c2feae2]
<FromGitter> <anapsix> ref: https://crystal-lang.org/api/0.36.1/Process.html#find_executable(name:Path%7CString,path:String?=ENV[%22PATH%22]?,pwd:Path%7CString=Dir.current):String?-class-method
f1reflyylmao is now known as f1refly
Human_G33k has quit [Remote host closed the connection]
Human_G33k has joined #crystal-lang
Human_G33k has quit [Quit: Leaving]
Human_G33k has joined #crystal-lang
Human_G33k has quit [Remote host closed the connection]
<FromGitter> <alexherbo2> thanks @anapsix o/
<FromGitter> <justin0mcateer> Noob question. What would be the most straightforward way to convert a nested Struct into a nested Hash?
<FromGitter> <Blacksmoke16> just dont, and use the struct?
<FromGitter> <Blacksmoke16> what are you trying to do?
<FromGitter> <justin0mcateer> Using Duktape, I need to send a structure to a JS function
<FromGitter> <justin0mcateer> I will try sending the Struct, but it doesn't look like it will accept that
<FromGitter> <Blacksmoke16> ah yea, i doubt it would in that case
<FromGitter> <Blacksmoke16> best bet would be to define a `.to_h` method on your structs to handle it
<FromGitter> <justin0mcateer> runtime error
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=602fc386e634904e60ad8024]
<FromGitter> <Blacksmoke16> something along those lines
<FromGitter> <justin0mcateer> Right
<FromGitter> <justin0mcateer> I was hoping there might be a general purpose way like 'to_json'
<FromGitter> <justin0mcateer> Sounds like, no
<FromGitter> <Blacksmoke16> naw not that i know of
<straight-shoota> no that would be crazy
<straight-shoota> because of all the type merging
<straight-shoota> why don't use use to_json though?
<straight-shoota> if you want to pass it to ducktape, json values sounds pretty good
<FromGitter> <justin0mcateer> Is there anyway to enumerate the members of a Struct?
<FromGitter> <justin0mcateer> I don't see any
<FromGitter> <erdnaxeli:cervoi.se> at runtim there isn't, at copmile time you can use macros
<FromGitter> <Blacksmoke16> ofc in your case it wouldnt need to worry about the column annotation or anything
<FromGitter> <justin0mcateer> OK. I am going to do it the manual/tedious way for now. I can try to write a macro that handles it later. It's a bit over my head at the moment.
<FromGitter> <justin0mcateer> Thanks for the advice!
<FromGitter> <oprypin:matrix.org> @justin0mcateer why don't you just apply JSON::Serializable to those structs?? you don't need to enumerate fields, it does it for you
<FromGitter> <justin0mcateer> Yeah, I could do that. I just don't want to have to serialize to JSON, then turn around and deserialize back to a Hash and do that in both directions.
<FromGitter> <Blacksmoke16> does ducktape handle converting a hash into json to pass to js?
<FromGitter> <Blacksmoke16> because a crystal hash isnt a js object
<FromGitter> <oprypin:matrix.org> yes like why does a js library require a Crystal Hash?
<FromGitter> <erdnaxeli:cervoi.se> we need a Hash::Serializable maybe? 🤔
<FromGitter> <Blacksmoke16> 👎
<FromGitter> <oprypin:matrix.org> yes but.. yes
<FromGitter> <Blacksmoke16> that would prob just make people use hashes more when thats usually a bad idea
<FromGitter> <oprypin:matrix.org> well but if you disregard bad people it'd be a good thing to have
<FromGitter> <erdnaxeli:cervoi.se> yeah that was not a serious idea ^^
<straight-shoota> => generic serialization framework
<straight-shoota> could have a hash backend
Human_G33k has joined #crystal-lang
Human_G33k has quit [Quit: Leaving]
<FromGitter> <jrei:matrix.org> yes, an object which has a `to_h`
<FromGitter> <jrei:matrix.org> (as @bla
<FromGitter> <jrei:matrix.org> @justin0mcateer: such feature may have its place in https://github.com/j8r/crystalizer
<FromGitter> <jrei:matrix.org> honestly I'm not sure, it is very specific for your use-case
watzon has joined #crystal-lang
watzon has quit [Quit: authenticating]
watzon has joined #crystal-lang
f1refly has left #crystal-lang ["WeeChat 3.0"]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
FromGitter has quit [Ping timeout: 265 seconds]
FromGitter has joined #crystal-lang
oprypin_ has joined #crystal-lang
oprypin has quit [Ping timeout: 265 seconds]
Xeago has quit [*.net *.split]
johnny101 has quit [*.net *.split]
robacarp has quit [*.net *.split]
baweaver has quit [*.net *.split]
commavir has quit [*.net *.split]
johnny101 has joined #crystal-lang
baweaver has joined #crystal-lang
commavir has joined #crystal-lang
robacarp has joined #crystal-lang
Xeago has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
_ht has quit [Remote host closed the connection]