Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 04:54
    aarongodin synchronize #11765
  • 04:52
    aarongodin synchronize #11765
  • 04:42
    aarongodin synchronize #11765
  • Jan 24 18:25
    straight-shoota labeled #11765
  • Jan 24 18:25
    straight-shoota labeled #11765
  • Jan 24 18:20
    FnControlOption synchronize #11476
  • Jan 24 18:06
    aarongodin opened #11765
  • Jan 24 17:42
    straight-shoota synchronize #11563
  • Jan 24 17:39
    FnControlOption synchronize #11476
  • Jan 24 17:05
    asterite closed #11756
  • Jan 24 14:30
    straight-shoota synchronize #11563
  • Jan 23 16:04
    HertzDevil labeled #11764
  • Jan 23 16:04
    HertzDevil opened #11764
  • Jan 23 16:04
    HertzDevil labeled #11764
  • Jan 23 15:34
    HertzDevil labeled #11763
  • Jan 23 15:34
    HertzDevil labeled #11763
  • Jan 23 15:34
    HertzDevil opened #11763
  • Jan 23 15:20
    HertzDevil labeled #11761
  • Jan 23 15:10
    HertzDevil labeled #11762
  • Jan 23 15:10
    HertzDevil labeled #11762
mfiano
@mjfiano:matrix.org
[m]
The specialness of initialize confused me
srasu
@suskeyhose:matrix.org
[m]
That's fair.
mfiano
@mjfiano:matrix.org
[m]
What about the new method that prompted this question early today?
    def self.new(&)
      res = new
      res.each_index { |i| res[i] = yield i }
      res
    end
Since my struct is Indexable I do this to allow passing a block
George Dietrich
@Blacksmoke16
thats probably fine
mfiano
@mjfiano:matrix.org
[m]
Example usages:
  def self.rand(min : T = 0.0, max : T = 1.0)
    new { Random.rand min..max }
  end

  def self.rand(min : self = ZERO, max : self = ONES)
    new { |i| Random.rand min[i]..max[i] }
  end
srasu
@suskeyhose:matrix.org
[m]
Yeah, that makes sense to me if Crystal doesn't provide a way to pass a block via initialize normally
mfiano
@mjfiano:matrix.org
[m]
That I'm not sure of, but thank you!
mfiano
@mjfiano:matrix.org
[m]
Anyone ever wish there was a way to mixin a module with instance and class methods and it doing the logical thing, rather than choosing how they are converted with include vs extend?
srasu
@suskeyhose:matrix.org
[m]
I finally see the answer to my question. A break inside a block breaks from the method that called the block

Which makes me curious about this

def something
  yield
end

def pass
  something { yield }
  puts "hey"
end

pass do
  break
end

does it print "hey"?

From IRC (bridge bot)
@FromIRC
<riza> @mjfiano yeah, that's the exact situation I was referring to when I said I use new sometimes to overload.
mfiano
@mjfiano:matrix.org
[m]
Ah
From IRC (bridge bot)
@FromIRC
<riza> @suskeyhose the semantics of the break operator in crystal (and ruby) are a bit counterintuitive because of the way that loops are generally implemented -- as blocks
<riza> this is also true of next
srasu
@suskeyhose:matrix.org
[m]
That answered my question
mfiano
@mjfiano:matrix.org
[m]
I'm guessing I need a macro to make this generic using Indexable instead of x/y/z/w in order to make a mixin that can be added to 2d, 3d and 4d vectors? The short-circuiting behavior of && tells me yes
    def <=>(other : self)
      @x <=> other.x && @y <=> other.y
    end
I'm just hoping macros are expanded after type merging
From IRC (bridge bot)
@FromIRC
<riza> make it generic meaning accept any number of operands to that comparison? like to be able to compare some XY with another XY and some XYZ with another XYZ, etc?
mfiano
@mjfiano:matrix.org
[m]
Make it generic as in, using each or something from Indexable rather than the logic explicitly needing to know about the ivars
But I think we meant the same thing
From IRC (bridge bot)
@FromIRC
<riza> you could either: ditch individual ivars and have an array which represented the set -- you could do this with generics easily
<riza> or you can use a macro to build out the guts of the class
Ary Borenszweig
@asterite
@suskeyhose:matrix.org you can break from a block where there's no while at all. The break goes a GOTO to the end of the called method (done with LLVM)
mfiano
@mjfiano:matrix.org
[m]
Thanks
From IRC (bridge bot)
@FromIRC
George Dietrich
@Blacksmoke16
:grimacing:
im sure there's a better way...
From IRC (bridge bot)
@FromIRC
<raz> i wish... but all these things can be nil and i can't change it (protobuf). i tried rewriting it in a bunch of ways. but it seems my only choices are spreading it out over 6 variable assignments or, well, this.
mfiano
@mjfiano:matrix.org
[m]
oh dear
George Dietrich
@Blacksmoke16
if you know all of this stuff is not nilable is there a reason its nilable in the first place?
im not super familiar with protobuf, but isn't the idea that you dont make everything nilable?
From IRC (bridge bot)
@FromIRC
<raz> well it's a "oneof". request.item.obj tells me which attr is set, so i can then look it up as request.item[ request.item.obj ]. i'm afraid all of these things are legally nil'able in this situation, but i'm still trying to find a better way
oprypin
@oprypin:matrix.org
[m]
heh could be a union of namedtuples
From IRC (bridge bot)
@FromIRC
<raz> https://carc.in/#/r/blw8 - this version also works.
oprypin
@oprypin:matrix.org
[m]
(with exactly one key each)
From IRC (bridge bot)
@FromIRC
<raz> but that's what my complain from earlier was about, i don't find it exactly clearer to read
George Dietrich
@Blacksmoke16
are you the only one using these types?
could leverage getter!
just would have to know when to do .item? versus .item
From IRC (bridge bot)
@FromIRC
<raz> hmmm that sounds like an idea. i may try a pr on protobuf.cr
George Dietrich
@Blacksmoke16
a quick look suggests they already support that
required ones are not nilable, optional are
From IRC (bridge bot)
@FromIRC
<raz> yea, but in proto3 everything is optional (don't get me started...)
George Dietrich
@Blacksmoke16
welp
From IRC (bridge bot)
@FromIRC
<riza> might as well write in node then
<raz> heureka.not_nil!