Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 28 21:02
    Blacksmoke16 labeled #13025
  • Jan 28 21:02
    Blacksmoke16 labeled #13025
  • Jan 28 21:02
    Blacksmoke16 labeled #13024
  • Jan 28 21:02
    Blacksmoke16 labeled #13024
  • Jan 28 18:45
    asterite opened #13025
  • Jan 28 16:23
    meatball133 synchronize #13024
  • Jan 28 15:53
    meatball133 edited #13024
  • Jan 28 15:51
    meatball133 opened #13024
  • Jan 28 15:10
    meatball133 ready_for_review #13008
  • Jan 28 13:24
    straight-shoota closed #13014
  • Jan 28 02:34
    Blacksmoke16 labeled #13023
  • Jan 28 02:19
    cyangle labeled #13023
  • Jan 28 02:19
    cyangle opened #13023
  • Jan 28 00:41
    devnote-dev labeled #13022
  • Jan 28 00:41
    devnote-dev opened #13022
  • Jan 27 23:05
    straight-shoota labeled #13021
  • Jan 27 23:05
    straight-shoota labeled #13021
  • Jan 27 23:05
    straight-shoota labeled #13021
  • Jan 27 23:05
    straight-shoota labeled #13021
  • Jan 27 23:05
    straight-shoota opened #13021
mfiano
@mjfiano:matrix.org
[m]
I'm just not sure why that is the case compared to first-class functions. Maybe I don't fully understand blocks
George Dietrich
@Blacksmoke16
Have you read about procs?
mfiano
@mjfiano:matrix.org
[m]
Yeah, and I don't know how that differs from a lambda/anonymous function in other languages.
George Dietrich
@Blacksmoke16
It's the same concept
A method with a block is similar to a method that accepts an anonymous callback function
mfiano
@mjfiano:matrix.org
[m]
Yeah...it's just confusing me because lambda calculus is so simple and doesn't require any of that to do the same things.
George Dietrich
@Blacksmoke16
:shrug:
mfiano
@mjfiano:matrix.org
[m]
module Origin
  private DEFAULT_TOLERANCE = 1e-7

  def self.=~(x : Float64, y : Float64, rel_tol : Float64 = DEFAULT_TOLERANCE, abs_tol : Float64 = rel_tol)
    (x - y).abs <= Math.max(abs_tol, rel_tol * Math.max(x.abs, y.abs))
  end
end
Interestingly, this can be called as a fully-qualified method: Origin.=~(a, b, rel_tol: c, abs_tol: d), or a binary operator without qualification if the defaults are sufficient: a =~ b. I'm not sure why the former requires qualification.
I think mayhbe my code is wrong and it is calling the wrong overload
No it is calling the same method in both cases.
mfiano
@mjfiano:matrix.org
[m]
I think everything is fine actually. If anyone has any suggestions for improvements on this snippet, I'd appreciate it: https://play.crystal-lang.org/#/r/bky9
George Dietrich
@Blacksmoke16
you can just do property x : Float64, y : Float64
save you 2 lines :p
mfiano
@mjfiano:matrix.org
[m]
Oh thanks
I just found what I think is a very minor compiler bug
George Dietrich
@Blacksmoke16
oh?
mfiano
@mjfiano:matrix.org
[m]
I tried to see if I could overload == instead of =~, and the error message says I'm trying to define a setter with more than 1 parameter. I know why this is the case, but maybe a special-cased error for arity-overloading == should exist
George Dietrich
@Blacksmoke16
pretty sure thats moreso an accepted limitation
mfiano
@mjfiano:matrix.org
[m]
Odd
I would expect <, > to be symmetrical with <=, <=.
err <=, >=
George Dietrich
@Blacksmoke16
right, hence the bug :p
which would be more likely to make the others only 1 arg as well
mfiano
@mjfiano:matrix.org
[m]
Has a stropping feature been shut down yet, like Nim?
George Dietrich
@Blacksmoke16
hm?
mfiano
@mjfiano:matrix.org
[m]
Stropping lets the user re-use reserved keywords in a different context, usually by escaping the symbol in some way. In Nim for example, you can define an == function by wrapping it in backticks
George Dietrich
@Blacksmoke16
ah no, the Crystal way would use a diff word
mfiano
@mjfiano:matrix.org
[m]
Ah k
mfiano
@mjfiano:matrix.org
[m]
I suppose I would have to manually define my property methods if I were to use a static array as storage and I wanted to map those x, y names to indices?
George Dietrich
@Blacksmoke16
im pretty sure that offers no benefit over a struct with getters
mfiano
@mjfiano:matrix.org
[m]
I'm using a class, and for different vector lengths, and especially matrices, it'd allow me to write iteration macros to define a lot of routines for all shapes simultaneously
George Dietrich
@Blacksmoke16
you meant to use a static array as a property within the class?
mean*
mfiano
@mjfiano:matrix.org
[m]
Yep
George Dietrich
@Blacksmoke16
cant you also just store a struct in the class?
be easier than knowing what index is what
mfiano
@mjfiano:matrix.org
[m]
Are you familiar with GLSL?
George Dietrich
@Blacksmoke16
nope
oprypin
@oprypin:matrix.org
[m]
mfiano: what's your question
mfiano
@mjfiano:matrix.org
[m]
I want to implement "swizzling", with a macro. That means, for a 2-dimensional vector that has an X and Y property, a macro would generate permutations of the accessors: x, y, xx, yy, yx
I have done such in Nim before. Just trying to figure out the best way with Crystal
oprypin
@oprypin:matrix.org
[m]
mfiano: well if your question can be more generally rephrased as "generate GLSL at compile time", here you go: https://gist.github.com/ba18db84e5e55ddc6d07a661062ae186
mfiano
@mjfiano:matrix.org
[m]
No no
oprypin
@oprypin:matrix.org
[m]
but like... why doesnt it solve your problem
mfiano
@mjfiano:matrix.org
[m]
This is not for generating GLSL in any way. It is for CPU computations. I was just pointing at the feature in GLSL
oprypin
@oprypin:matrix.org
[m]
mfiano: ok nevermind. then you can just use macros, yeah
i would suggest to still use a struct as storage, not a static array
mfiano
@mjfiano:matrix.org
[m]
I would like to use classes, containing an array, in order to support chained methods (mutations that return self)
pass by value would prevent that