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

Add form to get loop iteration counter #306

Open
EvanKirshenbaum opened this issue Jan 30, 2024 · 0 comments
Open

Add form to get loop iteration counter #306

EvanKirshenbaum opened this issue Jan 30, 2024 · 0 comments
Labels
3 medium Issue of medium importance in: DML issues related to the macro language is: feature Issue proposes a new feature

Comments

@EvanKirshenbaum
Copy link

Mike needed to do a loop that was essentially

repeat 10 times {​
    dispense_and_walk_dna(well#4);
}

but he wanted to print out the iteration number, so I had to tell him to do it as

repeat with int iter = 1 to 10 {​
    print "Dispensing DNA drop "+iter+".";
    dispense_and_walk_dna(well#4);
}

It's really annoying that you have to declare a special variable just to hold the iteration count, and it would be even uglier if there were some other loop control, because then you'd need to manage the counter yourself, e.g.,

int iter = 0;
repeat for 10 minutes {​
    iter = iter+1;
    print "Dispensing DNA drop "+iter+".";
    dispense_and_walk_dna(well#4);
}

and you'd probably want to enclose the whole thing in braces so that you didn't pollute the outside namespace.

This is ugly. What you want to do is something more like

repeat 10 times {​
    print "Dispensing DNA drop "+loop iteration+".";
    dispense_and_walk_dna(well#4);
}

where the looping mechanism keeps track of the counter for you and there's a special form that retrieves it. This shouldn't be difficult to implement.

Some considerations:

  • This probably can't be done simply as a special variable, as we'll want to be able to note an error if this is used in a context that isn't statically inside a loop. This will require treating it the way we treat exit statements, checking self.control_stack.in_loop.
  • Since we have named loops, it would be nice to have the ability to grab the iteration counter for loops that aren't the nearest one. I'm not sure what the syntax would be, but the implementation can probably be straightforwardly reading a variable whose name incorporates the loop name, e.g., **LOOP_outer_ITERATION**.
  • It's probably not worth it, but if we ever add an indication of external names referenced by a block, it would be a good idea for a loop to not bother creating and updating its counter if its body doesn't refer to it.
Migrated from internal repository. Originally created by @EvanKirshenbaum on Oct 02, 2023 at 5:02 PM PDT.
@EvanKirshenbaum EvanKirshenbaum added 3 medium Issue of medium importance in: DML issues related to the macro language is: feature Issue proposes a new feature labels Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 medium Issue of medium importance in: DML issues related to the macro language is: feature Issue proposes a new feature
Projects
None yet
Development

No branches or pull requests

1 participant