jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | 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
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 272 seconds]
_whitelogger has joined #crystal-lang
<lunarkitty7> Does crystal run on arm well?
<lunarkitty7> seems like it would be a good fit for rubyesque embedded stuff
<lunarkitty7> Though for my usage ruby is fast enough too
<lunarkitty7> Or I could be non wasteful and use C++ on bare metal arm or atmel, just suffer a little :p
hightower3 has quit [Ping timeout: 244 seconds]
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 244 seconds]
f1reflyylmao has quit [Ping timeout: 240 seconds]
f1refly has joined #crystal-lang
<FromGitter> <ianmaxwell> is it possible to specify constructor args to be optional (and thus initialized with nil)? ⏎ `def initialize(@value : String, @left : Node, @right : Node)` so that left and right don't always have to be passed in?
<FromGitter> <ianmaxwell> overloaded constructor would definitely work, but wondering if there is a slimmer option
<lunarkitty7> ianmaxwell, yes, I think you want `def initialize(@value : String?, @left : Node?, @right : Node?)` (note the question marks)
<FromGitter> <ianmaxwell> that was it. thanks @lunarkitty7
psydroid has quit [*.net *.split]
skrzyp has quit [*.net *.split]
snapcase has quit [*.net *.split]
bougyman has quit [*.net *.split]
psydroid has joined #crystal-lang
skrzyp has joined #crystal-lang
bougyman has joined #crystal-lang
snapcase has joined #crystal-lang
<FromGitter> <grkek> Aw thats really nice of you raz
<raz> grkek: i'm just sad cause i don't have a good native app idea atm. but very much looking forward to the next one :D
<raz> i abandoned quite a few in the past just cause there was no reasonable way to write a GUI without diving into ObjC hell
<FromGitter> <grkek> Do you like the idea of IU
<raz> if by idea you mean "usable GUI shard in crystal" then what's not to like?
lunarkitty7 has quit [Ping timeout: 244 seconds]
alexherbo2 has joined #crystal-lang
<oprypin> was there any way in crystal to interpret strings like "\x55" at runtime? i.e. the input is "\\x55" and the output is "U"
<oprypin> >> {"\x55", "\\x55"}
<DeBot> oprypin: # => {"U", "\\x55"} - https://carc.in/#/r/9p0t
<oprypin> the day will come when i dont have to write `arr.to_unsafe.to_slice(arr.bytesize)` - but it's not this day
alexherbo24 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo24 has quit [Ping timeout: 246 seconds]
alexherbo2 has joined #crystal-lang
<FromGitter> <grkek> Rip
<FromGitter> <grkek> make a macro which writes it out for you
hightower3 has joined #crystal-lang
ua has quit [Ping timeout: 260 seconds]
ua has joined #crystal-lang
ua has quit [Ping timeout: 240 seconds]
ua has joined #crystal-lang
alexherbo2 has quit [Remote host closed the connection]
<FromGitter> <RespiteSage> @oprypin Nice solution for mimicking C static variables!
<FromGitter> <RespiteSage> I still don't know why anyone would *want* that, though. :P
<oprypin> to mimick C code
<oprypin> cc @RespiteSage
<FromGitter> <dscottboggs> how do you store the tuple received from a splat as an ivar? i.e. ⏎ ⏎ ```https://carc.in/#/r/9p35``` [https://gitter.im/crystal-lang/crystal?at=5f5e68664f19dd093348a32f]
<FromGitter> <Blacksmoke16> pretty sure length would have to be known
<oprypin> dscottboggs, maybe the type can be a generic type. or store it as an array
<FromGitter> <RespiteSage> Oh, you're porting something.
<FromGitter> <dscottboggs> damn it. I'm trying to solve a practice problem and it expects an arbitrary number of values to be passed to the constructor and then transformed and passed to a callback
<FromGitter> <dscottboggs> the tests only check for one or two so I guess I'll just do a simple union
<FromGitter> <Blacksmoke16> do they have to be ivars?
<FromGitter> <dscottboggs> what do you mean? I don't think so
<FromGitter> <dscottboggs> ```Error: splatting a union (Tuple(Int32) | Tuple(Int32, Int32)) is not yet supported``` ⏎ ⏎ arrrggghh! [https://gitter.im/crystal-lang/crystal?at=5f5e714bd993b837e05fb5c5]
<FromGitter> <Blacksmoke16> splat generics could be used for this i think but you'll run into https://github.com/crystal-lang/crystal/issues/8520
<FromGitter> <dscottboggs> I can't use generics because the tests don't. ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Trying `Tuple(Cell, Cell?)`... [https://gitter.im/crystal-lang/crystal?at=5f5e71fcd993b837e05fb778]
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 244 seconds]
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 258 seconds]
<FromGitter> <j8r> because Array is dynamic maybe?
<oprypin> yea actually.. the `realloc` can break it
<FromGitter> <j8r> Tuple could have, but probably not used enough
<FromGitter> <j8r> to be worth it
lunarkitty7 has joined #crystal-lang
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Client Quit]
<FromGitter> <Qard> Is there some reason why the `Enum` type doesn't have a `to_unsafe` method that returns `value`? Seems to me like an obvious thing to do. 🤔
<FromGitter> <Blacksmoke16> wouldnt that just be `.value`?
<FromGitter> <dscottboggs> well yes, but having `#to_unsafe` aliased to `#value` would improve ergonomics when dealing with C APIs
<FromGitter> <Qard> Yeah, that's my thinking.
<FromGitter> <Blacksmoke16> but is it actually unsafe?
<FromGitter> <Blacksmoke16> not really?
<FromGitter> <dscottboggs> I mean, kind of
<FromGitter> <Qard> I'm working with a C API right now that maps a bunch of C enum stuff to Crystal enum, but you can't pass the values directly into the lib functions, you need to add `.value` after everything, which is easy to miss and gives really unhelpful errors.
<FromGitter> <dscottboggs> C is only seeing the value not the name, so you have to rely on the programmer to "get it right" which is usually what unsafe means...kinda
<FromGitter> <Blacksmoke16> if anything wouldnt a feature that allows you to pass an enum to a c func and it do that under the hood?
<FromGitter> <Blacksmoke16> be better*
<FromGitter> <Qard> Even if you use `: Type` to tell it the values in the enum are of a particular type, it still doesn't work without using `.value`.
<FromGitter> <Blacksmoke16> id maybe suggest that as a feature?
<oprypin> Qard, why dont u bind the C function as accepting that enum type
<FromGitter> <Qard> It's someone else's module.
<oprypin> tell them to fix it or make your own
<FromGitter> <Qard> Which I guess worked at some point? But it doesn't now.
<oprypin> whats the actual problem
<FromGitter> <Qard> It uses stuff from that `Parameter` enum directly in a bunch of places, which doesn't work because it thinks the type is wrong.
<oprypin> also why are you using a 3 years not updated repo
<FromGitter> <Qard> Because it's a lot of code, and it *would* work other than the `.value` issue.
<FromGitter> <Qard> It's not too hard to fork and find/replace, but it seems like the code must have worked at some point but doesn't now, and in looking at the code it seemed to me like something that *should* work.
<FromGitter> <dscottboggs> I think you need to fork and take on maintainership of that shard if you intend to use it
<FromGitter> <Blacksmoke16> maybe you had to do `.value` 3 years ago but the feature of typing an arg to an enum made it so you dont need to do that
<FromGitter> <dscottboggs> yeah, 3 years is a long time ago in the Crystal timeline. It wouldn't surprise me if something changed.
<FromGitter> <Qard> Sure, I'd expect some changes. Just seems to be like a feature I'd want to *keep*.
<FromGitter> <Qard> Thus asking if there was some particular *reason* why it doesn't work that way anymore.
<oprypin> Qard, could you post the error message? with --error-trace? i'm curious
<FromGitter> <dscottboggs> yeah, this feels like a valid thing to raise in a github issue or forum post (where the core maintainers pay more attention)
<FromGitter> <Qard> I don't have the exact code handy anymore, but this is a basic reproduction: https://play.crystal-lang.org/#/r/9p7g
<oprypin> wait it works https://carc.in/#/r/9p7i
<oprypin> of course the example u just linked is expected
<oprypin> >> sprintf("%.*s\n", 5, "abcdefghi")
<DeBot> oprypin: # => "abcde\n" - https://carc.in/#/r/9p7k
<oprypin> >> sprintf("%.*s\n", 5, "abcdefghi".to_unsafe) # how can I make this output `abcde` rather than garbage?
<DeBot> oprypin: # => "Point\n" - https://carc.in/#/r/9p7l
<FromGitter> <Blacksmoke16> you just want the first 5 values?
<FromGitter> <Blacksmoke16> `"abcdefghi"[..4]`?
<oprypin> Blacksmoke16, well no, i have a pointer and i want to perform this string operation, ideally through sprintf
<FromGitter> <dscottboggs> any particular reason it needs to happen through sprintf? is it the first 5 values or up-to-the-first-five values?
<FromGitter> <Blacksmoke16> https://carc.in/#/r/9p7q what you had seems to work fine?
<FromGitter> <Blacksmoke16> think the bot is just messing something up?
<oprypin> no i dont have a string, i have a pointer
<FromGitter> <Blacksmoke16> oh the 2nd example you gave
<FromGitter> <dscottboggs> wtf https://carc.in/#/r/9p7v
<FromGitter> <Blacksmoke16> its prob hitting up the `.to_s`/`.inspect` method of that type
<oprypin> yea
<oprypin> >> ptr = "abcdefghi".to_unsafe; sprintf("%s\n", String.new(ptr, 5))
<DeBot> oprypin: # => "abcde\n" - https://carc.in/#/r/9p80
<oprypin> i think i'll have to settle for making the sprintf obsolete
<FromGitter> <Blacksmoke16> dont suppose an overload of sprintf that takes a pointer would help
<FromGitter> <dscottboggs> right....so...https://carc.in/#/r/9p81
<FromGitter> <dscottboggs> the fact that gitter doesn't support the eyeroll emoji annoys me a lot
<oprypin> Blacksmoke16, well sure it would, if it was standard :)
<oprypin> thanks.
alexherbo2 has joined #crystal-lang
<oprypin> anyway the reason im doing these shenanigans is to keep code similar to its origin https://github.com/ocornut/imgui/blob/e8447dea453fe11c4f7da6512b86f4e039f03261/imgui_demo.cpp#L4414
<oprypin> so sure, i can make my own define
<oprypin> but how on earth would i make C++ code signal that a Crystal exception should be thrown
<oprypin> ooo a callback of course