Pliant language controlsA program provided as a finit set of instructions, with no loop, will not do much. Let's imagine that we want to compute the math function factorial(5) = 1*2*3*4*5 We could do it as: console "factorial(5) = " 1*2*3*4*5 eol We could also do it more step by step as: var Int f := 1 ForThe new sequence might look heavier at first, but it's just an intermediate level to introduce the loop notion: var Int f := 1 The 'for' bloc means: 'i' variable will be 2, then 3, then 4, then 5, and each time, we do f := f*i You can provide a 'step' option to 'for' instruction if you want the 'i' variable step to not be the default value which is one: var Int f := 1 In the previous sample, 'i' variable value has been 5, then 4, then 3, then 2. WhileHere are the different ways to do loops in Pliant: var Int f := 1 Part, but no gotovar Int f := 1 Or: var Int f := 1 'part' takes an identifier as a parameter. Here, we have choosen 'loop', but it could be any indentifier. The identifier is used by 'leave' and 'restart' instruction to select the right part in case your program contains several nested ones. part loop "Computing factorial 5" The 'goto' instruction is not provided by standard Pliant libraries, so the following program will not work: var Int f := 1 Also defining 'label' and 'goto' is a very good exercise for advanced programmers that are learning Pliant meta programming. IfIf is the statement introducing conditional execution: var Int i := 1 ShuntThe next program is equivalent to the previous one: var Int i := 1 The weak point of 'shunt' is that it want's the result to be the one of one of it's aguments, so in complex situtations, you might have to add an explicit casting: var CBool c does not work because 'i' type is 'Int16' and the type of 12 is 'uInt', so 'shunt' is not smart enough to decide that the result type must be 'Int'. You have to write it as: var Int j := shunt c (cast i Int) 12 so that 'Int' be the type of one of the arguments. |