Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 09:37
    HertzDevil edited #12366
  • 08:32
    orangeSi synchronize #12356
  • 08:10
    orangeSi synchronize #12356
  • Aug 07 22:57
    HertzDevil edited #12368
  • Aug 07 22:57
    HertzDevil labeled #12368
  • Aug 07 22:57
    HertzDevil labeled #12368
  • Aug 07 22:57
    HertzDevil opened #12368
  • Aug 07 22:54
    HertzDevil labeled #12367
  • Aug 07 22:54
    HertzDevil labeled #12367
  • Aug 07 22:32
    HertzDevil synchronize #12366
  • Aug 07 19:55
    refi64 synchronize #12367
  • Aug 07 19:54
    refi64 opened #12367
  • Aug 07 19:15
    straight-shoota closed #7164
  • Aug 07 19:15
    straight-shoota closed #11790
  • Aug 07 02:08
    Blacksmoke16 labeled #12365
  • Aug 07 01:06
    HertzDevil edited #12366
  • Aug 07 01:03
    HertzDevil edited #11973
  • Aug 07 01:03
    HertzDevil edited #11973
  • Aug 07 01:02
    HertzDevil synchronize #11973
  • Aug 07 00:54
    oprypin review_requested #12293
From IRC (bridge bot)
@FromIRC
<straight-shoota> Hm, I've never used if foo = nilable instead of foo.try {}
From IRC (bridge bot)
@FromIRC
<xyhuvud> why would if foo = nilable be bad in the first place?
<raz> when it's followed by a longer block, or worse, when the var is then used outside of that block, it can be quite confusing
<xyhuvud> you don't get to avoid it for @instance variables anyhow, so you might as well embrace it.
<straight-shoota> TIL *_with_index is not limited to integer index
<straight-shoota> >> (0..4).each_with_index('a') { |x, i| puts "#{i}: #{x}" }
<DeBot_> straight-shoota: a: 0 - more at https://carc.in/#/r/blo8
From IRC (bridge bot)
@FromIRC
<raz> that's neat, now we just need a use-case for it :⁠D
<straight-shoota> printing ordered lists (like list-style-type: lower-alpha in CSS)
<raz> that might get a bit nasty after 25 items ;⁠P
<straight-shoota> replacing i += 1 by i = i.succ makes it even more generically useful
<straight-shoota> all good with succ + String: https://carc.in/#/r/blod
From IRC (bridge bot)
@FromIRC
<raz> ha!
Taupiqueur
@alexherbo2
how to get Crystal on macOS M1 ?
I tried brew install crystal and with --build-from-source
George Dietrich
@Blacksmoke16
mfiano
@mjfiano:matrix.org
[m]
I am not that familiar with generics in Crystal, and I'm wondering if they are similar to Nim or Rust in that I can restrict a generic type parameter inline. The following is a Nim function definition, where T is restricted to be of type Vec, which is used for both arguments and the return type. How can I do similar with Crystal, without a type alias or relying on the inferred call site types?
proc abs[T: Vec](o: var T, v: T): var T = ...
George Dietrich
@Blacksmoke16
not in that way, would have to be within one of the methods in a macro
i.e. not something the lang supports atm
mfiano
@mjfiano:matrix.org
[m]
I see, thanks.
George Dietrich
@Blacksmoke16
From IRC (bridge bot)
@FromIRC
<straight-shoota> This would be an example of a macro-based type restriction: https://github.com/crystal-lang/crystal/blob/13dd77ef01c0d55f2d43372f97c648ff81c737d9/src/slice.cr#L745-L748
Ary Borenszweig
@asterite
another way would be to use a helper method: def foo(x : T, v : T) : T; foo_helper(x, v); end; def foo_helper(x : Vec, v : Vec). So both have to be the same type, and both have to be Vec
mfiano
@mjfiano:matrix.org
[m]
Yeah I'm not a fan of making the body less readable to restrict a type or two
Also not realy a fan of Nim's inline restriction...would like a more readable where or even overloading forall
George Dietrich
@Blacksmoke16
to be clear you could put that 1 line macro in the constructor and thats all you'd need
mfiano
@mjfiano:matrix.org
[m]
I think I want to see the information in the signature where it belongs
From IRC (bridge bot)
@FromIRC
<straight-shoota> one day we'll hopefully get that =)
George Dietrich
@Blacksmoke16
yea thats not a thing atm, but can emulate it yourself for 1 line
so :shrug: could be worse
Ary Borenszweig
@asterite
Yes, it's definitely not hard to implement, we just need to come up with a syntax and do it :-)
mfiano
@mjfiano:matrix.org
[m]
:) Sure, not a deal breaker for me. I like Crystal's "for humans" philosophy, and adding line noise is not in line with that :)
Regardless, it is one thing I would use a lot if it was a thing.
I might play around with a macro sometime...for now it's not really needed. Thanks!
mfiano
@mjfiano:matrix.org
[m]
@Blacksmoke16: Where is out used, or is it just a reserved keyword?
mfiano
@mjfiano:matrix.org
[m]
Aha
I thought about your macro generating the entire def instead of mine just generating the body, and I decided on mine, for a couple reasons. 1) The readability as mentioned. 2) I would like to selectively choose which ones to annotate as always inlined, 3) I would like to add additional logic to some methods.
mfiano
@mjfiano:matrix.org
[m]

I'm trying to write a class method that initializes an Indexable type with random floats.

    def self.rand(min = 0.0, max = 1.0)
      res = new
      res.each_index { |i| res[i] = Random.rand min..max }
      res
    end

This works, but I am wondering if this can be done more concisely/in one line instead of 3. Don't really want to macro around this if the language has something I could use that I don't know about.

From IRC (bridge bot)
@FromIRC
<straight-shoota> I don't think this is much about the language, more about the API of your type
mfiano
@mjfiano:matrix.org
[m]
Perhaps.
mfiano
@mjfiano:matrix.org
[m]
I am thinking you are implying I write a new that takes a block. That would help at least.
From IRC (bridge bot)
@FromIRC
<riza> why not just put it in the initialize method?
From IRC (bridge bot)
@FromIRC
George Dietrich
@Blacksmoke16
its prob not in shardbox
its a manual registry remember
From IRC (bridge bot)
@FromIRC
<hightower2> ah so, didn't remember offhand, thanks
<hightower2> shards.info finds it, but also only if trying by 'tasko.cr' rather than just 'tasko'
srasu
@suskeyhose:matrix.org
[m]
Does the break statement break from the first while in its dynamic scope? Or are blocks handled specially by inlining to allow loop to have a block with a break statement?