Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 08:50
    HertzDevil edited #11348
  • 08:34
    HertzDevil edited #11348
  • 08:33
    HertzDevil labeled #11349
  • 08:33
    HertzDevil opened #11349
  • 07:35
    HertzDevil opened #11348
  • 07:35
    HertzDevil labeled #11348
  • 07:35
    HertzDevil labeled #11348
  • 04:24
    HertzDevil synchronize #11139
  • Oct 22 19:53
    straight-shoota synchronize #11207
  • Oct 22 17:04
    straight-shoota synchronize #11139
  • Oct 22 17:04
    straight-shoota synchronize #11207
  • Oct 22 17:02
    straight-shoota synchronize #11297
  • Oct 22 17:02
    straight-shoota synchronize #11207
  • Oct 22 12:49
    straight-shoota closed #10889
  • Oct 22 12:49
    straight-shoota closed #6498
  • Oct 22 12:44
    straight-shoota closed #10377
  • Oct 22 12:43
    straight-shoota closed #11265
  • Oct 22 12:43
    straight-shoota closed #4704
  • Oct 22 12:43
    straight-shoota closed #11262
  • Oct 22 12:43
    straight-shoota closed #11253
mfiano
@mjfiano:matrix.org
[m]
Which has the special NoReturn type
mfiano
@mjfiano:matrix.org
[m]
What class does #[]= come from?
I would like to include the 5 overloads for #[]= of Array into my Indexable struct type. Any ideas?
mfiano
@mjfiano:matrix.org
[m]
Is there a better way to perform an element-wise operation on my Indexable struct?
    def round
      v = dup
      v.each_with_index { |elt, i| v[i] = elt.round }
      v
    end
From IRC (bridge bot)
@FromIRC
<riza> #map
mfiano
@mjfiano:matrix.org
[m]
But the point is to mutate while traversing
I don't see how to do that with map
From IRC (bridge bot)
@FromIRC
<riza> from your code there, I don't see what you're trying to achieve that map doesn't
mfiano
@mjfiano:matrix.org
[m]
map returns an iterator which can be converted to an array
in my code, i am mutating the ivars of an Indexable struct
Not constructing an intermediate sequence
From IRC (bridge bot)
@FromIRC
<riza> dup?
mfiano
@mjfiano:matrix.org
[m]
Yeah I'm doing it on a copy as a test to prevent some foot guns that were bothering me
From IRC (bridge bot)
@FromIRC
<riza> okay, I see. It looks like Indexable doesn't include map anyway
mfiano
@mjfiano:matrix.org
[m]
But self.each_with_index { |elt, i| self[i] = elt.round } doesn't return anything, unlike map
It modifies my struct in place
From IRC (bridge bot)
@FromIRC
<riza> sure, whats your end goal with this which each_with_index doesn't achieve?
mfiano
@mjfiano:matrix.org
[m]
each_with_index is what I came up with, and it works. I was only wondering if there was something more concise/more idiomatic for this use-case :)
I've only played with a tiny bit of the API, and no 3rd party libraries or anything yet
From IRC (bridge bot)
@FromIRC
<riza> dealing with the indices manually doesn't feel idiomatic to me, but it's not at all wrong
<riza> (I would run a .map so I didn't need to deal with the indices)
<riza> self.map {|e| e.round}
mfiano
@mjfiano:matrix.org
[m]
that will produce an array, right?
From IRC (bridge bot)
@FromIRC
<riza> Well, #map isn't available on an Indexable so it wouldn't compile
<riza> what led you to use an Indexable instead of just an Array?
mfiano
@mjfiano:matrix.org
[m]
array is a generic class, not a module. Blacksmoke16 recommended me to include Indexable on my struct so that I can implement the abstract methods to be able to index/iterate over it
Which I have done and therefor get Enumerable and Iterable too
I'm not sure what you mean by #map not being available. It is inherited in Indexable from Enumerable
From IRC (bridge bot)
@FromIRC
<riza> oh I see, this is an exercise in implementing the modules
mfiano
@mjfiano:matrix.org
[m]
I mean what I have works. The map suggestion is only half of the work required.
From IRC (bridge bot)
@FromIRC
<riza> oh sure enough it is. I thought Indexable only included Iterable.
mfiano
@mjfiano:matrix.org
[m]
This is more than constructing a sequence of values. It is modifying the input sequence in the process, so does not need an intermediary sequence.
That's why I chose each_with_index. Maybe this is not idiomatic, but I don't see another way to do it efficiently
From IRC (bridge bot)
@FromIRC
<riza> you're probably right about that
<riza> a bunch of the crystal community sheds a lot of sweat about saving bits of memory... I try to avoid dealing with memory concerns
<riza> it's not wrong by any means, I'd just rather solve problems that aren't already more-or-less solved for me by the language
<riza> if that weren't the case, I'd write a lot more C
mfiano
@mjfiano:matrix.org
[m]
Usually a good decision, at least until profiling says you shouldn't
From IRC (bridge bot)
@FromIRC
<riza> yep, exactly
mfiano
@mjfiano:matrix.org
[m]
Ok thanks for the help :)
From IRC (bridge bot)
@FromIRC
<riza> thankfully in Crystal, it's pretty uncommon to need to care about an extra loop or copy of the data
mfiano
@mjfiano:matrix.org
[m]
Speaking of the Crystal community. It is small, but probably the most helpful for a newcomer than any of the few dozen languages I've used.
Very friendly crowd around here
From IRC (bridge bot)
@FromIRC
<riza> well I think we all count that as a win, for everyone. glad you found it welcoming, it often is exactly that
mfiano
@mjfiano:matrix.org
[m]
I left Nim, which is a similar language, due to a very toxic community (among other reasons, but mostly that)
It was sad, but I am liking everything about Crystal much better anyway
From IRC (bridge bot)
@FromIRC
<riza> Nim's a pretty neat language. It's difficult to keep a community from getting toxic or divided as it grows.
From IRC (bridge bot)
@FromIRC
<riza> @mjfiano what kind of programming do you do which you were using Nim for and are now evaluating crystal?
mfiano
@mjfiano:matrix.org
[m]
riza: Mostly 3D games, or 3D math visualizations/simulations that require soft real time performance.