New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Confusing behavior with structs and closures #40
Comments
This also brings up the question: how are closures stored on a struct? In Rust, one would likely |
This is an interesting and useful pattern. We will make sure we have an example of how to do this in Mojo ASAP |
The basic idea is that your
which should allow you to write
|
Thanks for looking into it! That makes sense. I wonder if there could be a |
Why not allow r-values to be mutated in this way? Is it not possible to come up with a semantics for this? Oh wait, I see: the original definition of I don't understand why
|
This is a lot like scala's See "Copying" for more details here: https://docs.scala-lang.org/tour/case-classes.html |
I was trying to trigger moves rather than copies in this case, but I'm not sure that's possible right now |
@lsh there's a typo in your code fn set_y(self&, y: fn(F32) -> F32):
self.x = y |
Closing this for now. |
Hi, last night I was playing around in the notebook and ran into a few interesting sharp edges.
The struct I had in mind was a D3 inspired "line builder", where it takes an x and y function, and some points, and returns the transformed points with that function.
The builder was defined as follows:
The goal was to follow something like the builder idiom. For the following here is some book keeping:
Originally I wanted to write
However that errors with:
So I wrote it out as:
Here is the second sharp edge
(see #39 about the
e.__len__()
)outputs:
In other words,
evaluate
is still using the originalself.x
, not the currentself.x
.The text was updated successfully, but these errors were encountered: