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> <mixflame> I got my websocket patch almost ready
<FromGitter> <mixflame> I need to get around this IO::Error
<FromGitter> <mixflame> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60e39e34457e19611a382ee8]
<FromGitter> <mixflame> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60e39e4b9cf3171730110b83]
<FromGitter> <mixflame> what am i doing that breaks thepipe?
<FromGitter> <mixflame> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60e39f0d6c992105fdb93a15]
SeedyROM has joined #crystal-lang
<FromGitter> <mixflame> nevermind i fixed it
<FromGitter> <mixflame> hopefully someone merges my stuff soon, it works to give scalability in websocket apps on amber
jrayhawk_ is now known as jrayhawk
SeedyROM has quit [Quit: Leaving]
delucks has joined #crystal-lang
<delucks> hey folks! I'm trying to compile a Crystal "hello world" on a SPARCv9 machine running OpenBSD6.8 using LLVM 10. I've built a ll file of the code on a x86 machine running the latest release of the compiler, but when building it on the target machine using llc, I get a segfault running DAG Pattern Instruction Selection. LLVM claims to support this target triplet :) Has anyone successfully compiled Crystal
<delucks> code on SPARCv9/SPARC64?
<FromGitter> <Blacksmoke16> never heard of it
<FromGitter> <Blacksmoke16> https://crystal-lang.org/reference/platform_support.html breaks down the levels of support
<FromGitter> <Blacksmoke16> i dont see it on there so would prob need a PR to support it
SeedyROM has joined #crystal-lang
ur5us_ has quit [Ping timeout: 246 seconds]
<delucks> thanks Blacksmoke16. Do you have any suggestions for how to debug this llvm compilation failure and get more info about where in the crystal codebase needs to be modified?
<FromGitter> <Blacksmoke16> from my understanding since this is a totally new arch, you'd need something like https://github.com/crystal-lang/crystal/pull/3491
<FromGitter> <Blacksmoke16> however that PR is quite old so im not sure if the exact implementation is still relevant
<FromGitter> <Blacksmoke16> https://github.com/crystal-lang/crystal/pull/9360 is a more recent example, but it's based on x86_64 as well, so it didn't need to define an abi for that arch
<FromGitter> <Blacksmoke16> granted im no expert on this, just basing things off stuff i read in past PRs/issues but the majority of platform support would be defining the related libC bindings in https://github.com/crystal-lang/crystal/tree/master/src/lib_c, then an abi like the ones https://github.com/crystal-lang/crystal/tree/master/src/llvm/abi, then letting the compiler know about this new target, then any other platform
<FromGitter> ... specifics
<delucks> thanks, super helpful. is there a process for accepting new architectures like this, or would that be a discussion for a future PR?
<FromGitter> <Blacksmoke16> afaik the last one just made a PR
<FromGitter> <Blacksmoke16> that would probably suffice
<FromGitter> <Blacksmoke16> could prob reference the rust implementation of the abi as it also uses llvm
ur5us_ has joined #crystal-lang
deavmi_ has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
mike_onlooker has joined #crystal-lang
<FromGitter> <nanobowers> Hello all, new to crystal and trying to migrate some ruby code to crystal in an attempt to learn it. I'm trying to port something that uses rspec yield matchers: https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/yield-matchers ⏎ and cannot seem to find a feature in Crystal's `Spec` that has equivalent functionality. Did I miss something, or is there a shard that does this?
<FromGitter> <Blacksmoke16> whats the thing you're wanting to test?
<FromGitter> <Blacksmoke16> id just test that versus worrying about how many times something yields or something
<FromGitter> <nanobowers> Also, if anyone knows of a cheat-sheet (mapping) of ruby stdlib to crystal stdlib, that would be helpful. There are a lot of similarities, but also plenty of differences and a lot of hunting to find the *nearly* equivalent thing
<FromGitter> <mixflame> whew ok ⏎ Amber patch is perfect, 2 tests, working, and confirmed you don't have to use the hack anymore.
<FromGitter> <nanobowers> @Blacksmoke16 For this particular thing i could creat an array and successively yield to construct it, but for some streaming cases maybe that wont work... In this particular case, i picked up a utility written in ruby with rspec tests that i didnt write and have little familiarity with - I was hoping to spend more time in the code and just migrate the tests as closely as possible, but now i'll have a
<FromGitter> ... chance to explore both in more detail.
<FromGitter> <Blacksmoke16> can you share the code?
<FromGitter> <mixflame> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60e3c3fc8a40b11728477851]
<FromGitter> <Blacksmoke16> sorry that was @nanobowers
<FromGitter> <mixflame> oh, my bad ⏎ :)
<FromGitter> <Blacksmoke16> can you not just do like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60e3c625bcb3e8060e0104f9]
<FromGitter> <Blacksmoke16> or something along those lines?
<FromGitter> <Blacksmoke16> wayy more readable imo
<FromGitter> <Blacksmoke16> `Layout.new`*
<FromGitter> <Blacksmoke16> or whatever the type is
<FromGitter> <nanobowers> Yeah, probably so... I've used rspec for some time and never seen even half of the stuff i've seen used in this code.
<FromGitter> <Blacksmoke16> Spec module is deff a lot more simplistic than rspec, IMO for the better most of the time
<FromGitter> <nanobowers> Are 'named' globals available? Saw very little discussion in the documentation and the compiler complains when the long-name versions of builtin globals are used e.g. $0 vs $PROGRAM_NAME and $? vs $CHILD_STATUS
<FromGitter> <Blacksmoke16> crystal doesn't have global vars
<FromGitter> <Blacksmoke16> at least that the user can define on their own. The only real global vars are defined via the compiler, which are like `$~` and `$1`, `$n` representing regex matches
<FromGitter> <nanobowers> Makes sense, will need to add that to my list of things to find the Ruby equivalent for - I think i've figured out $? equiv vias Process.run()
<FromGitter> <nanobowers> Thanks for all of the help/advice
aquijoule_ has joined #crystal-lang
richbridger has quit [Ping timeout: 246 seconds]
SeedyROM has quit [Quit: Leaving]
ur5us_ has quit [Remote host closed the connection]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 252 seconds]
lucf117 has quit [Quit: Leaving]
mike_onlooker has quit [Ping timeout: 246 seconds]
<FromGitter> <YusufCakan> how to people normally debug the crystal compiler. Are there any instructions on how to do this.
<FromGitter> <mixflame> confirmed amber redis websocket adapter patch is stable and works with multiple amber processes :D
<FromGitter> <mixflame> +tests added+
ur5us has joined #crystal-lang
<postmodern> is there an Enumerable method that finds the last occurance based on a block?
<jhass[m]> mmh, I don't think so but could maybe concort something with with_index and max?
<FromGitter> <HertzDevil> you cannot traverse backwards with an `Enumerable`, but there's `rindex` for `Indexable`
<jhass[m]> has some yet unhandled edge cases around the only match being the first one or no match of course
<FromGitter> <HertzDevil> https://carc.in/#/r/bhfb
<jhass[m]> Indexable#rfind could use reverse_each and break I guess
ur5us has quit [Ping timeout: 240 seconds]
<postmodern> how do i specify a literal ASCII string? "\xff\xfe" is being interpreted as a unicode string with one character instead of two
<FromGitter> <naqvis> `"\u{ff}\u{fe}"` if two separate chars
<FromGitter> <naqvis> https://carc.in/#/r/bhhm
<postmodern> ah, weird syntax but that seems to work
<postmodern> ah but that defines a unicode string of four bytes. i need a two-byte string of 0xff and 0xfe
notzmv has quit [Ping timeout: 252 seconds]
<FromGitter> <naqvis> ` "\xff\xfe"` is actually two byte String
<FromGitter> <naqvis> `pp "\xff\xfe".to_slice # => Bytes[255, 254]`
<FromGitter> <naqvis> can you please describe, what are you getting? and what's your expected output?
<postmodern> i think the problem is because my code is using String#chars which returns unicode characters
<FromGitter> <naqvis> but `FF FE` is a UTF16-LE BOM
<postmodern> yeah, kind of wish Crystal had a way to forcibly defining an ASCII string, so you can contain non-UTF binary strings of random data that could be misinterpreted as UTF codepoints
<FromGitter> <naqvis> `pp "\u{ff}\u{fe}".chars # => ['ÿ', 'þ']` ⏎ ⏎ this is correct representation
<postmodern> bytes shows extra unicode stuff in there [195, 191, 195, 190]
<FromGitter> <Blacksmoke16> are they multibyte chars?
<postmodern> they shouldn't be, but i guess they are being interpreted as such
<FromGitter> <naqvis> since `String` is UTF-8 but you are dealing with UTF-16
<FromGitter> <naqvis> so you should be invoking `"\u{ff}\u{fe}".to_utf16` to get the correct byte representation
<postmodern> crystal's utf8-by-default Strings are making it hard for me to define a String of garbage ASCII data
<FromGitter> <naqvis> for encoding other than UTF-8 you should be using stream instead of String
<postmodern> ah ha, thanks
<postmodern> curious why String.new(Bytes[0xff, 0xfe]).chars.map(&.ord) returns [65533, 65533]
<postmodern> ah ha, i probably want to check String#valid_encoding? and check String#chars otherwise check String#bytes.
<FromGitter> <naqvis> its because that's not valid UTF-8
<FromGitter> <naqvis> `String.from_utf16("\u{ff}\u{fe}".to_utf16).chars.map(&.ord) # => [255, 254]`
<postmodern> well got specs passing. good enough for now.
<jhass[m]> I still wish we kept String at enforced valid UTF-8 only and instead developed better tooling around Bytes
<jhass[m]> the dual use of String as character and byte array is a C ism that has no real place in a high level language IMO. It's probably my biggest gripe with Ruby
<postmodern> as long as you don't end up going the route of python3's byte arrays vs utf8 strings. that seems to be creating a lot of friction.
<postmodern> i'd be happy if String#valid_encoding? # => false, then the String would fallback to raw ASCII where #chars would be the ASCII bytes converted to ASCII 8bit chars.
<postmodern> seems a bit magic with how String tries its best to convert non-UTF byte sequences to UTF chars. idk, i need to sleep.
postmodern has quit [Quit: Leaving]
notzmv has joined #crystal-lang
notzmv has quit [Ping timeout: 246 seconds]
notzmv has joined #crystal-lang
notzmv has quit [Ping timeout: 246 seconds]
notzmv has joined #crystal-lang
Flipez has quit [Changing host]
Flipez has joined #crystal-lang
notzmv has quit [Ping timeout: 240 seconds]
<FromGitter> <didactic-drunk> How do you get a `String` `Class::Name.method_name` from a macro?
<FromGitter> <Blacksmoke16> `{{"#{@type}.#{@def.name.id}".id}}` would prob do it
<FromGitter> <didactic-drunk> `@what` for the caller?
<FromGitter> <Blacksmoke16> is `Class::Name` the same as the class the method is in?
<FromGitter> <didactic-drunk> First example didn't quiet work ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60e4bafd24f0ae2a2448864f]
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/bhl6
<FromGitter> <didactic-drunk> My more complex code shows `Foo.bar`
<FromGitter> <Blacksmoke16> got a link?
<FromGitter> <didactic-drunk> Not published, I'll work on it
<FromGitter> <Blacksmoke16> the `\{{` is impt
<FromGitter> <Blacksmoke16> otherwise the macro expression is evaluated within the macro def
<FromGitter> <vgramkris> hey, new here, posting some general questions out here. ⏎ Any reason why String.to_i32! is not implemented?
<FromGitter> <vgramkris> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60e4bd85110daa37b1256d65]
<FromGitter> <Blacksmoke16> what would `to_i32!` to diff than `.to_i`?
<FromGitter> <Blacksmoke16> do diff*
<FromGitter> <vgramkris> if you see above, in line 2, assignment to be works fine
<FromGitter> <vgramkris> but line 4 is an issue
<FromGitter> <Blacksmoke16> right, can't you just call `c.to_i32`?
<FromGitter> <vgramkris> so if the String cannot be typecasted to i32 then i expect nil instead of a exception
<FromGitter> <Blacksmoke16> it'll raise on over/under flow iirc
<FromGitter> <vgramkris> thats right, that is what i am trying to overcome with the '!'
<FromGitter> <Blacksmoke16> you're getting a compile time error not an over/underflow exception
<FromGitter> <Blacksmoke16> if you want it to wrap, try `.to_i32?`
<FromGitter> <vgramkris> yep thats right
<FromGitter> <Blacksmoke16> so im not sure i see the problem?
<FromGitter> <Blacksmoke16> going from a number to number has diff semantics than a string to a number, which is probably why they have slightly diff conversion methods
<FromGitter> <vgramkris> yeah exactly, so num to num with ! we can do both checking & assignment in same line
<FromGitter> <vgramkris> but from string to num i need to check with .to_i32? and then assign
<FromGitter> <vgramkris> that is what i was trying to understand if there is any reason why for string they did not have .to_i32! while they do have .to_i32 for string
<FromGitter> <Blacksmoke16> still not sure i follow, you deff can do like `d : Int32 | Nil = c.to_i32?`
<FromGitter> <Blacksmoke16> because `to_i32!` represents a wrapping operation on the value if it over/underflows. In the case of a string its `to_i32?` because you cant wrap a string, and needs to handle the case of the string not being a number. So it'll return `nil` if either of those happens
<FromGitter> <vgramkris> okay this makes sense.. thanks!
<FromGitter> <Blacksmoke16> there is a block version of `to_i32` that you can use. Which will use the blocks value in case of under/overflow or its not a valid number
<FromGitter> <Blacksmoke16> e.g. `e : Int32 = c.to_i { 0 }`
<FromGitter> <Blacksmoke16> habit, `to_i` is the same as `to_i32`
<FromGitter> <vgramkris> sure, this would work as well! thanks @Blacksmoke16
<FromGitter> <Blacksmoke16> np, ofc another solution is to just not go from number to string to number :)
<FromGitter> <Blacksmoke16> but i assume that was just an example
<FromGitter> <vgramkris> :)
ur5us has joined #crystal-lang
postmodern has joined #crystal-lang
wolfshappen has joined #crystal-lang