Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 17:47
    HertzDevil edited #11537
  • 17:36
    straight-shoota milestoned #11515
  • 17:36
    straight-shoota synchronize #11343
  • 17:34
    straight-shoota closed #11512
  • 17:13
    HertzDevil labeled #11537
  • 17:13
    HertzDevil labeled #11537
  • 17:13
    HertzDevil opened #11537
  • 15:44
    straight-shoota edited #11536
  • 15:43
    straight-shoota labeled #11536
  • 15:43
    straight-shoota labeled #11536
  • 15:43
    straight-shoota labeled #11536
  • 15:43
    straight-shoota labeled #11536
  • 15:43
    straight-shoota opened #11536
  • 12:51
    BlobCodes opened #11535
  • 12:06
    gballet synchronize #9848
  • 09:33
    straight-shoota closed #11521
  • 09:29
    straight-shoota labeled #11534
  • 09:29
    straight-shoota labeled #11534
  • 09:25
    straight-shoota labeled #11533
  • 09:25
    straight-shoota labeled #11533
From IRC (bridge bot)
@FromIRC
<riza> I can't imagine being productive in a Lisp... I always have to sit and stare at the screen for 3 hours before typing a line. But it's a neat language, and I imagine if I spent the time on it maybe that 3 hours would shrink a bit...
mfiano
@mjfiano:matrix.org
[m]
I guess you have to have a good teacher/learning resource. I switched to Common Lisp from Python and was more productive after a week, which says a lot I think.
From IRC (bridge bot)
@FromIRC
<riza> The thing that slows me down about Crystal is the lack of a REPL. I spent years in the Ruby REPL and the lack of instantenous feedback makes the development process feel very slow to me.
<riza> I wonder what the performance benchmarks of common lisp against crystal are
<riza> maybe you wouldn't need to think about performance anymore!
mfiano
@mjfiano:matrix.org
[m]
I hear you there. Lisp is very interactive, with many more tools than the REPL, so this is very new to me.
Curious, do you think reading a book about Ruby would help me to learn Crystal better, or would I just confuse myself even more?
I know absolutely zero Ruby, but been using Crystal for about a week and loving it so far.
From IRC (bridge bot)
@FromIRC
<riza> there's just enough divergence between the ecosystems that I wouldn't recommend it
<riza> just stick with the reference and the api docs
Kirk Haines
@wyhaines
@riza, @asterite demo'd a instant feedback REPL for the Crystal Conference 1.0 a couple weeks ago.
From IRC (bridge bot)
@FromIRC
<riza> from an algorithms perspective, there are probably more reference implementations on the internet in ruby
<riza> neat! have a link? I had a ticket but couldn't go at the last minute
Kirk Haines
@wyhaines
The talks aren't published yet. As for the code....I don't know if he has committed it to a branch in the repo yet, or not.
But it's pretty slick.
mfiano
@mjfiano:matrix.org
[m]
Is this the new crystal i PR?
Kirk Haines
@wyhaines
Yeah
mfiano
@mjfiano:matrix.org
[m]
That looked interesting, but will take some time to iron out for sure. I really like how Crystal is managed and coming together.
If I'm being honest, I'll share the major reason besides the toxic community that I left Nim, and I'm not seeing it here.
The project seemed like an experimental sandbox of the lead developer, pushing out new features that didn't need to exist, and before testing them, making the compiler very complex and fragile. There's like 7 garbage collector choices, and a bunch of other features that makes it feel more like C++ than a well thought out language.
mfiano
@mjfiano:matrix.org
[m]
I need some help with blocks. Not sure if what I want is possible.

I'm trying not to get into macros at this point, so ignoring them. I have a bunch of methods that all repeat a lot of code. Here's 2 of them:

    def round
      v = dup
      v.each_with_index { |elt, i| v[i] = elt.round }
      v
    end

    def abs
      v = dup
      v.each_with_index { |elt, i| v[i] = elt.abs }
      v
    end

So I was thinking of making a method:

    private def element_wise(&block)
      v = dup
      v.each_with_index { |elt, i| v[i] = ... }
      v
    end

That does all the logic, and I would like to pass in the ellipsized part to be executed if possible like:

    def round
      element_wise { round }
   end

or something or other.

mfiano
@mjfiano:matrix.org
[m]
Is this even possible or should I abort now? :)
George Dietrich
@Blacksmoke16
v = dup
v.each_with_index { |elt, i| v[i] = yield elt }
v
actually what you want is prob v[i] = with elt yield
at which point you could prob just do like
element_wise &.round
but this is probably a good use case for macros
as the methods are all the same
mfiano
@mjfiano:matrix.org
[m]
with elt yield worked, but not with &.round...had to be { round }
George Dietrich
@Blacksmoke16
the former should work if you just do yield elt
iirc with .. yield is kinda buggy in some cases
so :shrug:
mfiano
@mjfiano:matrix.org
[m]
Pretty nifty, it works
This will do until I macroize things, thanks
George Dietrich
@Blacksmoke16
:thumbsup:
mfiano
@mjfiano:matrix.org
[m]
I'm not quite sure how I'd call element_wise for this one though, as it takes a second argument:
    def copysign(other : self)
      x = Math.copysign @x, other.x
      y = Math.copysign @y, other.y
      V2.new x, y
    end
George Dietrich
@Blacksmoke16
prob just keep it as is?
mfiano
@mjfiano:matrix.org
[m]
There's a bunch like that. They all have the same pattern, just additional args
George Dietrich
@Blacksmoke16
id say just go with a macro imo
even if you have a helper private method its still just boilerplate
mfiano
@mjfiano:matrix.org
[m]
I'm feeling a little intimidated by Crystal macros still
Spent last night trying to figure out the basics from reading the docs...couldn't apply it to my own code
George Dietrich
@Blacksmoke16
{% for m in ["round", "abs"] %}
    def {{m.id}}
      v = dup
      v.each_with_index { |elt, i| v[i] = elt.{{m.id}} }
      v
    end
{% end %}
assumes the method name is the same as the method called on the element, but could easily work around that if thats not what you want
mfiano
@mjfiano:matrix.org
[m]
In my case, I'd only want to generate the method body, not the whole method, supplying the name of the method called on the element
and therefor without a hard-coded list of strings too
George Dietrich
@Blacksmoke16
why would it matter?
mfiano
@mjfiano:matrix.org
[m]
@Blacksmoke16: I took your advice 😀