Talk:Jump anywhere: Difference between revisions

From Rosetta Code
Content added Content deleted
m (→‎Signal use in Rexx: show output)
(→‎Signal use in Rexx: added comments regarding what's legal vs. what's wrong programming. -- ~~~~)
Line 28: Line 28:
__Warning__: Not only jumping into Do loops (as noted under REXX) is usually an error.
__Warning__: Not only jumping into Do loops (as noted under REXX) is usually an error.
Jumping into or within Do groups is equally wrong.
Jumping into or within Do groups is equally wrong.

:: Jumping (in REXX, '''signal'''ing) within a '''DO''' loop is legal and is illustrated within the Regina PDF documentation. [What is ''wrong'' is merely a judgement call.] It's the execution of the '''DO''' or the '''END''' statement [after a '''signal''' instruction is executed] that is illegal and thus causes a '''syntax''' error. I don't want to endorse nor propose its use. I was merely showing what is legal, not what is considered bad practice (or wrongness) by some. I don't pontificate what should be considered/practiced/used when it comes to what is legal vs. what is bad programming. -- [[User:Gerard Schildberger|Gerard Schildberger]] 21:02, 9 December 2012 (UTC)


Please consider Signal only for condition handling or very global jumps such as Signal end_of_job.
Please consider Signal only for condition handling or very global jumps such as Signal end_of_job.
Line 39: Line 41:
4 *-* End
4 *-* End
Error 10 running H:\sig.rex line 4: Unexpected or unmatched END
Error 10 running H:\sig.rex line 4: Unexpected or unmatched END
Error 10.1: END has no corresponding DO, LOOP, or SELECT
Error 10.1: END has no corresponding DO, LOOP, or SELECT
</pre>
</pre>

: Please note that that your (illegal) code is "executing" the '''END''' instruction which has been rendered invalid by the execution of the '''signal''' instruction, which resulted in the '''syntax''' error (as cautioned in the comments in the REXX section header). -- [[User:Gerard Schildberger|Gerard Schildberger]] 21:02, 9 December 2012 (UTC)

: I use the '''signal''' instruction for other than error condition handling or very global jumps for E-O-J and such. There are other uses for the '''signal''' instruction than that. -- [[User:Gerard Schildberger|Gerard Schildberger]] 21:02, 9 December 2012 (UTC)

Revision as of 21:02, 9 December 2012

Draft task

My new task description might not match my intent. I have a short Ruby example, but I want to add more Ruby code, and some C code. --Kernigh 02:41, 19 May 2011 (UTC)

OK, I'll monitor and ask about changes needed for the Python as things develop :-)
--Paddy3118 02:54, 19 May 2011 (UTC)
Tcl (8.6) has pretty much the same capabilities as Python in this area. (When people ask for general jump anywhere capabilities, we tend to be somewhat brusque in our dismissals; it's totally against nice structured programming as well as being evil.) I'll keep an eye on the evolution of the page to see whether I want to omit or implement. Generally, should continuations be a solution of this task? Or is it more about setjmp/longjmp? –Donal Fellows 17:51, 19 May 2011 (UTC)
Just to be clear, this is not to diss having a task on continuations. It's just they're not simple jumps; if we split, we can easily justify another task specifically for them. –Donal Fellows 19:09, 19 May 2011 (UTC)

Demonstrate a local jump and a global jump

It might be better for the task to be demonstrate a local jump and a global jump. (Currently the requirement appears to be for a global jump, requiring a new task to be created for a local jump).

Markhobley 14:19, 19 May 2011 (UTC)

I propose that unwinding of the call stack is moved to a separate task, and rename this task to "Demonstrate local and global jumps". Keeping the tasks separated, enables the solutions to remain simple, and separates aspects. --Markhobley 16:40, 6 June 2011 (UTC)

What is a "global jump"? Continuation? Longjump (which involves stack)? --Ledrug 03:04, 11 June 2011 (UTC)
I assumed that a local jump is to a label within the same procedure (or block of procedures), whereas a global jump is to anwhere within the program. --Markhobley 08:12, 11 June 2011 (UTC)
That would normally involves unwinding the stack, then, because if you are going out of a proc or function and not coming back, you have to clean up what's already allocated for your current scope, or everyone gets confused -- unless your language doesn't have a stack concept, which is rare. --Ledrug 08:39, 11 June 2011 (UTC)
Yeah. It depends on the language. A local jump within the same procedure would probably not need an unwind. A global jumb could need an unwind, and the unwind may be done at source, prior to the jump or at destination following the jump. Jumping out of a procedure (following a call) is not usually a good idea, although it may be for a critical reason, such as an abort. I would just stick a note saying "the stack will need to be unwound, before this jump is performed" and cross reference to the stack unwinding task. Some languages may have a garbage collector, which removes the need to unwind the stack. Maybe it would be tidier to split the task into Jumps/Local, Jumps/Global and Jumps/With stack unwinding. --Markhobley 10:20, 11 June 2011 (UTC)

Signal use in Rexx

__Warning__: Not only jumping into Do loops (as noted under REXX) is usually an error. Jumping into or within Do groups is equally wrong.

Jumping (in REXX, signaling) within a DO loop is legal and is illustrated within the Regina PDF documentation. [What is wrong is merely a judgement call.] It's the execution of the DO or the END statement [after a signal instruction is executed] that is illegal and thus causes a syntax error. I don't want to endorse nor propose its use. I was merely showing what is legal, not what is considered bad practice (or wrongness) by some. I don't pontificate what should be considered/practiced/used when it comes to what is legal vs. what is bad programming. -- Gerard Schildberger 21:02, 9 December 2012 (UTC)

Please consider Signal only for condition handling or very global jumps such as Signal end_of_job. Example: <lang rexx> Do

  Signal label
  label: Say 'label reached'
End</lang>

Output:

     4 *-* End
Error 10 running H:\sig.rex line 4:  Unexpected or unmatched END
Error 10.1:  END has no corresponding DO, LOOP, or SELECT 
Please note that that your (illegal) code is "executing" the END instruction which has been rendered invalid by the execution of the signal instruction, which resulted in the syntax error (as cautioned in the comments in the REXX section header). -- Gerard Schildberger 21:02, 9 December 2012 (UTC)
I use the signal instruction for other than error condition handling or very global jumps for E-O-J and such. There are other uses for the signal instruction than that. -- Gerard Schildberger 21:02, 9 December 2012 (UTC)