Jump to content

Flow-control structures: Difference between revisions

m (Unicon/Icon consistency 2 + next to do find somewhere for all the supporting detail here, but where? Language page?)
Line 378:
==={{header|Icon}}===
====Prelude about Goal-Directed Evaluation and Generators====
A central feature of Icon and Unicon is what is known as Goal-Directed Evaluation, and the intimately related concept of Generators. Without trying to be a tutorial, the idea is that expressions can yield more than one result (Generators) and if a further part of the expression results in failure, the earlier Generators will be driven to yield more results. The effect is not unlike the backtracking found in Prolog or Regular Expressions, however the feature is built into the very core of the language. Prolog programmers will find it very familiar but of course with differences because Icon and Unicon do not use the functional language pattern matching technique of Prolog.
 
To cut a long story short, every expression and statement can ''fail'', or generate one or more results that can be consumed or applied in further parts of the statement. There are also a few keyword statements which force the generation of all possible outcomes for a statement or expression.
 
Two of the key features of Icon and Unicon that affect program flow are [[Icon%2BUnicon/Intro#Goal-Directed_Evaluation_and_Generators|Goal Directed Evaluation and Generators]] and [[Icon%2BUnicon/Intro#Failure_is_an_Option|Expression Failure]]. Goal Direction uses Generators to produce multiple results as needed and Expression Success and Failure forces the selection of logic pathways within programs.
Another way of looking at it is to understand that every expression can yield a ''result sequence'' that can be empty; any code using this expression may choose to ask for more results, gather them into a container or aggregate, or choose to use one value and then move on without asking for all possible results.
 
====goto====
Does not exist in the Icon or Unicon language.
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.