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
Feature request: passing parameters by reference #4258
Comments
Sorry, I have no idea what you are asking for. If it's about making values mutable, that's unlikely to happen. The are steps into the direction of making data structures available to user code (#3087). |
I started to think about a return-by-reference scheme, where a module could return a value by assignment to a specially-marked argument, but the current order of execution would make that impossible. All assignments happen before all module invocations, and so an assignment cannot depend on a module invocation. In many cases the best way to achieve this goal with OpenSCAD is to make use of its "child" mechanism. The "house" module would accept a "chimney" child, and would position it appropriately.
|
Ok, closing this as there's no repsonse. I'm open to discussions about this, but we are not going to have this ticket open with the questions hanging in the air. |
I wrote some code to allow rotation of a point around a center, using 3 angles of rotation: xy, xz and yz.
|
Wouldn't this be a function that accepts three 3-vectors (point to transform, rotation center, rotation angles) and returns one 3-vector (transformed point)? This sounds like it's precisely BOSL2's rot() function function, with a "cp" specified. But if you'd like a how-to, this isn't the right place. Take it to the mailing list. |
I'm a noob, Jordan. I have no idea how to write a function that returns a vector. After all, a function is a one-line formula here, unlike C. If I cannot fully write all 3 vector formulas in the same line, it can't be done. And I don't know about that mailing list. |
Functions can return any OpenSCAD type.
OpenSCAD has vector arithmetic as a native feature and so the natural way to solve problems like this is to construct appropriate transformation matrixes for each step and multiply them together, then multiply by the point to be transformed. For more, join the mailing list (openscad.org -> community -> mailing list) or drop me a note at openscad (at) jordan.maileater.net. |
Also functions don't have to be one line. You can use |
How ? Can you give an example ? I see it doesn't have a procedural body ending with a "return", but it's just an equal... |
|
Oh, that's something. I didn't even know you can apply a for cycle inside the assignment of an array... |
That's list comprehensions. But again, a github issue isn't really a good place to discuss this. I'm happy to (and many other people are happy to) give hints, advice, and instructions, but here isn't the right place. |
I know this gets shut down all the time, but coding around that is abnormal.
This feature is not an extra that structured languages have, it's part of what makes them functional.
Imagine you design something really big, and you need to expose anchor point coordinates for every sub-structure you draw,
so that you have a point on which to attach other ones and so on.
This can only be achieved with multiplicated code, by coding functions that return anchor data.
Suppose I have an "object" that creates a parametrized building, and then I want to add a chimney in a certain position.
The functions that get to the anchor points somewhere on the roof that can be used for adding the chimney, will contain all of them the same formulas for creating most of the building, just to get to an output relating to a point on the roof.
An elegant, yet abnormal solution, would be to have an array exposed in documentation, which the user creates in the code, and then an order of calling that is, functions have to be called in this order, assigned returns to these positions in the array so that everything has a one time call. This would simulate a full construction of an object along its public properties.
All of this would be easy peasy with a module that returns whatever it needs to return by reference. One time coding.
The text was updated successfully, but these errors were encountered: