Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 02 23:04
    straight-shoota milestoned #12188
  • Jul 02 19:13
    Blacksmoke16 labeled #12189
  • Jul 02 19:13
    Blacksmoke16 labeled #12189
  • Jul 02 19:11
    asterite opened #12189
  • Jul 02 19:09
    asterite assigned #12187
  • Jul 02 16:53
    HertzDevil edited #12186
  • Jul 02 16:53
    HertzDevil edited #12186
  • Jul 02 15:24
    Blacksmoke16 labeled #12187
  • Jul 02 15:24
    Blacksmoke16 labeled #12187
  • Jul 02 15:19
    HertzDevil edited #12186
  • Jul 02 15:18
    HertzDevil edited #12186
  • Jul 02 15:16
    HertzDevil labeled #12188
  • Jul 02 15:16
    HertzDevil labeled #12188
  • Jul 02 15:16
    HertzDevil opened #12188
  • Jul 02 15:07
    cyangle labeled #12187
  • Jul 02 15:07
    cyangle opened #12187
  • Jul 02 13:58
    HertzDevil labeled #12186
  • Jul 02 13:58
    HertzDevil labeled #12186
  • Jul 02 13:58
    HertzDevil labeled #12186
  • Jul 02 13:58
    HertzDevil labeled #12186
From IRC (bridge bot)
@FromIRC
<straight-shoota> *kotlin
From IRC (bridge bot)
@FromIRC
<raz> https://kotlinlang.org/docs/null-safety.html#the-operator - similar to crystal but syntax is more convenient, closer to ruby in that regard (?. instead of .try &)
<raz> (eh sorry, my link hit a bit too low, you gotta scroll up a bit to "Safe calls")
Ary Borenszweig
@asterite
Regarding if foo = ..., I proposed being able to use if foo := bar in conditionals to avoid this issue, but it wasn't well received. I think it would have made things much clearer for some
From IRC (bridge bot)
@FromIRC
<straight-shoota> raz, try or a safe navigation operator can't really replace a proper conditional. They are related but different use cases IMO.
<straight-shoota> An equivalent alternative to if foo = some_nilable would be foo = some_nilable; if foo (or maybe a dedicated assignment operator as @asterite mentioned)
From IRC (bridge bot)
@FromIRC
<raz> yup true. but with more convenient navigation fewer people would reach for if foo = nilable. i think atm that mainly happens because they want to avoid the ugly .try or .not_nil! that would otherwise be required.
<raz> (as mentioned in kotlin if foo = anything is not allowed at all. i imagine they may have had a similar discussion in their past)
<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.