ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
<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 ``?
<FromGitter> <> wow thanks matrix for the nice edit message
<FromGitter> <> oprypin ( you're designing an (http) router?
<FromGitter> <> what feature will it bring compared to the others out there?
<FromGitter> <> params aren't forced to be at a slash boundary
<FromGitter> <> for instance?
<FromGitter> <> `/foo/bar_#{id}/`
<FromGitter> <> no other router can match
<FromGitter> <> `/foo/#{id}.zip` would be a more popular example
<FromGitter> <> 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> <> Hum, how can it be documented OpenAPI-wise?
<FromGitter> <> 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>, 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:
<FromGitter> <> 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> <> 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> 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:
<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> you need a, 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
<FromGitter> <Blacksmoke16> ```code paste, see link``` ⏎ ⏎ Should this be an allowed state? []
<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> <> same
<straight-shoota> I guess in some contexts, it doesn't matter
<FromGitter> <> meanwhile
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> <> @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> <> Ha the id
<FromGitter> <> 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> <> 🙈
<FromGitter> <> Or 0.37.0 (I troll :D)
<FromGitter> <Blacksmoke16> `0.36.2` :trollface:
<FromGitter> <> By looking at, 1.0.0 is always being pushed more
<FromGitter> <Blacksmoke16>!(value)-class-method, these should have `**args` that get passed to the underlying `to_f32!` call
<FromGitter> <> Blocking issues are closed, that's great, but new ones get added :/
<FromGitter> <> @Blacksmoke16: hmm? but `to_f32!` has no args
<FromGitter> <Blacksmoke16> oh really?
<FromGitter> <Blacksmoke16> wait
<FromGitter> <> wait im dumb, this is just misleading linking in the docs :D
<FromGitter> <Blacksmoke16> oh sorry i meant ` value` one
<FromGitter> <> 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> <> this is intended for ``
<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 []
<FromGitter> <> 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> <> `!(1e300)` -> Infinity
<straight-shoota> yeah those arguments should be forwarded for the string overload
<straight-shoota> >>!(500)
<DeBot> straight-shoota: # => -12 -
<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 -
<straight-shoota> >> Math::PI
<DeBot> straight-shoota: # => 3.141592653589793 -
<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")``` []
<FromGitter> <anapsix> ref:,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``` []
<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> <> 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> <> @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> <> yes like why does a js library require a Crystal Hash?
<FromGitter> <> we need a Hash::Serializable maybe? 🤔
<FromGitter> <Blacksmoke16> 👎
<FromGitter> <> yes but.. yes
<FromGitter> <Blacksmoke16> that would prob just make people use hashes more when thats usually a bad idea
<FromGitter> <> well but if you disregard bad people it'd be a good thing to have
<FromGitter> <> 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> <> yes, an object which has a `to_h`
<FromGitter> <> (as @bla
<FromGitter> <> @justin0mcateer: such feature may have its place in
<FromGitter> <> 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]