Skip to content
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

Capture variables in expressions #12

Open
serguei-k opened this issue Sep 23, 2018 · 0 comments
Open

Capture variables in expressions #12

serguei-k opened this issue Sep 23, 2018 · 0 comments

Comments

@serguei-k
Copy link
Owner

serguei-k commented Sep 23, 2018

It would be great to capture parts of an expression as a variable that could be reused inline.

Here is a motivating example:

# get plane normal
normal = eval_expression('axis(plane.matrix, 1)', 'proj')

# project vector to plane
eval_expression('src.translate - ({normal} * dot(src.translate, {normal}))'.format(normal=normal), 'proj')

The normal gets used twice in expression, therefore it needs to be evaluated separately if it is to be reused. What if we could do something like this instead:

eval_expression('src.translate - (normal * dot(src.translate, axis(plane.matrix, 1)->normal))', 'proj')

Exact syntax is TBD.
One thing to consider is that capture would need to happen on the first use of the expression segment as per operation order.

Alternative proposal is to detect duplicate sections by comparing the AST nodes and reuse output internally, so you would still write:

eval_expression('src.translate - (axis(plane.matrix, 1) * dot(src.translate, axis(plane.matrix, 1)))', 'proj')

Feedback welcomed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant