Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 00:58
    HertzDevil synchronize #13034
  • 00:47
    HertzDevil synchronize #13034
  • Feb 02 22:23
    HertzDevil ready_for_review #13034
  • Feb 02 22:22
    straight-shoota closed #13039
  • Feb 02 22:21
    straight-shoota closed #13020
  • Feb 02 22:21
    straight-shoota closed #11646
  • Feb 02 22:21
    HertzDevil synchronize #13034
  • Feb 02 19:26
    straight-shoota labeled #13044
  • Feb 02 19:26
    straight-shoota labeled #13044
  • Feb 02 19:26
    straight-shoota assigned #13044
  • Feb 02 19:26
    straight-shoota opened #13044
  • Feb 02 18:56
    straight-shoota synchronize #13043
  • Feb 02 18:55
    straight-shoota labeled #13043
  • Feb 02 18:55
    straight-shoota labeled #13043
  • Feb 02 18:55
    straight-shoota labeled #13043
  • Feb 02 18:55
    straight-shoota labeled #13043
  • Feb 02 18:55
    straight-shoota assigned #13043
  • Feb 02 18:55
    straight-shoota opened #13043
  • Feb 02 18:07
    straight-shoota closed #12915
  • Feb 02 18:07
    straight-shoota edited #12915
mfiano
@mjfiano:matrix.org
[m]
It makes some things easy, like extracting a column from a matrix to a vector: https://git.mfiano.net/mfiano/origin.nim/src/branch/master/src/origin/mat.nim#L589-L595
George Dietrich
@Blacksmoke16
are there only ever going to be like 2..4 types?
idk, nvm, deff not familiar with this stuff
mjfiano
@mjfiano:matrix.org
[m]
2-4 for vectors.
The matrices I need are the same sizes squared: 4, 9, 16
which means rows x cols
But, np. I'm almost ready to take a break for today
mfiano
@mjfiano:matrix.org
[m]
oprypin: Were you talking about size or instruction overhead wrt classes vs structs?
oprypin
@oprypin:matrix.org
[m]
mfiano: class instances are always on the heap (scattered, so worse for cache) and, importantly, need to be garbage collected.
mfiano
@mjfiano:matrix.org
[m]
Yes, I'm aware of that. I'm almost thinking that is an acceptable trade-off to make in favor of a nice chained mutable method API
But I'm not certain yet. If I can find a nicer balance with structs, that'd be better.
ryanprior
@ryanprior:matrix.org
[m]
I'd like to write data to sqlite & read it back again from query results, all without writing custom serialization code. I like how JSON::Serializable works and would like something similar. Any suggestions?
ryanprior
@ryanprior:matrix.org
[m]
@Blacksmoke16: heck yeah, this looks fantastic
ryanprior
@ryanprior:matrix.org
[m]
Hold on though, it looks like DB::Serializable only handles creating objects from query results & not creating table schema or formatting query strings to insert data?
Or else I'm missing some big piece of this? This looks like JSON::Serializable except if it for some reason only gave you from_json but not to_json?
George Dietrich
@Blacksmoke16
Right
ryanprior
@ryanprior:matrix.org
[m]
Yikes, is this seen widely as a shortcoming or not really?
George Dietrich
@Blacksmoke16
That's the hard part
Not really, as there isn't a single way to do what you want. I.e. insert versus update
Plus the table should already be created, that would be out of scope
If it also handled migrations and such
ryanprior
@ryanprior:matrix.org
[m]
Okay well it's a start I guess :)
George Dietrich
@Blacksmoke16
Inserts and updates can just use prepared statements so really np
mfiano
@mjfiano:matrix.org
[m]
Perhaps a dumb question, but is there any best practice as to when to use x, @x, or self.x to refer to an instance variable in an instance method? I seem to be able to use all 3 with the same effect.
mfiano
@mjfiano:matrix.org
[m]
My guess is that @x is the only "safe" thing that will always resolve to an ivar, even if there is another local var or method named x...so is there no reason to use the other 2, other than to make things less explicit and confusing? :)
erdnaxeli
@erdnaxeli:cervoi.se
[m]
"x" resolves to "self.x", unless you have a local var named "x"
"self.x" is a method (you are probably using the macro "getter") that returns "@x"
and "@x" is the actual instance var
so the best practice if you want to access to the instance var is to use the instance var "@x" :)
From IRC (bridge bot)
@FromIRC
<hightower2> if at some point later you replace access to an instance var with a getter method, then you'll need to replace @x with x or self.x
<hightower2> sometimes I wish that instead of making local vars be unprefixed, the lang designers chose to prefix local vars... so then the scope/lookup of all unprefixed vars like 'x' or 'var1' would be very uniform regardless of whether it was a property or method
<hightower2> well, I guess if one really wanted to do so, one could stick to a rule of always prefixing local vars with something, manually...
George Dietrich
@Blacksmoke16
i always use self. when wanting to invoke a method, and use @x within the type
this way its always clear what is a method call and what isnt
however, a good usecase for using self.x is if you have customer logic in the getter and/or are using a lazily initialized ivar
From IRC (bridge bot)
@FromIRC
<hightower2> yes, that works, but what I find silly then is that we use self.x for vars and x for methods...
George Dietrich
@Blacksmoke16
can also use x and x()
From IRC (bridge bot)
@FromIRC
<hightower2> sure, but this just continues the practice of non-uniform invocation. I would actually prefer the invocation to always be 'x', regardless of whether it is an instance var accessor or instance method
Daniel Worrall
@Daniel-Worrall
If you have a lazy getter, I'd use x, but you could use self.x to be verbose too
Oh, glossed over. lazy was already mentioned
mfiano
@mjfiano:matrix.org
[m]
Makes sense, thanks all
Does crystal have anything like...I'm not sure what it's called, but in Nim, you can assign a slice to a slice of a variable...like:
var x = [1, 2, 3, 4, 5]
var y = [6, 7, 8, 9, 10]

x[1..2] = y[1..2] # x => [1, 7, 8, 4, 5]
Ary Borenszweig
@asterite
If you remove var from that code, it already works in Crystal. It's nothing special in the language, just a method call
mfiano
@mjfiano:matrix.org
[m]
Oh nice. It seems you can even grow shrink it with unsymmetrical ranges
Thanks @asterite
mfiano
@mjfiano:matrix.org
[m]
Are there functions for extracting the sign and fractional components of floating-point numbers? In some languages you have something like sign and fract:
sign(42.0) # 1.0
sign (-42.0) # -1.0
sign (0.0) # 0.0
fract(42.123) # 0.123
I suppose line 3 can be implemented differently if there is a distinction between IEEE-754 positive and negative zero