3 ms·
When I saw this, I was hoping for the impossible, and was predictably disappointed. This is not the GOTO you know (at least, it will never match up to C or to
by tc 17y ago
When I saw this, I was hoping for the impossible, and was predictably disappointed. This is not the GOTO you know (at least, it will never match up to C or to CL's TAGBODY), as it cannot jump forward to labels declared textually later in the code.
I've worked through various ways of trying to implement goto in Javascript via preprocessing for the parenscript CL library, and have always come away feeling unsatisfied. You can do it, but as far as I can tell, you have to use a trampoline.
A native goto statement in Javascript would go a long way into making JS an acceptable compilation target.
- s3graham 17y ago> A native goto statement in Javascript would go a long way into making JS an acceptable compilation target. Much agreement here. I alternate between wishing for a goto in JS, and wishing for a lower level bytecode to be exposed from the browser. goto does seem more likely though.
- tlrobinson 17y agoRather than using nested while loops with labels, why not use one big while loop and a switch statement? This seems cleaner and would allow jumping ahead, rather than just behind. Labels "[lbl] foo" would become "case 'foo':goto_label=false;" and gotos "goto foo;" would become "goto_label='foo'; continue goto_loop;". Example: var goto_label='top'; goto_loop: while(goto_label) { switch(goto_label) { case 'top': goto_label=false; ... goto_label='foo'; continue goto_loop; ... case 'foo': goto_label=false; ... }} Not perfect, but better. edit: scratch that, labels within other control structures won't work, only top level ones.