## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• 02:16
renovate[bot] edited #12735
• Feb 04 23:27
straight-shoota milestoned #12966
• Feb 04 23:27
straight-shoota milestoned #12966
• Feb 04 22:45
Blacksmoke16 synchronize #12966
• Feb 04 12:51
straight-shoota closed #12224
• Feb 04 12:51
straight-shoota closed #13034
• Feb 04 12:15
straight-shoota milestoned #12921
• Feb 04 12:15
straight-shoota milestoned #12921
• Feb 04 10:44
straight-shoota edited #12921
• Feb 04 02:39
cyangle synchronize #12921
• Feb 04 01:08
cyangle synchronize #12921
• Feb 04 01:08
cyangle synchronize #12921
• Feb 03 22:11
straight-shoota labeled #12794
• Feb 03 22:11
straight-shoota assigned #12794
• Feb 03 22:07
straight-shoota synchronize #12959
• Feb 03 21:38
straight-shoota milestoned #12983
• Feb 03 21:38
straight-shoota milestoned #12983
• Feb 03 17:37
straight-shoota milestoned #13045
• Feb 03 17:37
straight-shoota milestoned #13045
• Feb 03 16:49
straight-shoota review_requested #13045
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
@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
George Dietrich
@Blacksmoke16
static arrays are also pass by value
mfiano
@mjfiano:matrix.org
[m]
Right, but I wouldn't be returning them
George Dietrich
@Blacksmoke16
so then just use a struct within the class and return self as you would?