Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 22 10:57
    straight-shoota closed #10540
  • Sep 22 10:57
    straight-shoota closed #10493
  • Sep 22 10:57
    straight-shoota closed #11234
  • Sep 21 18:28
    straight-shoota review_requested #11195
  • Sep 21 17:00
    straight-shoota labeled #11236
  • Sep 21 15:34
    straight-shoota labeled #11164
  • Sep 21 15:32
    straight-shoota labeled #11192
  • Sep 21 15:30
    straight-shoota labeled #11221
  • Sep 21 15:12
    lugia-kun edited #11237
  • Sep 21 15:04
    lugia-kun labeled #11237
  • Sep 21 15:04
    lugia-kun opened #11237
  • Sep 21 13:26
    straight-shoota closed #10467
  • Sep 21 13:26
    straight-shoota closed #10457
  • Sep 21 13:26
    straight-shoota closed #11215
  • Sep 21 13:24
    straight-shoota closed #10998
  • Sep 21 12:35
    bcardiff closed #11228
  • Sep 20 20:50
    straight-shoota assigned #10603
  • Sep 20 18:27
    beta-ziliani reopened #10310
  • Sep 20 17:25
    asterite closed #10310
  • Sep 20 17:13
    superhawk610 opened #11236
George Dietrich
@Blacksmoke16
id checkout that thread
From IRC (bridge bot)
@FromIRC
<riza> the code sample at the end is basically what I was driving at
<riza> using =~ is a good idea
mfiano
@mjfiano:matrix.org
[m]
nearly_equals? seems to be the desired behavior. I'll have to inspect it to see if it is semantically equivalent with what I need.
Thanks
George Dietrich
@Blacksmoke16
:thumbsup:
hightower4: that's quite the macro you got there
From IRC (bridge bot)
@FromIRC
<hightower4> yeah, probably {% debug %} would be the next thing
George Dietrich
@Blacksmoke16
would that help? idt it's even going to run because it doesnt even expland
expand
From IRC (bridge bot)
@FromIRC
<hightower4> Wouldn't it print if it was placed above the place of error?
George Dietrich
@Blacksmoke16
the error is the macro itself so no
mjfiano
@mjfiano:matrix.org
[m]
About the code in the above thread...they seem to overload =~ for the language's Float type. I was hoping to not monkey patch the whole language, if that is what this is doing, and only introduce this overload when used in my specific module.
George Dietrich
@Blacksmoke16
there are no specific scope overloads
other option would be to use a decorator
mfiano
@mjfiano:matrix.org
[m]
Perhaps my concerns are nothing, but I am hesitant to do such a thing, if the library I am writing is to be used with third party code expecting different behavior for =~ of 2 floats.
I don't know how the language behaves in this regard
George Dietrich
@Blacksmoke16
would be better off defining a new method in such case
mfiano
@mjfiano:matrix.org
[m]
Fair enough. Should I subclass the builtin float type and use that everywhere in my domain, or is there a more idiomatic approach?
George Dietrich
@Blacksmoke16
a decorator type is usually the better way to go afaik
mfiano
@mjfiano:matrix.org
[m]
I'll look that up
Thanks
Do you mean defining an annotation?
George Dietrich
@Blacksmoke16
more like something like
struct FloatWrapper
  @value : Float64

  forward_missing_to @value

  def initialize(@value : Float64); end

  def special_method
  end
end
mfiano
@mjfiano:matrix.org
[m]
Hmm, I don't really understand how that is delegating, but I'll study that code some. Thanks
mfiano
@mjfiano:matrix.org
[m]
Yeah that was my first stop. Just trying to figure out how this is different than inheritance. The docstring/example could be better imo
Taupiqueur
@alexherbo2
@Blacksmoke16 what is the % in the macro?
George Dietrich
@Blacksmoke16
hm?
Taupiqueur
@alexherbo2
%v1
Taupiqueur
@alexherbo2
it looks to work without the %
Rishav Sharan
@rishavs
How would one go about converting a hex string to normal string?
George Dietrich
@Blacksmoke16
what do you mean by "normal string"?
a hex string is just a string of hex characters
Taupiqueur
@alexherbo2
so I should replace my value with %value to avoid side effects?
George Dietrich
@Blacksmoke16
@alexherbo2 idt it would matter
that's not what fresh vars are for
Rishav Sharan
@rishavs
I am trying to convert a hexstring to base64. I am assuming that i need to first convert the hex to slice and then to base64
George Dietrich
@Blacksmoke16
hexstring.hexbytes
Rishav Sharan
@rishavs
Thanks :heart:
mfiano
@mjfiano:matrix.org
[m]
Is there a shorthand form for when you have the same type restriction for adjacent parameters, to make something like (a : Float64, b : Float64, c : Float64, d : Float64) more concise?
oprypin
@oprypin:matrix.org
[m]
mfiano: no
mfiano
@mjfiano:matrix.org
[m]
Ok, thanks
mfiano
@mjfiano:matrix.org
[m]
# src/origin/common.cr

require "math"

module Origin
  def foo(x, y, rel_tol, abs_tol)
    (x - y).abs <= Math.max(abs_tol, rel_tol * Math.max(x.abs, y.abs))
  end
end
# src/origin.cr

require "./origin/*"

Origin.foo 1.2, 3.4, 1e-7, 1e-7 # Error: undefined method 'foo' for Origin:Module
Can someone tell me what I am doing wrong here?
oprypin
@oprypin:matrix.org
[m]
mfiano: u defined an instance method but there's no instance involved
class A
include Origin
end

A.new.foo
but you probably want to just define a class/module method by writing def self.foo