ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
ur5us has quit [Ping timeout: 250 seconds]
<FromGitter> <> 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> <> 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> <> 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> <> 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> <> You mean so `matrix[2, 3]` is possible?
<FromGitter> <Blacksmoke16> Yes
<FromGitter> <> That's what I'll try first then. Thanks
<FromGitter> <> Found this, and, I understand very little of it
<FromGitter> <> 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> <> I get that. I don't know why not just use an array
<FromGitter> <> or static array, rather than this delegating
<FromGitter> <Blacksmoke16> Performance probably?
<FromGitter> <> Ok, is `[]=` assignment a statement or expression?
<FromGitter> <> I don't see a return value in the signature for the overloads in the API anyway
Nik- has joined #crystal-lang
<FromGitter> <naqvis> `[]=` is an expression, it returns the value
<FromGitter> <naqvis>
postmodern has joined #crystal-lang
<postmodern> does crystal have an annotation that's the equivalent of __attribute__((__packed__))?
<FromGitter> <naqvis> `Packed`?
<FromGitter> <> Thanks
Welog has quit [*.net *.split]
Welog has joined #crystal-lang
<FromGitter> <> 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> > `[]=` 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> <> mfiano ( yes in release mode there's some inlining happening. don't know the details
<FromGitter> <> 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> <> Thanks
<FromGitter> <> How can I restrict an argument to be an integer from 0 to 3?
<FromGitter> <Blacksmoke16> `raise "Value must be between 0 and 3" if value.negative? || value > 3`
<FromGitter> <> Ah so no type like Nim
<FromGitter> <Blacksmoke16> nope
<FromGitter> <> `index: range[0..3]`
<hightower2> maybe even ... unless 0 <= value <= 3
<FromGitter> <> Thanks
<FromGitter> <> 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> <> 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> <> Ok, I'm stuck
<FromGitter> <>
<FromGitter> <Blacksmoke16> looks like just a limitation?
<FromGitter> <> 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> <> Ah got it
<FromGitter> <> wanted to see if they were all unambiguous
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <> wait...
<FromGitter> <> on my machine i get 1, 2, 3, 4 printed
<FromGitter> <> 1,1,3,3 on carc
<FromGitter> <Blacksmoke16> carc is still using `1.0`, might have something to do with it
<FromGitter> <> interesting. that is quite the bug fix
<FromGitter> <> But seems you need `v.+` when using the named argument like in your example above
<FromGitter> <> 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> <> i'll add it to my list of issues/feature requests to file
<FromGitter> <> I see these both used in instance methods, which one is more idiomatic? `typeof(self).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> <> I see, thanks
<FromGitter> <> would that be like `{{@type}}.new`?
<FromGitter> <Blacksmoke16> depends on exactly what you want i think
<FromGitter> <Blacksmoke16> like `` 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> <> Oh yeah I assumed that. I was wondering how `{{@type}}` is different from `typeof(self)`
<FromGitter> <> 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> at least in this context
<FromGitter> <> huh interesting
<FromGitter> <> I'm experimenting with unrolling my element wise loops with a macro and generics
<FromGitter> <> no idea if Crystal is powerful enough
Guest380 has joined #crystal-lang
Guest380 has quit [Client Quit]
<FromGitter> <Blacksmoke16> how would that work
<FromGitter> <> generate ast nodes that call `[]=` instead of looping at runtime to do so?
<FromGitter> <Blacksmoke16> got an exmple?
<FromGitter> <> not yet
<FromGitter> <Blacksmoke16> do you just mean replacing a like `4.times do` with 4 explicit `[]=` calls?
<FromGitter> <> ```code paste, see link``` []
<FromGitter> <Blacksmoke16> i.e. instead of using the `each_with_index`?
<FromGitter> <> 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> <> the block is inlined, but there are several blocks through an iterator
<FromGitter> <Blacksmoke16> gotcha
<FromGitter> <> This is bizarre
<FromGitter> <> maybe a generics issue you were speaking of...
<FromGitter> <> ```code paste, see link``` []
<FromGitter> <> this class method is defined in the vector class. min should not be a float
<FromGitter> <Blacksmoke16> got a min reproduction?
<FromGitter> <> Sure one sec
<FromGitter> <>
<FromGitter> <> I am probably too tired to notice an obvious problem
<FromGitter> <> 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> <> Yes I just noticed as soon as you did
<FromGitter> <> Thanks for the :duc
<FromGitter> <>
<FromGitter> <> That one is, odd...
<FromGitter> <> Oh another = typo
<FromGitter> <> same thing though
<FromGitter> <> 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> <> but the first isn't a listed choice of overloads available
<FromGitter> <> 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> <> i built from master 2 days ago
<FromGitter> <Blacksmoke16> yea same error
<FromGitter> <> odd thing is it works without the default values on the first
<FromGitter> <Blacksmoke16> @HertzDevil would prob have an idea
<FromGitter> <> Ok I'll take a break and see if he replies later
<FromGitter> <> Thanks
<FromGitter> <> @HertzDevil: Updated minimal example:
<FromGitter> <alexherbo2> is there a way to do actions on properties with `from_yaml`?
<FromGitter> <alexherbo2> ```roots: ["config/"] ⏎ extensions: [".cr"]``` []
<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 <<`
<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``` []
<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``` []
<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``` []
<FromGitter> <alexherbo2> that way I can do `Scopes.from_yaml("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``` []
<FromGitter> <alexherbo2> `@scopes` is empty no?
<FromGitter> <alexherbo2> it would be more: ⏎ ⏎ `````` []
<FromGitter> <alexherbo2> ```if @roots ⏎ @scopes << ⏎ end ⏎ ...``` []
<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> <> I still haven't been able to continue around this problem that might be a bug in Crystal.
<FromGitter> <> I'm not sure if maybe I should file the bug report and come back to Crystal when it is more mature.
<FromGitter> <> 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> <> 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> <> 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> <> 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> <> I still think it's a bug, but one that makes sense now at least
<FromGitter> <> and easily workaroundable
<FromGitter> <Blacksmoke16> but you were passing in `Float64` as the value of `T` tho?
<FromGitter> <> I was for the instance being created, not for the method call
<FromGitter> <Blacksmoke16> so? `T` is inherited from the generic
<FromGitter> <> Maybe the fact that there is also an overload for min and max = self, means that it could be recursive I think
<FromGitter> <> Infact the issue goes away if the self versions are removed, even though they are not in the call graph anywhere
<FromGitter> <> 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> <> Before reporting it anyway
<FromGitter> <Blacksmoke16> looks sufficient enough for a bug report
<FromGitter> <Blacksmoke16> might be related to, let me see if it reproduces with
<FromGitter> <> Oh nice reduction
<FromGitter> <> 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> <> Can you elaborate on that?
<FromGitter> <Blacksmoke16> oh
<FromGitter> <Blacksmoke16> typo got me :(
<FromGitter> <Blacksmoke16> i used `new` in the first overload
<FromGitter> <> ha
<FromGitter> <Blacksmoke16> so prob just have to workaround it until if/when that is merged/released
<FromGitter> <> reading the referenced overload order document
<FromGitter> <asterite> The call to run hits the first overload
<FromGitter> <asterite> Yeah, that :-)
<FromGitter> <> @asterite: See
<FromGitter> <> 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> <> Are Carcin examples permanent links? I'm guessing not with such a small id
<FromGitter> <Blacksmoke16> long enough
<FromGitter> <> Nice detective work finding that PR
<FromGitter> <Blacksmoke16> it helps when you read every issue/pr 🙃
<FromGitter> <> 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> <> Thanks
<FromGitter> <Blacksmoke16> np
<FromGitter> <> 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]