Branch: Difference between revisions

Jump to navigation Jump to search
32 bytes added ,  00:06, 20 July 2022
#Abort
No edit summary
(#Abort)
Line 5: Line 5:
Branch was the only form of flow control in early versions of APL, having been carried over from the conditional flow arrows of [[Iverson Notation]]. Some APL dialects later added the more modern [[control structure]]s leading to deprecation of Branch.
Branch was the only form of flow control in early versions of APL, having been carried over from the conditional flow arrows of [[Iverson Notation]]. Some APL dialects later added the more modern [[control structure]]s leading to deprecation of Branch.


Branch is unusual having syntax resembling a [[monadic function]], but affecting program flow rather than altering arrays. In addition, a so called "naked branch", that is, a [[niladic]] <source lang=apl inline>→</source> will cut one level off the call stack.
Branch is unusual having syntax resembling a [[monadic function]], but affecting program flow rather than altering arrays. <span id=Abort>In addition, a so called "naked branch" or"abort", that is, a [[niladic]] <source lang=apl inline>→</source> will cut one level off the call stack.</span>


In a [[tradfn]], Branch can take a [[scalar]] or [[vector]] argument, and immediately cause execution to resume on the line indicated by the first element of the argument, which must be a non-negative integer. If the line number is 0, the function will return to its caller. If the argument is empty, the effect is that of consuming the argument and giving no result, equivalent to the dfn <source lang=apl inline>{}</source>. Inserting a label (an identifier followed by a colon <source lang=apl inline>:</source>) into a function, in a sense declares a name as a constant with the scalar value of the current number for whichever line the label occurs on. This ensures stability when lines are inserted into a function.
In a [[tradfn]], Branch can take a [[scalar]] or [[vector]] argument, and immediately cause execution to resume on the line indicated by the first element of the argument, which must be a non-negative integer. If the line number is 0, the function will return to its caller. If the argument is empty, the effect is that of consuming the argument and giving no result, equivalent to the dfn <source lang=apl inline>{}</source>. Inserting a label (an identifier followed by a colon <source lang=apl inline>:</source>) into a function, in a sense declares a name as a constant with the scalar value of the current number for whichever line the label occurs on. This ensures stability when lines are inserted into a function.

Navigation menu