3 ms·
Do you have or know of a better implementation?
by e40 10y ago
Do you have or know of a better implementation?
- kazinator 10y agoHow about a while true loop with cases in it on a state variable. goto=42 while true ; do case $goto in 1 ) code for label 1 goes here break # finish ;; 42 ) code for label 42 goes here goto=1 ;; esac done You don't have the syntactic sugar here, and there are some inconveniences, but think of the positives: this does not claim a new stack frame for each jump, let a lone a new stack frame holding a big string variable that holds most of the script source code.
- striking 10y agoI recall seeing a coroutine library for C that did exactly this using preprocessor magic. EDIT: /me sighs, this isn't the one I was looking for but it'll do for now. http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html / http://www.chiark.greenend.org.uk/~sgtatham/coroutines.h http://www.chiark.greenend.org.uk/~sgtatham/coroutines.h