Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 13:58
    HertzDevil labeled #12186
  • 13:58
    HertzDevil labeled #12186
  • 13:58
    HertzDevil labeled #12186
  • 13:58
    HertzDevil labeled #12186
  • 13:58
    HertzDevil opened #12186
  • 13:02
    Blacksmoke16 labeled #12185
  • 10:45
    asterite edited #12185
  • 10:20
    straight-shoota milestoned #12184
  • 10:20
    straight-shoota labeled #12184
  • 10:18
    straight-shoota labeled #12185
  • 09:38
    asterite synchronize #12183
  • 09:06
    HertzDevil labeled #12184
  • 09:05
    HertzDevil labeled #12183
  • 09:05
    HertzDevil labeled #12183
  • 07:41
    syalon opened #12185
  • 07:41
    syalon labeled #12185
  • 04:47
    elebow opened #12184
  • 00:07
    asterite opened #12183
  • Jul 01 22:41
    straight-shoota milestoned #12167
  • Jul 01 22:36
    beta-ziliani labeled #12180
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?
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 happen
Ramakrishnan Vasantha Gopal
@vgramkris
okay this makes sense.. thanks!
George Dietrich
@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