<hightower2>
What would it entail to make crystal and crystal i share variables, when crystal i would be running inside a crystal program like an interpreter for script files loaded in runtime? And would this, as a side effect, also enable having shared libs with crystal?
<hightower2>
Is it hard, or not doable given current architecture?
<straight-shoota>
You mean using interpreted Crystal as a kind of scripting engine from a Crystal program?
<straight-shoota>
I'm not sure how difficult it would be to share data with the embedded interpreter context.
<straight-shoota>
But should be doable
<straight-shoota>
I don't see any relation to shared libraries, though. The hassle with shared libs is Crystal's stdlib runtime.
<hightower2>
aha ok, thanks. I thought the issues were (also) with gc
<FromGitter>
<mjfiano:matrix.org> What does it mean to have an instance method at the module level, if the module isn't a partial type? Can this method be invoked somehow?
<FromGitter>
<Blacksmoke16> this goes back to `include` and `extend`
<FromGitter>
<mjfiano:matrix.org> Right, so it's only usable when the type is completed with one of those?
<FromGitter>
<mjfiano:matrix.org> and not from the partial type
<FromGitter>
<Blacksmoke16> yea, at that point its a mixin not meant to be used on its own
<FromGitter>
<Blacksmoke16> you *can* do `extend self` that allows it to be a mixin, but still call methods on the module itself
<riza>
is there an obvious way that I can specify an argument type be "any hash"?
<FromGitter>
<Blacksmoke16> `arg : Hash`
<riza>
:|
<riza>
it's so easy!
<FromGitter>
<Blacksmoke16> and just to clarify this only would work for an argument or return type restriction
<riza>
well I've been overthinking that problem for a week
<FromGitter>
<Blacksmoke16> you cant type an ivar to `Hash`
<riza>
yeah, for sure
<FromGitter>
<Blacksmoke16> 👍
notzmv has quit [Ping timeout: 258 seconds]
notzmv has joined #crystal-lang
hightower2 has quit [Ping timeout: 258 seconds]
szutt has quit [Quit: Client closed]
szutt has joined #crystal-lang
avane has quit [Quit: o/]
avane has joined #crystal-lang
szutt has quit [Quit: Client closed]
hexreel has quit [Quit: nyaa~]
<FromGitter>
<rymiel:rymiel.space> Decided to poke around with the compiler source and wow i've never experienced having to run the compiler specs... takes like 30 minutes
<FromGitter>
<asterite> yeah... we kept adding more and more specs and it became like that. In general you never need to run them locally, we usually run specs for things we change, and then let CI run all of them
<FromGitter>
<rymiel:rymiel.space> i just don't know the build system well enough to run only the specs i changed and i'm waiting for the CI to finish before i make a pull request because i already had a few dumb mistakes...
<FromGitter>
<mjfiano:matrix.org> I wonder if non-dependent specs, could be run in parallel
<FromGitter>
<rymiel:rymiel.space> what a lifesaver..
<FromGitter>
<mjfiano:matrix.org> I will say its better than over in Nim. Just a few tests takes forever to compile, not to mention run, and outputs in tens of thousands of lines of C code iirc
<FromGitter>
<rymiel:rymiel.space> omg it even tells me the command to run a failed spec for each failed spec... i'm just blind
<FromGitter>
<Blacksmoke16> 😅
<FromGitter>
<mjfiano:matrix.org> Is there a decent way to call a method with arguments being the elements of a (small) StaticArray? I'm coming up with hacky stuff without diving into macros
<FromGitter>
<Blacksmoke16> if you used a tuple you could `*tuple`
<FromGitter>
<mjfiano:matrix.org> Sort of like splatting, but without a tuple or intermediary sequence
<FromGitter>
<Blacksmoke16> `arr[0], arr[1]`
<FromGitter>
<mjfiano:matrix.org> Yeah I thought I could do function application from the result of a functional map or something
<FromGitter>
<mjfiano:matrix.org> Oh well
<FromGitter>
<mjfiano:matrix.org> are tuples stack objects or are they collected?
<FromGitter>
<Blacksmoke16> stack
<FromGitter>
<Blacksmoke16> ofc if you used a struct you could just pass the struct thru and use its getters
<FromGitter>
<mjfiano:matrix.org> i would assume a tuple is fixed in length then
<FromGitter>
<mjfiano:matrix.org> What are the performance characteristics compared to a StaticArray?
<FromGitter>
<Blacksmoke16> not sure, probably similar?
<FromGitter>
<mjfiano:matrix.org> Yes, I am there. That page is nearly empty :)
<FromGitter>
<Blacksmoke16> API docs have a bit more info
<FromGitter>
<mjfiano:matrix.org> I see. Main difference I see is SA is a homogeneous container, which might be more contiguous/better for cache
<straight-shoota>
@mjfiano What exactly do you want to do?
<FromGitter>
<mjfiano:matrix.org> straight-shoota: I'm pretty new, just experimenting mostly. But right now I have Vector (math) types in 2-4 dimensions, and currently using separate float ivars. Would like to back their storage in some container, so the method logic can map over them and reduce code by being generic for all 3 types.
sagax has joined #crystal-lang
<FromGitter>
<mjfiano:matrix.org> Most operations are element-wise, so could reduce quite a bit of code by iterating over a generic container of some size to produce results for a given operation/vector type.
<FromGitter>
<mjfiano:matrix.org> THat is the idea anyway. Not sure where to start yet :)
<FromGitter>
<Blacksmoke16> fwiw its fairly easy to make a struct that is iterable
<FromGitter>
<mjfiano:matrix.org> Interesting
<FromGitter>
<Blacksmoke16> that you could use with `.each` or `.map `etc
<FromGitter>
<Blacksmoke16> makes it super easy to do like `arry.sort!`
<FromGitter>
<mjfiano:matrix.org> I am beginning to see how Crystal is very extensible with these mixin modules
<FromGitter>
<mjfiano:matrix.org> It seems I have to study generic type parameters more because the compiler can't infer the type parameter and I'm not sure what to specify.
<FromGitter>
<mjfiano:matrix.org> Heh, you're right. That *is* easy. I do have one complaint about the compiler here though.
<FromGitter>
<Blacksmoke16> oh?
<FromGitter>
<mjfiano:matrix.org> When i `include Indexable(T)`, the compiler was smart enough to tell me I didn't implement `unsafe_fetch`. After I implemented that and tried using it, the compiler ended up overflowing the stack due to recursing infinitely. It wasn't until I implemented `size` that it worked. It makes me wonder why it just blew the stack instead of complaining that I didn't implement `size`.
<FromGitter>
<Blacksmoke16> hm
<FromGitter>
<Blacksmoke16> got a small example of that behavior? I have a theory
<straight-shoota>
The problem is that `Indexable#size` is actually implemented by it's ancestor `Enumerable#size`
<FromGitter>
<mjfiano:matrix.org> I will make one on play
<FromGitter>
<Blacksmoke16> yea that was my guess ^ which its implementation just iterates the whole thing to figure out
<FromGitter>
<rymiel:rymiel.space> wouldn't you unsafe_fetch here return a nilable value
<FromGitter>
<rymiel:rymiel.space> because there's no else in the case
<FromGitter>
<mjfiano:matrix.org> Hmm how do I fix it?
<FromGitter>
<rymiel:rymiel.space> have an else which throws an exception?
<FromGitter>
<rymiel:rymiel.space> speaking of, is there no way to view the `--error-trace` on carc.in?
<FromGitter>
<Blacksmoke16> prob raise if index isnt 0 or 1 then just do like `idx.zero? ? @x : @y`
<FromGitter>
<mjfiano:matrix.org> Yeah for this type. Also have 3d (x y z), and 4d (x y z w) types
<FromGitter>
<Blacksmoke16> case + else with exception prob be the way to go then
<riza>
how does log.context get "inherited" when a fiber is spawned? I had assumed there was something in spawn/Fiber that called a .dup or .clone on the ivars on Fiber at .new time but I don't see it
<FromGitter>
<Blacksmoke16> does it inherit context?
hexreel has joined #crystal-lang
<FromGitter>
<mjfiano:matrix.org> Spent a while trying to figure out why Number#negative? was erroring out. Looks like I am still on 1.0.0. Also looks like I need a break :/
<FromGitter>
<Blacksmoke16> hey that was my feature :P
<riza>
this api is kind of confusing, because you call #set on the context but if you want to render all the things you've set you have to call context.metadata
<FromGitter>
<Blacksmoke16> context represents global fiber data, while metadata represents data on a specific log message
ur5us has joined #crystal-lang
<FromGitter>
<mjfiano:matrix.org> ```code paste, see link``` ⏎ ⏎ @Blacksmoke16 Curious if this is a bug, but the latter version results in a compiler error when using some Indexable methods: `Error: no overload matches 'Array(Float64)#<<' with type (Float64 | Nil)` [https://gitter.im/crystal-lang/crystal?at=60f7383472c37b6f4564d480]
<FromGitter>
<Blacksmoke16> unsafe_fetch can return `nil`
<FromGitter>
<mjfiano:matrix.org> I mean it is still exhaustive i would think
<FromGitter>
<Blacksmoke16> because thats the default return value of a case w/o an else
<FromGitter>
<mjfiano:matrix.org> I would think it could either return x, y, or NoReturn
<FromGitter>
<Blacksmoke16> which is why you need to put it in the else if you're using case
<FromGitter>
<mjfiano:matrix.org> the raise catches not a 0 or 1, doesn't it?
<FromGitter>
<Blacksmoke16> :shrug: guess it's not that smart?
<FromGitter>
<mjfiano:matrix.org> Which has the special NoReturn type
<FromGitter>
<mjfiano:matrix.org> What class does #[]= come from?
<FromGitter>
<mjfiano:matrix.org> I would like to include the 5 overloads for `#[]=` into my Indexable struct type. Any ideas?
deavmi has quit [Read error: Connection reset by peer]
<FromGitter>
<mjfiano:matrix.org> It modifies my struct in place
<riza>
sure, whats your end goal with this which each_with_index doesn't achieve?
<FromGitter>
<mjfiano:matrix.org> each_with_index is what I came up with, and it works. I was only wondering if there was something more concise/more idiomatic for this use-case :)
<FromGitter>
<mjfiano:matrix.org> I've only played with a tiny bit of the API, and no 3rd party libraries or anything yet
<riza>
dealing with the indices manually doesn't feel idiomatic to me, but it's not at all wrong
<riza>
(I would run a .map so I didn't need to deal with the indices)
<riza>
`self.map {|e| e.round}`
<FromGitter>
<mjfiano:matrix.org> that will produce an array, right?
<riza>
Well, #map isn't available on an Indexable so it wouldn't compile
<riza>
what led you to use an Indexable instead of just an Array?
<FromGitter>
<mjfiano:matrix.org> array is a generic class, not a module. Blacksmoke16 recommended me to `include Indexable` on my struct so that I can implement the abstract methods to be able to index/iterate over it
<FromGitter>
<mjfiano:matrix.org> Which I have done and therefor get Enumerable and Iterable too
<FromGitter>
<mjfiano:matrix.org> I'm not sure what you mean by #map not being available. It is inherited in Indexable from Enumerable
<riza>
oh I see, this is an exercise in implementing the modules
<FromGitter>
<mjfiano:matrix.org> I mean what I have works. The map suggestion is only half of the work required.
<riza>
oh sure enough it is. I thought Indexable only included Iterable.
<FromGitter>
<mjfiano:matrix.org> This is more than constructing a sequence of values. It is modifying the input sequence in the process, so does not need an intermediary sequence.
<FromGitter>
<mjfiano:matrix.org> That's why I chose each_with_index. Maybe this is not idiomatic, but I don't see another way to do it efficiently
<riza>
you're probably right about that
<riza>
a bunch of the crystal community sheds a lot of sweat about saving bits of memory... I try to avoid dealing with memory concerns
<riza>
it's not wrong by any means, I'd just rather solve problems that aren't already more-or-less solved for me by the language
<riza>
if that weren't the case, I'd write a lot more C
<FromGitter>
<mjfiano:matrix.org> Usually a good decision, at least until profiling says you shouldn't
<riza>
yep, exactly
<FromGitter>
<mjfiano:matrix.org> Ok thanks for the help :)
<riza>
thankfully in Crystal, it's pretty uncommon to need to care about an extra loop or copy of the data
<FromGitter>
<mjfiano:matrix.org> Speaking of the Crystal community. It is small, but probably the most helpful for a newcomer than any of the few dozen languages I've used.
<FromGitter>
<mjfiano:matrix.org> Very friendly crowd around here
<riza>
well I think we all count that as a win, for everyone. glad you found it welcoming, it often is exactly that
<FromGitter>
<mjfiano:matrix.org> I left Nim, which is a similar language, due to a very toxic community (among other reasons, but mostly that)
<FromGitter>
<mjfiano:matrix.org> It was sad, but I am liking everything about Crystal much better anyway
<riza>
Nim's a pretty neat language. It's difficult to keep a community from getting toxic or divided as it grows.
<riza>
@mjfiano what kind of programming do you do which you were using Nim for and are now evaluating crystal?
<FromGitter>
<mjfiano:matrix.org> riza: Mostly 3D games, or 3D math visualizations/simulations that require soft real time performance.
<riza>
nice, sounds fun! Anything published? I believe there have been people working on 3D engines at some point, but I don't know if there are any active projects anymore.
<FromGitter>
<mjfiano:matrix.org> I mostly do so in Common Lisp, which gives me the performance of C with the productivity of Python, and the ability to extend the language with macros. But, having used it for nearly 20 years exclusively, I have recently started looking for other languages, primarily to learn all the different ideas there are out there.
<FromGitter>
<mjfiano:matrix.org> I'm a researcher mostly, so just like to implement cool graphics techniques in academic papers :)
<FromGitter>
<mjfiano:matrix.org> Haven't made much of anything I would call an application, but I would like to one day.
<riza>
I can't imagine being productive in a Lisp... I always have to sit and stare at the screen for 3 hours before typing a line. But it's a neat language, and I imagine if I spent the time on it maybe that 3 hours would shrink a bit...
<FromGitter>
<mjfiano:matrix.org> I guess you have to have a good teacher/learning resource. I switched to Common Lisp from Python and was more productive after a week, which says a lot I think.
<riza>
The thing that slows me down about Crystal is the lack of a REPL. I spent years in the Ruby REPL and the lack of instantenous feedback makes the development process feel very slow to me.
<riza>
I wonder what the performance benchmarks of common lisp against crystal are
<riza>
maybe you wouldn't need to think about performance anymore!
<FromGitter>
<mjfiano:matrix.org> I hear you there. Lisp is very interactive, with many more tools than the REPL, so this is very new to me.
<FromGitter>
<mjfiano:matrix.org> Curious, do you think reading a book about Ruby would help me to learn Crystal better, or would I just confuse myself even more?
<FromGitter>
<mjfiano:matrix.org> I know absolutely zero Ruby, but been using Crystal for about a week and loving it so far.
<riza>
there's just enough divergence between the ecosystems that I wouldn't recommend it
<riza>
just stick with the reference and the api docs
<FromGitter>
<wyhaines> @riza, @asterite demo'd a instant feedback REPL for the Crystal Conference 1.0 a couple weeks ago.
<riza>
from an algorithms perspective, there are probably more reference implementations on the internet in ruby
<riza>
neat! have a link? I had a ticket but couldn't go at the last minute
<FromGitter>
<wyhaines> The talks aren't published yet. As for the code....I don't know if he has committed it to a branch in the repo yet, or not.
<FromGitter>
<wyhaines> But it's pretty slick.
<FromGitter>
<mjfiano:matrix.org> Is this the new `crystal i` PR?
<FromGitter>
<wyhaines> Yeah
<FromGitter>
<mjfiano:matrix.org> That looked interesting, but will take some time to iron out for sure. I really like how Crystal is managed and coming together.
<FromGitter>
<mjfiano:matrix.org> If I'm being honest, I'll share the major reason besides the toxic community that I left Nim, and I'm not seeing it here.
<FromGitter>
<mjfiano:matrix.org> The project seemed like an experimental sandbox of the lead developer, pushing out new features that didn't need to exist, and before testing them, making the compiler very complex and fragile. There's like 7 garbage collector choices, and a bunch of other features that makes it feel more like C++ than a well thought out language.
<FromGitter>
<mjfiano:matrix.org> I need some help with `blocks`. Not sure if what I want is possible.
<FromGitter>
<mjfiano:matrix.org> I'm trying not to get into macros at this point, so ignoring them. I have a bunch of methods that all repeat a lot of code. Here's 2 of them: ⏎ ⏎ ``` def round ⏎ element_wise { round } ⏎ end``` ⏎ ⏎ or something or other. [https://gitter.im/crystal-lang/crystal?at=60f7605bf4d1dc69f3f721f1]
<FromGitter>
<mjfiano:matrix.org> Is this even possible or should I abort now? :)