Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 08:23
    caspiano edited #10531
  • Dec 08 23:04
    HertzDevil edited #12623
  • Dec 08 22:57
    Blacksmoke16 edited #9745
  • Dec 08 22:57
    Blacksmoke16 labeled #9745
  • Dec 08 22:57
    Blacksmoke16 labeled #9745
  • Dec 08 22:54
    HertzDevil labeled #12828
  • Dec 08 22:54
    HertzDevil labeled #12828
  • Dec 08 22:54
    HertzDevil opened #12828
  • Dec 08 22:34
    straight-shoota edited #12827
  • Dec 08 22:32
    straight-shoota edited #12827
  • Dec 08 22:29
    straight-shoota labeled #12827
  • Dec 08 22:29
    straight-shoota labeled #12827
  • Dec 08 22:29
    straight-shoota opened #12827
  • Dec 08 22:15
    straight-shoota closed #12814
  • Dec 08 17:12
    straight-shoota assigned #12814
  • Dec 08 17:12
    straight-shoota assigned #12813
  • Dec 08 17:12
    straight-shoota assigned #12809
  • Dec 08 17:12
    straight-shoota assigned #12802
  • Dec 08 17:12
    straight-shoota assigned #12797
  • Dec 08 17:12
    straight-shoota assigned #12664
George Dietrich
@Blacksmoke16
But I see more of like .foo and.foo? Versus .foo! And.foo?
mfiano
@mjfiano:matrix.org
[m]
FYI: This convention is very old, derived from Scheme (a Lisp)
mfiano
@mjfiano:matrix.org
[m]
I think I decided on classes over structs. pass-by-value is sort of convoluting my API already.
re: yesterday's discussion
George Dietrich
@Blacksmoke16
:thumbsup: usually the suggested approach is just use classes to start
then can fix bottlenecks as needed, OR if the obj is for immutable and small
mfiano
@mjfiano:matrix.org
[m]
Yeah I chose structs first because this is ultimately going to be for high performance math routines used in math visualization animations
But that was a mistake...for now
George Dietrich
@Blacksmoke16
are you created a lot of objects in a loop or something?
that would prob be noticable diff
mfiano
@mjfiano:matrix.org
[m]
The math routines will typically have 2 different methods for each...one that allocates, and one that mutates...so, using classes should be fine, and I can always mutate a pre-allocated object before the loop
I mean I can always mutate inside the loop, a pre-existing object
My Lisp code I'd like to replace is over-optimized. I create temporary objects at init time and never allocate at runtime...heh
George Dietrich
@Blacksmoke16
:thumbsup: sounds like a plan
mfiano
@mjfiano:matrix.org
[m]
One thing that I still haven't gotten used to is blocks. It's very strange how methods are not first-class functions, coming from Lisp and a bit of Rust.
George Dietrich
@Blacksmoke16
Hm?
mfiano
@mjfiano:matrix.org
[m]
top-level variables being inaccessible in methods, intentionally restricting closures in favor of a separate construct (blocks).
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?