Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 13:49
    HertzDevil labeled #11554
  • 13:49
    HertzDevil labeled #11554
  • 13:49
    HertzDevil labeled #11554
  • 13:49
    HertzDevil opened #11554
  • 13:23
    HertzDevil labeled #11505
  • 13:23
    HertzDevil labeled #11505
  • 12:25
    straight-shoota edited #11177
  • 12:24
    straight-shoota milestoned #11211
  • 11:31
    HertzDevil labeled #11553
  • 11:31
    HertzDevil labeled #11553
  • 11:31
    HertzDevil labeled #11553
  • 11:31
    HertzDevil opened #11553
  • 11:23
    HertzDevil labeled #11552
  • 11:23
    HertzDevil labeled #11552
  • 11:23
    HertzDevil opened #11552
  • 11:08
    straight-shoota closed #11475
  • 10:16
    straight-shoota closed #9647
  • 10:16
    straight-shoota edited #9647
  • 10:12
    straight-shoota demilestoned #11230
  • 10:07
    straight-shoota milestoned #11094
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*
Ramakrishnan Vasantha Gopal
@vgramkris
if you see above, in line 2, assignment to be works fine
but line 4 is an issue
George Dietrich
@Blacksmoke16
right, can't you just call c.to_i32?
Ramakrishnan Vasantha Gopal
@vgramkris
so if the String cannot be typecasted to i32 then i expect nil instead of a exception
George Dietrich
@Blacksmoke16
it'll raise on over/under flow iirc
Ramakrishnan Vasantha Gopal
@vgramkris
thats right, that is what i am trying to overcome with the '!'
George Dietrich
@Blacksmoke16
you're getting a compile time error not an over/underflow exception
if you want it to wrap, try .to_i32?
Ramakrishnan Vasantha Gopal
@vgramkris
yep thats right
George Dietrich
@Blacksmoke16
so im not sure i see the problem?
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
Ramakrishnan Vasantha Gopal
@vgramkris
yeah exactly, so num to num with ! we can do both checking & assignment in same line
but from string to num i need to check with .to_i32? and then assign
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
George Dietrich
@Blacksmoke16
still not sure i follow, you deff can do like d : Int32 | Nil = c.to_i32?