Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 18 13:16
    hugopl closed #12062
  • May 17 20:20
    Blacksmoke16 synchronize #12044
  • May 17 18:19
    straight-shoota edited #11947
  • May 17 18:19
    straight-shoota milestoned #11947
  • May 17 18:18
    straight-shoota closed #11971
  • May 17 18:18
    straight-shoota closed #11970
  • May 17 17:21
    HertzDevil labeled #12063
  • May 17 17:21
    HertzDevil labeled #12063
  • May 17 17:21
    HertzDevil labeled #12063
  • May 17 17:21
    HertzDevil opened #12063
  • May 17 16:29
    HertzDevil labeled #12062
  • May 17 13:50
    hugopl opened #12062
  • May 17 13:50
    hugopl labeled #12062
  • May 16 19:05
    lbguilherme synchronize #11947
  • May 16 17:29
    straight-shoota milestoned #11971
  • May 16 17:15
    straight-shoota closed #12038
  • May 16 17:15
    straight-shoota closed #12036
  • May 16 17:14
    straight-shoota edited #12038
  • May 16 13:47
    straight-shoota closed #12051
  • May 16 13:47
    straight-shoota closed #12050
From IRC (bridge bot)
@FromIRC
<jhass[m]> has some yet unhandled edge cases around the only match being the first one or no match of course
Quinton Miller
@HertzDevil
From IRC (bridge bot)
@FromIRC
<jhass[m]> Indexable#rfind could use reverse_each and break I guess
From IRC (bridge bot)
@FromIRC
<postmodern> how do i specify a literal ASCII string? "\xff\xfe" is being interpreted as a unicode string with one character instead of two
Ali Naqvi
@naqvis
"\u{ff}\u{fe}" if two separate chars
From IRC (bridge bot)
@FromIRC
<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
Ali Naqvi
@naqvis
"\xff\xfe" is actually two byte String
pp "\xff\xfe".to_slice # => Bytes[255, 254]
can you please describe, what are you getting? and what's your expected output?
From IRC (bridge bot)
@FromIRC
<postmodern> i think the problem is because my code is using String#chars which returns unicode characters
Ali Naqvi
@naqvis
but FF FE is a UTF16-LE BOM
From IRC (bridge bot)
@FromIRC
<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
Ali Naqvi
@naqvis

pp "\u{ff}\u{fe}".chars # => ['ÿ', 'þ']

this is correct representation

From IRC (bridge bot)
@FromIRC
<postmodern> bytes shows extra unicode stuff in there [195, 191, 195, 190]
George Dietrich
@Blacksmoke16
are they multibyte chars?
From IRC (bridge bot)
@FromIRC
<postmodern> they shouldn't be, but i guess they are being interpreted as such
Ali Naqvi
@naqvis
since String is UTF-8 but you are dealing with UTF-16
so you should be invoking "\u{ff}\u{fe}".to_utf16 to get the correct byte representation
From IRC (bridge bot)
@FromIRC
<postmodern> crystal's utf8-by-default Strings are making it hard for me to define a String of garbage ASCII data
Ali Naqvi
@naqvis
for encoding other than UTF-8 you should be using stream instead of String
From IRC (bridge bot)
@FromIRC
<postmodern> ah ha, thanks
From IRC (bridge bot)
@FromIRC
<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.
Ali Naqvi
@naqvis
its because that's not valid UTF-8
String.from_utf16("\u{ff}\u{fe}".to_utf16).chars.map(&.ord) # => [255, 254]
From IRC (bridge bot)
@FromIRC
<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
From IRC (bridge bot)
@FromIRC
<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
From IRC (bridge bot)
@FromIRC
<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.
didactic-drunk
@didactic-drunk
How do you get a String Class::Name.method_name from a macro for the current method?
George Dietrich
@Blacksmoke16
{{"#{@type.name.id}.#{@def.name.id}".id}} would prob do it
didactic-drunk
@didactic-drunk
@what for the caller?
George Dietrich
@Blacksmoke16
is Class::Name the same as the class the method is in?
didactic-drunk
@didactic-drunk
First example didn't quiet work
class Foo
  macro foo
    p "{{"#{@type.name.id}.#{@def.name.id}".id}}"
  end
end

class Bar
  def bar
    Foo.foo
  end
end

Bar.new.bar => "Foo.bar"
# Should print "Bar.bar"
George Dietrich
@Blacksmoke16
didactic-drunk
@didactic-drunk
My more complex code shows Foo.bar
George Dietrich
@Blacksmoke16
got a link?
didactic-drunk
@didactic-drunk
Not published, I'll work on it
George Dietrich
@Blacksmoke16
the \{{ is impt
otherwise the macro expression is evaluated within the macro def
Ramakrishnan Vasantha Gopal
@vgramkris
hey, new here, posting some general questions out here.
Any reason why String.to_i32! is not implemented?
a : Int64 = (Int32::MAX).to_i64 + 1
b : Int32 | Nil = a.to_i32!
c : String = a.to_s
d : Int32 | Nil = c.to_i32!  # Error: undefined method 'to_i32!' for String
George Dietrich
@Blacksmoke16
what would to_i32! to diff than .to_i32?
do diff*