Content deleted Content added
m →SNOBOL |
BrainStack (talk | contribs) Link suggestions feature: 3 links added. |
||
Line 95:
</syntaxhighlight>
This means, "as long as read does not fail, call write, otherwise stop".{{sfn|Tratt|2010|p=74}} There is no need to specify a test against the magic number as in the Java example, this is implicit, and the resulting code is simplified. Because success and failure are passed up through the call chain, one can embed function calls within others and they stop when the [[nested function]] call fails. For instance, the code above can be reduced to:{{sfn|Griswold|1996|p=2.1}}
<syntaxhighlight lang="icon">
Line 244:
</syntaxhighlight>
Of course there are times where one does want to find a string after some point in input, for instance, if scanning a [[text file]] that contains a line number in the first four columns, a space, and then a line of text. Goal-directed execution can be used to skip over the line numbers:
<syntaxhighlight lang="icon">
Line 361:
Icon refers to the left-hand-side of the {{code|?}} as the ''subject'', and passes it into string functions. Recall the {{code|find}} takes two parameters, the search text as parameter one and the string to search in parameter two. Using {{code|?}} the second parameter is implicit and does not have to be specified by the programmer. In the common cases when multiple functions are being called on a single string in sequence, this style can significantly reduce the length of the resulting code and improve clarity. Icon function signatures identify the subject parameter in their definitions so the parameter can be [[Loop-invariant code motion|hoisted]] in this fashion.
The {{code|?}} is not simply a form of [[syntactic sugar]], it also sets up a "string scanning environment" for any following string operations. This is based on two internal variables, {{code|&subject}} and {{code|&pos}}; {{code|&subject}} is simply a pointer to the original string, while {{code|&pos}} is the current position within it, or cursor. Icon's various string manipulation procedures use these two variables so they do not have to be explicitly supplied by the programmer. For example:
<syntaxhighlight lang="icon">
|