Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 10:40
    straight-shoota closed #13040
  • 10:37
    straight-shoota milestoned #12963
  • 10:34
    straight-shoota milestoned #13034
  • 10:34
    straight-shoota milestoned #13034
  • 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
erdnaxeli
@erdnaxeli:cervoi.se
[m]
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
last one could just be like value - (value.floor) probably?
mfiano
@mjfiano:matrix.org
[m]
Of course I only went down the type tower API from Float64 to Float
George Dietrich
@Blacksmoke16
inherited methods are also listed towards the bottom
image.png
mfiano
@mjfiano:matrix.org
[m]
I suppose I was searching for the wrong half, fract 😆
mfiano
@mjfiano:matrix.org
[m]
If I have a type with value types (floats) for ivars, is it conventional to call a method which copies it clone or dup? In this case there is nothing to traverse for a deep copy, but I see some projects use clone in this case, while others use dup, so I'm not sure if there is a consensus.
George Dietrich
@Blacksmoke16
i imagine dup would be ok if the only thing you need is a new type instance
Ary Borenszweig
@asterite
dup for shallow copy, clone for deep copy
mfiano
@mjfiano:matrix.org
[m]
Yes, in this case a deep copy is a shallow copy
Maybe I worded it poorly. I was stating that either would be semantically correct for this particular example, and asking if there was a general agreement of which takes preference.
Ary Borenszweig
@asterite
I think there's no need to implement clone in this case given that dup already covers that use case
mfiano
@mjfiano:matrix.org
[m]
Thanks
Taupiqueur
@alexherbo2
how to convert the following yaml { a: ["1", "2"], b: true } to a MyClass with items being ItemA, ItemB?
the real use case is to parse a scope.yml having the properties roots, paths, etc. in a Scope class, I'd like to avoid flow control to check the filters as scope.roots, scope.paths, to something like scope.filters having their own class
I have Scope with property roots and property paths to pull the data from the file, but what I want when creating the instance is more something like a property filters doing when having roots keys, Root.new(value), etc.
so when filtering, I can just do scope.filters.all? { |filter| filter.evaluate_with(path) }
Taupiqueur
@alexherbo2
not sure if I actually need an intermediate class to pull the data fromscope.ymlother than Scope
like ScopeFile and using it to create the new Scope with the correct filters
George Dietrich
@Blacksmoke16
regarding your first question you can use a custom converter on that property
that could do like Item.new pull.read_string and return that array
Taupiqueur
@alexherbo2
currently I have a monolithic Scope class with hard-coded properties, it is not necessarily a problem as my scope will probably not have other props than roots, paths, extensions, but I realized there was too much logic in my Scope#evaluate method
I have to re-check if the props are nil, what they are supposed to do etc.
mfiano
@mjfiano:matrix.org
[m]
Is there a builtin module with a linear interpolation function?
George Dietrich
@Blacksmoke16
if its not in Math id vote no
Benjamin Wade
@RespiteSage
I just realized I basically accidentally reimplemented the main part of Tracery in my discord bot.
Daniel Worrall
@Daniel-Worrall
Hey @RespiteSage just to let you know, discordcr was moved to shardlab/discordcr and has updates there
Just saw that you were using the old source in your dependencies