ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
ur5us has quit [Ping timeout: 250 seconds]
<FromGitter> <mjfiano:matrix.org> I find myself explicitly typing the return value of each method, so it shows up in docs, and also to help catch silly logical mistakes causing the compiler to deduce something i wasn't intending. am i alone?
<FromGitter> <mjfiano:matrix.org> and also, I noticed that some people use `{{ ... }}` in place of `{% ... %}` to splice in compile-time evaluations. Are they always interchangeable, or only for certain things?
<FromGitter> <mjfiano:matrix.org> Also back to being afk, no rush
<FromGitter> <Blacksmoke16> no, its a good idea to add type restrictions
<FromGitter> <Blacksmoke16> normally the practice is to use `{{ ... }}` for things that should "paste" something into the program, while `{% ... %}` are used for meta level stuff. Like defining variables, loops, conditional logic etc
<FromGitter> <mjfiano:matrix.org> For matrix accessors, instead of names like x, y, z, etc, they are supposed to be accessed by row/column indices. That leaves: ⏎ ⏎ 1) Continue using named accessors prefixed with for example `m`, as in `matrix.m23`. ⏎ 2) Override the underlying storage from 1-dimensional and or the `[]` method to be able to use `matrix[2][3]`. ⏎ 3) Use the array-like literal syntax of `matrix{2, 3}`. ...
<FromGitter> <Blacksmoke16> You can make #[] take 2 args
<FromGitter> <mjfiano:matrix.org> You mean so `matrix[2, 3]` is possible?
<FromGitter> <Blacksmoke16> Yes
<FromGitter> <mjfiano:matrix.org> That's what I'll try first then. Thanks
<FromGitter> <mjfiano:matrix.org> Found this, and, I understand very little of it https://github.com/unn4m3d/crystaledge/blob/4e546ea9cedb55dee2e9df48cde2f91d5616bd37/src/crystaledge/matrix.cr
<FromGitter> <mjfiano:matrix.org> I mean, I see they are doing this, but I don't get the Slice stuff, or why it's needed
<FromGitter> <Blacksmoke16> It's basically working directly with a pointer, but safer as it has bounds checks
<FromGitter> <mjfiano:matrix.org> I get that. I don't know why not just use an array
<FromGitter> <mjfiano:matrix.org> or static array, rather than this delegating
<FromGitter> <Blacksmoke16> Performance probably?
<FromGitter> <mjfiano:matrix.org> Ok, is `[]=` assignment a statement or expression?
<FromGitter> <mjfiano:matrix.org> I don't see a return value in the signature for the overloads in the API anyway
Nik- has joined #crystal-lang
<FromGitter> <naqvis> @mjfiano:matrix.org `[]=` is an expression, it returns the value
<FromGitter> <naqvis> https://carc.in/#/r/bmzf
postmodern has joined #crystal-lang
<postmodern> does crystal have an annotation that's the equivalent of __attribute__((__packed__))?
<FromGitter> <naqvis> `Packed`?
<FromGitter> <mjfiano:matrix.org> Thanks
Welog has quit [*.net *.split]
Welog has joined #crystal-lang
<FromGitter> <mjfiano:matrix.org> Does the compiler or LLVM ever try to inline normal methods (ones that don't yield, etc)? I'm just wondering if I can save some time benchmarking and manually marking functions with the `AlwaysInlined` annotation, which would be a lot of work on all my target hardware, and instead just leave it up to the compiler.
sagax has quit [*.net *.split]
sagax has joined #crystal-lang
Welog has quit [Remote host closed the connection]
Welog has joined #crystal-lang
<postmodern> naqvis, thanks!
<FromGitter> <pyrsmk> > @mjfiano:matrix.org `[]=` is an expression, it returns the value ⏎ ⏎ Does it depend on how `[]=` is implemented? It would make sense to have it written like `def []=(value) : Nil`, so maybe it just depends on the implementation
<FromGitter> <pyrsmk> but yeah, it returns a value ^^
jrayhawk has quit [Quit: seuoia upgrades]
jrayhawk has joined #crystal-lang
Nik- has quit [Read error: Connection reset by peer]
<FromGitter> <oprypin:matrix.org> mfiano (https://matrix.to/#/@mjfiano:matrix.org): yes in release mode there's some inlining happening. don't know the details
<FromGitter> <oprypin:matrix.org> well i do know that only the llvm side of compilation can do the inlining
hightower2 has joined #crystal-lang
jrayhawk has quit [Quit: leaving]
jrayhawk has joined #crystal-lang
jrayhawk has quit [Quit: leaving]
jrayhawk has joined #crystal-lang
jrayhawk has quit [Quit: leaving]
jrayhawk has joined #crystal-lang
szutt has joined #crystal-lang
Nik- has joined #crystal-lang
szutt has quit [Quit: Client closed]
<FromGitter> <mjfiano:matrix.org> Thanks
<FromGitter> <mjfiano:matrix.org> How can I restrict an argument to be an integer from 0 to 3?
<FromGitter> <Blacksmoke16> `raise ArgumentError.new "Value must be between 0 and 3" if value.negative? || value > 3`
<FromGitter> <mjfiano:matrix.org> Ah so no type like Nim
<FromGitter> <Blacksmoke16> nope
<FromGitter> <mjfiano:matrix.org> `index: range[0..3]`
<hightower2> maybe even ... unless 0 <= value <= 3
<FromGitter> <mjfiano:matrix.org> Thanks
<FromGitter> <mjfiano:matrix.org> I think I need to go back to using a class instead of a struct
iskra has quit [Read error: Connection reset by peer]
<FromGitter> <Blacksmoke16> oh?
<FromGitter> <mjfiano:matrix.org> I am going to need an allocating and mutating API for each method like my existing Lisp library. The amount of copying done for intermediate matrix calculations is pretty insane.
iskra has joined #crystal-lang
<FromGitter> <mjfiano:matrix.org> Ok, I'm stuck
<FromGitter> <mjfiano:matrix.org> https://play.crystal-lang.org/#/r/bn43
<FromGitter> <Blacksmoke16> looks like just a limitation?
<FromGitter> <mjfiano:matrix.org> hmm?
<FromGitter> <Blacksmoke16> well first off `+(v, 20.0, into: v)` isn't valid syntax
<FromGitter> <Blacksmoke16> should be like `v + 20.0, into: v` no?
<FromGitter> <Blacksmoke16> as its an instance method o nself
<FromGitter> <Blacksmoke16> on self*
<FromGitter> <mjfiano:matrix.org> Ah got it https://play.crystal-lang.org/#/r/bn4n
<FromGitter> <mjfiano:matrix.org> wanted to see if they were all unambiguous
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <mjfiano:matrix.org> wait...
<FromGitter> <mjfiano:matrix.org> on my machine i get 1, 2, 3, 4 printed
<FromGitter> <mjfiano:matrix.org> 1,1,3,3 on carc
<FromGitter> <Blacksmoke16> carc is still using `1.0`, might have something to do with it
<FromGitter> <mjfiano:matrix.org> interesting. that is quite the bug fix
<FromGitter> <mjfiano:matrix.org> But seems you need `v.+` when using the named argument like in your example above
<FromGitter> <mjfiano:matrix.org> your example also fails to parse without that
<FromGitter> <Blacksmoke16> makes sense i guess
<FromGitter> <Blacksmoke16> maybe that can be improved, idk
<FromGitter> <Blacksmoke16> but when you do like `1 + 2` the compiler turns that into like `1.+(2)`
<FromGitter> <Blacksmoke16> as it's just a method call
<FromGitter> <mjfiano:matrix.org> i'll add it to my list of issues/feature requests to file
<FromGitter> <mjfiano:matrix.org> I see these both used in instance methods, which one is more idiomatic? `typeof(self).new`, `self.class.new`
<FromGitter> <Blacksmoke16> pretty sure they mean slightly diff things. `typeof` returns the compile time type, while `self.class` is the runtime type
<FromGitter> <Blacksmoke16> so might depend on exact context what they return
<FromGitter> <mjfiano:matrix.org> I see, thanks
<FromGitter> <mjfiano:matrix.org> would that be like `{{@type}}.new`?
<FromGitter> <Blacksmoke16> depends on exactly what you want i think
<FromGitter> <Blacksmoke16> like `self.class.new` would support child types when defined on a parent, but `{{@type}}` prob would return the type that it's called in
postmodern has quit [Remote host closed the connection]
<FromGitter> <mjfiano:matrix.org> Oh yeah I assumed that. I was wondering how `{{@type}}` is different from `typeof(self)`
<FromGitter> <mjfiano:matrix.org> i guess the latter is the function invocation of the literal
<FromGitter> <Blacksmoke16> actually from what i can tell they all seem equivalent
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/bn5t at least in this context
<FromGitter> <mjfiano:matrix.org> huh interesting
<FromGitter> <mjfiano:matrix.org> I'm experimenting with unrolling my element wise loops with a macro and generics
<FromGitter> <mjfiano:matrix.org> no idea if Crystal is powerful enough
Guest380 has joined #crystal-lang
Guest380 has quit [Client Quit]
<FromGitter> <Blacksmoke16> how would that work
<FromGitter> <mjfiano:matrix.org> generate ast nodes that call `[]=` instead of looping at runtime to do so?
<FromGitter> <Blacksmoke16> got an exmple?
<FromGitter> <mjfiano:matrix.org> not yet
<FromGitter> <Blacksmoke16> do you just mean replacing a like `4.times do` with 4 explicit `[]=` calls?
<FromGitter> <mjfiano:matrix.org> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60fee3e9e9aaeb7fbe21f7f8]
<FromGitter> <Blacksmoke16> i.e. instead of using the `each_with_index`?
<FromGitter> <mjfiano:matrix.org> I mean instead of calling each_with_index at runtime, just call all required `result[...]`, given a sizing type parameter and a known memory layout
<FromGitter> <Blacksmoke16> i will say using the method is equivilent to just doing `result[0] = {{op}}` etc
<FromGitter> <Blacksmoke16> as they're always inlined
<FromGitter> <mjfiano:matrix.org> the block is inlined, but there are several blocks through an iterator
<FromGitter> <Blacksmoke16> gotcha
<FromGitter> <mjfiano:matrix.org> This is bizarre
<FromGitter> <mjfiano:matrix.org> maybe a generics issue you were speaking of...
<FromGitter> <mjfiano:matrix.org> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60fee9ed36b0b97fa2cc3e0b]
<FromGitter> <mjfiano:matrix.org> this class method is defined in the vector class. min should not be a float
<FromGitter> <Blacksmoke16> got a min reproduction?
<FromGitter> <mjfiano:matrix.org> Sure one sec
<FromGitter> <mjfiano:matrix.org> https://play.crystal-lang.org/#/r/bn7d
<FromGitter> <mjfiano:matrix.org> I am probably too tired to notice an obvious problem
<FromGitter> <mjfiano:matrix.org> Will take a break in a minute :)
<FromGitter> <Blacksmoke16> i think the issue is it's using the overload above it
<FromGitter> <Blacksmoke16> which is passing in `0.0` and `1.0`
<FromGitter> <Blacksmoke16> because `min = self` isn't a type restriction, just a default value
<FromGitter> <mjfiano:matrix.org> Yes I just noticed as soon as you did
<FromGitter> <mjfiano:matrix.org> Thanks for the :duc
<FromGitter> <mjfiano:matrix.org> https://play.crystal-lang.org/#/r/bn7f
<FromGitter> <mjfiano:matrix.org> That one is, odd...
<FromGitter> <mjfiano:matrix.org> Oh another = typo
<FromGitter> <mjfiano:matrix.org> same thing though https://play.crystal-lang.org/#/r/bn7h
<FromGitter> <mjfiano:matrix.org> dunno what i am missing. guess it's break time...
<FromGitter> <Blacksmoke16> i mean the 2nd overload is being called
<FromGitter> <Blacksmoke16> which should then use the first overload
<FromGitter> <mjfiano:matrix.org> but the first isn't a listed choice of overloads available
<FromGitter> <mjfiano:matrix.org> This seems to be a bug in the compiler, but I'm not certain. It works if you remove the default values from the first overload
<FromGitter> <Blacksmoke16> let me try from master
<FromGitter> <mjfiano:matrix.org> i built from master 2 days ago
<FromGitter> <Blacksmoke16> yea same error
<FromGitter> <mjfiano:matrix.org> odd thing is it works without the default values on the first
<FromGitter> <Blacksmoke16> @HertzDevil would prob have an idea
<FromGitter> <mjfiano:matrix.org> Ok I'll take a break and see if he replies later
<FromGitter> <mjfiano:matrix.org> Thanks
<FromGitter> <mjfiano:matrix.org> @HertzDevil: Updated minimal example: https://play.crystal-lang.org/#/r/bn7m
<FromGitter> <alexherbo2> is there a way to do actions on properties with `from_yaml`?
<FromGitter> <alexherbo2> ```roots: ["config/environment.cr"] ⏎ extensions: [".cr"]``` [https://gitter.im/crystal-lang/crystal?at=60fef81a1a1db149e9e20317]
<FromGitter> <alexherbo2> I'd like to be able to do `from_yaml` to have my `roots`, `extensions`, `paths` and `global` sets.
<FromGitter> <Blacksmoke16> there's a method that executes after deserialization is done if that helps
<FromGitter> <Blacksmoke16> `after_initialize`
<FromGitter> <alexherbo2> when they are set do this: `@scopes << Scope::Root.new(value)`
<FromGitter> <alexherbo2> instead of doing logic like in a method: `if @roots ... @scopes << ...`
<FromGitter> <Blacksmoke16> not really no, would need to implement that logic yourself, but it could live in the `after_initialize` method
<FromGitter> <alexherbo2> @Blacksmoke16 do you have a link to the documentation?
<FromGitter> <alexherbo2> @Blacksmoke16 currently instead of a class from parsing the YAML I have done this:
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60fef9ad58232d5ab4e73ab9]
<FromGitter> <alexherbo2> to process the `scope.yaml` file
<FromGitter> <Blacksmoke16> idt there really is any
<FromGitter> <Blacksmoke16> it would just be like add this method to your type
<FromGitter> <Blacksmoke16> ```def after_initialize ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=60fef9fb58232d5ab4e73b6a]
<FromGitter> <Blacksmoke16> and it gets called after deserialization
<FromGitter> <alexherbo2> I wanted my file without a discriminator, not sure if it would be best
<FromGitter> <alexherbo2> @Blacksmoke16 how to "hide" my @scopes property to not be considered when doing from/to yaml?
<FromGitter> <Blacksmoke16> `@[YAML::Field(ignore: true)]`
<FromGitter> <alexherbo2> hm
<FromGitter> <alexherbo2> I'm not sure, but, instead of `after_initialize`, couldn't avoid logic if the json/yaml serializable use the setters instead of setting the properties directly?
<FromGitter> <Blacksmoke16> possibly, but idt there's a way to have it use the setters
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60fefc0b6ccf813819dbd79e]
<FromGitter> <alexherbo2> that way I can do `Scopes.from_yaml(File.open("scope.yml")).scopes` to get the list of scope instances
<FromGitter> <Blacksmoke16> i mean just add this within the after initialize method
<FromGitter> <Blacksmoke16> ```@scopes.each do |scope| ⏎ self.roots = scope ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=60fefcb036b0b97fa2cc6a0d]
<FromGitter> <alexherbo2> `@scopes` is empty no?
<FromGitter> <alexherbo2> it would be more: ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=60fefcf3f4d1dc69f3075336]
<FromGitter> <alexherbo2> ```if @roots ⏎ @scopes << Scope::Root.new(@roots) ⏎ end ⏎ ...``` [https://gitter.im/crystal-lang/crystal?at=60fefd183a178069da89c13b]
<FromGitter> <alexherbo2> as I would like to allow nilable (roots, extensions, etc. being optional in the yaml file)
<FromGitter> <Blacksmoke16> oops yea
<FromGitter> <alexherbo2> maybe there is a more elegant approach than creating a `Scopes` class
notzmv has quit [Ping timeout: 272 seconds]
<FromGitter> <Blacksmoke16> :shrug:
ua_ has quit [Ping timeout: 245 seconds]
ua_ has joined #crystal-lang
Nik- has quit [Quit: My Mac Mini has gone to sleep. ZZZzzz…]
notzmv has joined #crystal-lang
ur5us has joined #crystal-lang
iskra has quit [Ping timeout: 265 seconds]
iskra has joined #crystal-lang
<FromGitter> <jwaldrip> Question: Does 1.1 have precompiled binaries for apple silicon?
<FromGitter> <jwaldrip> Familiar with the split arch alternatives. But we need true m1 builds. So I will continue to wait.
<FromGitter> <jwaldrip> Or does this actually give me an m1 build of crystal?
<jhass[m]> it's a universal build, a single executable containing code for both architectures as far as I understood it
<FromGitter> <mjfiano:matrix.org> I still haven't been able to continue around this problem that might be a bug in Crystal.
<FromGitter> <mjfiano:matrix.org> I'm not sure if maybe I should file the bug report and come back to Crystal when it is more mature.
<FromGitter> <mjfiano:matrix.org> But I would like to confirm it's not my fault and actually is a bug before I end up doing that.
<riza> @mjfiano have you posted your code sample anywhere?
<FromGitter> <mjfiano:matrix.org> Yeah, @Blacksmoke16 was helping earlier today
<riza> I'd make a github issue -- if it's a bug and it's unreported that's the best way to get some real eyes on it.
<riza> I've run into issues doing operations "Size" generics like that as well, but have always just found a way around them
<FromGitter> <mjfiano:matrix.org> I just figured out the problem
<FromGitter> <Blacksmoke16> oh?
<riza> semantically it didn't make much difference to to me say Klass(T).new(4) instead of Klass(T,4).new
<FromGitter> <mjfiano:matrix.org> I'm setting the default value of the T-restricted arguments to be a Float64 value. The compiler is very confused about that, and it doesn't make sense anyway
<FromGitter> <mjfiano:matrix.org> I still think it's a bug, but one that makes sense now at least
<FromGitter> <mjfiano:matrix.org> and easily workaroundable
<FromGitter> <Blacksmoke16> but you were passing in `Float64` as the value of `T` tho?
<FromGitter> <mjfiano:matrix.org> I was for the instance being created, not for the method call
<FromGitter> <Blacksmoke16> so? `T` is inherited from the generic
<FromGitter> <mjfiano:matrix.org> Maybe the fact that there is also an overload for min and max = self, means that it could be recursive I think
<FromGitter> <mjfiano:matrix.org> Infact the issue goes away if the self versions are removed, even though they are not in the call graph anywhere
<FromGitter> <mjfiano:matrix.org> Seems like some elusive compiler bug that probably deserves me fooling around to come up with a more minimal test case, since there are multiple ways that contribute to the problem in the current example
<FromGitter> <mjfiano:matrix.org> Before reporting it anyway
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/bnci looks sufficient enough for a bug report
<FromGitter> <Blacksmoke16> might be related to https://github.com/crystal-lang/crystal/issues/10231, let me see if it reproduces with https://github.com/crystal-lang/crystal/pull/10711
<FromGitter> <mjfiano:matrix.org> Oh nice reduction
<FromGitter> <mjfiano:matrix.org> So not due to generics or multiple same-arity overloads
<FromGitter> <asterite> Note that both are called run, so not a bug
<FromGitter> <Blacksmoke16> why should that matter? they have diff signatures so should be considered overloads no?
<FromGitter> <mjfiano:matrix.org> Can you elaborate on that?
<FromGitter> <Blacksmoke16> oh
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/bncm typo got me :(
<FromGitter> <Blacksmoke16> i used `new` in the first overload
<FromGitter> <mjfiano:matrix.org> ha
<FromGitter> <Blacksmoke16> so prob just have to workaround it until if/when that is merged/released
<FromGitter> <mjfiano:matrix.org> reading the referenced overload order document
<FromGitter> <asterite> The call to run hits the first overload
<FromGitter> <asterite> Yeah, that :-)
<FromGitter> <mjfiano:matrix.org> @asterite: See https://play.crystal-lang.org/#/r/bncn
<FromGitter> <mjfiano:matrix.org> It's not immediately clear to me how anything in that draft should fix this particular example, but hey if it does, cool...I'll work around the problem until it is finalized.
<FromGitter> <asterite> Ah, I see. Sorry, too complex to understand on a Phone, but it seems there's a PR that fixes ir so it's probably a bug
<FromGitter> <mjfiano:matrix.org> Are Carcin examples permanent links? I'm guessing not with such a small id
<FromGitter> <Blacksmoke16> long enough
<FromGitter> <mjfiano:matrix.org> Nice detective work finding that PR
<FromGitter> <Blacksmoke16> it helps when you read every issue/pr 🙃
<FromGitter> <mjfiano:matrix.org> Haha. Well I can easily work around this, as there is no reason I absolutely need a "type" type parameter for these codes, only size.
<FromGitter> <mjfiano:matrix.org> Thanks
<FromGitter> <Blacksmoke16> np
<FromGitter> <mjfiano:matrix.org> and to confirm, this issue also goes away if the `T` type parameter goes away and uses concrete types in place, which is why that PR fix doesn't make a whole lot of sense to me
hightower2 has quit [Ping timeout: 276 seconds]
notzmv has quit [Ping timeout: 240 seconds]