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
acoolstraw has joined #crystal-lang
wwalker has joined #crystal-lang
<wwalker> is there something like OpenStruct in Crystal? I know there are performance costs...
ur5us has quit [Ping timeout: 264 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 260 seconds]
ur5us has joined #crystal-lang
Sankalp has quit [Ping timeout: 265 seconds]
Sankalp has joined #crystal-lang
walez___ has joined #crystal-lang
<yxhuvud> Depends on what you actually need. If compile time shape is sufficient, then you have the `record` macro. If you need something with arbitrary shape at runtime then you are basically out of luck and need to use a hash table or something similar.
Sankalp has quit [Ping timeout: 252 seconds]
Sankalp has joined #crystal-lang
ur5us has quit [Ping timeout: 246 seconds]
hightower3 has quit [Ping timeout: 268 seconds]
hightower2 has joined #crystal-lang
walez___ has quit [Quit: Leaving]
walez__ has joined #crystal-lang
hightower3 has joined #crystal-lang
hightower2 has quit [Ping timeout: 265 seconds]
ur5us has joined #crystal-lang
hightower3 has quit [Ping timeout: 246 seconds]
<FromGitter> <jrei:matrix.org> Dynamically at runtime a Hash of Procs could do, depending of the case a `case/when` could do too. ⏎ Indeed better to have a record/struct, which would be safer and faster
Sankalp has quit [Ping timeout: 250 seconds]
Sankalp has joined #crystal-lang
ur5us has quit [Ping timeout: 250 seconds]
Sankalp has quit [Ping timeout: 246 seconds]
jmdaemon has quit [Ping timeout: 246 seconds]
ur5us has joined #crystal-lang
Sankalp has joined #crystal-lang
ur5us has quit [Ping timeout: 248 seconds]
hightower2 has joined #crystal-lang
hightower2 has quit [Ping timeout: 268 seconds]
analogsalad has joined #crystal-lang
analogsalad has left #crystal-lang [#crystal-lang]
hightower2 has joined #crystal-lang
onyx has joined #crystal-lang
onyx_ has joined #crystal-lang
hightower2 has quit [Ping timeout: 268 seconds]
<FromGitter> <riffraff169> can you call a method by name? like, you have a hash of names of methods, then do something like hash["my_method"] or something...rather than hash of procs, but call by name
<FromGitter> <riffraff169> like, if you have a name, can you resolve the method that has that name, and then call it
<FromGitter> <Blacksmoke16> whats the reason against using a hash of procs?
<FromGitter> <Blacksmoke16> there is no `#send` so if you dont go the proc route, your best bet would be like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=634428ee35c5276a722462be]
hightower2 has joined #crystal-lang
jmiven has quit [Quit: reboot]
jmiven has joined #crystal-lang
<wwalker> yxhuvud: Thanks!
<FromGitter> <riffraff169> no reason, just wondering if there was a way to associate a name with a method...not saying this is the issue, but gtkbuilder uses name to map against functions, it does a lookup in a table internally i think, but it requires you to provide the text name (because it is pulled from an xml file)
<FromGitter> <riffraff169> so if someone wanted to create some kind of auto-generating process...probably would have to create hash of procs to names, so when they reference the name in the config file, you would look up the proc that goes with it...ok
<FromGitter> <Blacksmoke16> `Hash(String, Proc(...))` yea
<FromGitter> <Blacksmoke16> can also use https://crystal-lang.org/reference/1.6/syntax_and_semantics/literals/proc.html#from-methods to handle converting the method into a proc
<FromGitter> <Blacksmoke16> tho ofc this would be a typing nightmare if the methods accept diff args and/or return diff values
chromebittin has joined #crystal-lang
chromebittin has left #crystal-lang [#crystal-lang]
<FromGitter> <noaheverett> I have a return value from a function type showing as "(Array(Float32 | Float64 | Int32 | Int64) | Float32 | Float64 | Int32 | Int64 | Nil)" by Crystal
<FromGitter> <noaheverett> Trying to cast this value into an integer or even better a Pointer
<FromGitter> <noaheverett> When trying to cast to an int I get "Error: undefined method 'to_i' for Array(Float32 | Float64 | Int32 | Int64) (compile-time type is (Array(Float32 | Float64 | Int32 | Int64) | Float32 | Float64 | Int32 | Int64 | Nil))"
<FromGitter> <noaheverett> I'm kinda new to Crystal's type system coming from Ruby 🙋‍♂️
<FromGitter> <Blacksmoke16> do you know the value is always going to be an array or a scalar value?
<FromGitter> <Blacksmoke16> er let me rephrase
<FromGitter> <noaheverett> Well this is where it get's a little murky, the return value is coming from a WASM module (Written in / compiled by Crystal) that's supposed to be returning a Pointer to a buffer
<FromGitter> <Blacksmoke16> do you know for sure that the return value of the method invocation in this particular context will be a scalar value?
<FromGitter> <Blacksmoke16> because if so you prob want to do `.as(Int32)`
<FromGitter> <noaheverett> yeah it should be a Int8 technically
<FromGitter> <Blacksmoke16> then `.as(Int8)`
<FromGitter> <noaheverett> this is the WASM function that's returning the value
<FromGitter> <Blacksmoke16> which will tell the compiler to reduce the union to `Int8`
<FromGitter> <noaheverett> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=63445c5e64f29419bfd19afe]
<FromGitter> <noaheverett> @Blacksmoke16 ahh ok that worked (technically .as(Int32)
<FromGitter> <noaheverett> Int8 gave an error as not an option in the union
<FromGitter> <noaheverett> Error: can't cast (Array(Float32 | Float64 | Int32 | Int64) | Float32 | Float64 | Int32 | Int64 | Nil) to Int8
<FromGitter> <Blacksmoke16> ah 👍
<FromGitter> <Blacksmoke16> would want to do like `.as(Int32).to_i8`
<FromGitter> <noaheverett> which leads me to one other question, should I just cast the WASM function to return an Int32?
<FromGitter> <noaheverett> or should I stick with the specific Pointer type?
<FromGitter> <Blacksmoke16> i mean i dont see how what you have there relates to the larger union?
<FromGitter> <Blacksmoke16> given there is no pointer type in it
_onyx_ has joined #crystal-lang
<FromGitter> <noaheverett> I appreciate the help! @Blacksmoke16
<yxhuvud> Unions with multiple variants of numbers are usually not a good idea anyhow, as it is usually just wasteful compared to using the biggest member type
<FromGitter> <noaheverett> Yeah I'm not for sure why the value comes back as being possibly those types, I assume something between the WASM to Crystal connection or how WASM returns values
<FromGitter> <noaheverett> Oddly enough I have another WASM function written in Crystal that returns just an Int32 and when I do `typeof(rval)` it shows the same variants
<FromGitter> <noaheverett> but regardless this fixes my issue, appreciate it all!
_ht has joined #crystal-lang
jmdaemon has joined #crystal-lang
walez___ has joined #crystal-lang
walez__ has quit [Ping timeout: 265 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 244 seconds]
_ht has quit [Quit: _ht]
ur5us has joined #crystal-lang
walez___ has quit [Read error: Connection reset by peer]
walez___ has joined #crystal-lang
walez___ has quit [Ping timeout: 244 seconds]
rez has quit [Ping timeout: 265 seconds]
onyx has quit [Read error: Connection reset by peer]
onyx_ has quit [Read error: Connection reset by peer]
_onyx_ has quit [Read error: Connection reset by peer]
jmd_ has joined #crystal-lang
jmdaemon has quit [Ping timeout: 252 seconds]