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

Example implementation of variables #124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Epitrochoid
Copy link

Implemented a quick spike of one of the ideas from issue #120. This is a pretty limited example since it only supports using a setting as a variable in a Set call. set grid/color = &background or similar works with these changes.

Is this a direction worth pursuing? To be useful for #120 it would in the very least need to cover referencing a setting's value in any command (allowing selection movement to be based on grid size). Adding code to each and every command doesn't seem tenable, but I'm fairly sure that mapping over the cmd argument in fn command (session.rs) and resolving any Value::vars would be doable.

Additionally I didn't tackle tuple destructuring support here. I'm thinking the easiest solution would be to allow tuple values to access by index as &grid/spacing.0 or possibly &grid/spacing.first.

@cloudhead
Copy link
Owner

Yeah that's a good start!

To generalize it so it can be used anywhere I guess you would define a value() parser that resolves variables into primitive types. Another approach would be to parse everything first and then evaluate variables to their underlying values, ie. a 2-step process.

@cloudhead
Copy link
Owner

Actually that would only work for "static" variables ... variables that change over the course of the program will need to be treated differently, and for doing something like selection/move &grid.x the variable needs to be preserved and looked up only at the time when the command is executed.

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

Successfully merging this pull request may close these issues.

None yet

2 participants