Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
cfl_ch_2-the_cfl_language [2019/01/30 20:50]
admin
cfl_ch_2-the_cfl_language [2019/02/20 10:51]
kcifreo
Line 17: Line 17:
 **Comments** describe what is going on. The author may thoroughly understand their own work, but when they return for maintenance in six months, they often forgot the intricacies of their own creation. Just like white space, CFL ignores all comments, regardless of how lengthy they are. **Comments** describe what is going on. The author may thoroughly understand their own work, but when they return for maintenance in six months, they often forgot the intricacies of their own creation. Just like white space, CFL ignores all comments, regardless of how lengthy they are.
  
-A **single-line comment** is created by typing in two slashes (//). Comments go at the end of a line of code. '' Declare x : 3*4 ; '' //'' Explain what x is used for here ''+A **single-line comment** is created by typing in two slashes (//). Comments go at the end of a line of code. // 
 +<code> 
 +//'' Declare x : 3*4 ; ''  //'' Explain what x is used for here '' 
 +</code>
  
 A **multi-line comment** begins with an open curly bracket ({) and ends with a closed curly bracket (}). A **multi-line comment** begins with an open curly bracket ({) and ends with a closed curly bracket (}).
Line 124: Line 127:
 </code> </code>
  
-CFL treats Booleans as a special case of the number type mentioned already. Zero (0) is considered NO or FALSE, whereas one ((3 4AND (1 1))  is considered to be YES or TRUE.+CFL treats Booleans as a special case of the number type mentioned already. Zero (0) is considered NO or FALSE, whereas one <sup>((1)))</sup>  is considered to be YES or TRUE.
  
 **DateTime Types** **DateTime Types**
Line 192: Line 195:
 |AND||Logical AND||  False|| |AND||Logical AND||  False||
 |NOT||Negation||( Not (3 4) ) True|| |NOT||Negation||( Not (3 4) ) True||
-|OR||Logical OR||((3 4OR (1 1))  True|| +|OR||Logical OR||<sup>((2)))</sup>  True|| 
-|XOR||Logical XOR||((3 4XOR (1 1))  True||+|XOR||Logical XOR||<sup>((3)))</sup>  True||
  
 **DateTime Operators** **DateTime Operators**
Line 229: Line 232:
 |2nd Highest||Unary||+, -, Not, BitNot, %|| |2nd Highest||Unary||+, -, Not, BitNot, %||
 |3rd Highest||Units||Per, In, *, /, Units|| |3rd Highest||Units||Per, In, *, /, Units||
-|Exponentiation||\^   ^| +|Exponentiation||\^   ^
-|Multiplicative||*, /, Mod|| |+|Multiplicative||*, /, Mod|| | |
 |3rd Lowest||Additive||+, - , And, Or, XOR, BitOr, BitAnd, BitXOR|| |3rd Lowest||Additive||+, - , And, Or, XOR, BitOr, BitAnd, BitXOR||
 |2nd Lowest||Relational||, , ,  || |2nd Lowest||Relational||, , ,  ||
 |Lowest||Assignment|| | | |Lowest||Assignment|| | |
- 
  
 When operands are between operators of the same precedence, then operations are performed from left to right, with the exception of unary and assignment operators. Therefore, When operands are between operators of the same precedence, then operations are performed from left to right, with the exception of unary and assignment operators. Therefore,
 +
 <code> <code>
 3 * 4 / 0 * 5 3 * 4 / 0 * 5
 </code> </code>
 +
 is equivalent to ( ( ( 3 * 4 ) / 0 ) * 5 ), and gives an error, due to division by zero, whereas the expression is equivalent to ( ( ( 3 * 4 ) / 0 ) * 5 ), and gives an error, due to division by zero, whereas the expression
 +
 <code> <code>
 3 * 4 / 5 * 0 3 * 4 / 5 * 0
 </code> </code>
 +
 will not give an error. will not give an error.
-\\ + 
-\\ +**Temporary Variables** Complex formulas are easier (and usually faster) if they are broken down into steps. Temporary variables are ideal for such occasions. Temporary variables are created within the CFL block and do not retain their values after the evaluation of the block is complete. (This is in contrast to Global Variables, which is discussed later.) Temporary variables use the "DECLARE" keyword and can be assigned a value immediately or upon later use, as in this example:
-**Temporary Variables** +
-Complex formulas are easier (and usually faster) if they are broken down into steps. Temporary variables are ideal for such occasions. Temporary variables are created within the CFL block and do not retain their values after the evaluation of the block is complete. (This is in contrast to Global Variables, which is discussed later.) \\ +
-Temporary variables use the "DECLARE" keyword and can be assigned a value immediately or upon later use, as in this example:+
 <code> <code>
 // First, convert the temperature Global Variable to Centigrade // First, convert the temperature Global Variable to Centigrade
Line 255: Line 258:
 Declare ExpansionText ; Declare ExpansionText ;
 // Calculate the expansion coefficient for the C temperature // Calculate the expansion coefficient for the C temperature
-Declare Expansion := Centigrade\^1.5 / 6.17323 ;+Declare Expansion := \Centigrade^1.5 / 6.17323 ;
 ExpansionText := "Expansion of " + ToString( Expansion ) + "nm / Y"  ; ExpansionText := "Expansion of " + ToString( Expansion ) + "nm / Y"  ;
 // Now repeat the expansion text 2 times as the result // Now repeat the expansion text 2 times as the result
 ExpansionText + " ! " + ExpansionText + " ! " ExpansionText + " ! " + ExpansionText + " ! "
 </code> </code>
-Note that the assignment operator is the colon-equals, and not just the equal sign as in some programming languages. This is to prevent confusion with the comparison operator. + 
-In this example, the temporary variable "Centigrade" converted the global variable "Temperature" to degrees C. From this, CFL calculated the expansion coefficient. This entire calculation could not be done in one step, and the multiple-step approach makes the logic easier to follow. \\ +Note that the assignment operator is the colon-equals, and not just the equal sign as in some programming languages. This is to prevent confusion with the comparison operator. In this example, the temporary variable "Centigrade" converted the global variable "Temperature" to degrees C. From this, CFL calculated the expansion coefficient. This entire calculation could not be done in one step, and the multiple-step approach makes the logic easier to follow. As in the example above, temporary variables are not limited to numbers. They can be any of the CFL data types, including Objects! 
-As in the example above, temporary variables are not limited to numbers. They can be any of the CFL data types, including Objects!+
 <code> <code>
 // First, define our local object reference variables // First, define our local object reference variables
 Declare Referral := 'None'; Declare Referral := 'None';
 Declare Salesperson := 'None'; Declare Salesperson := 'None';
- +
 // Assign the 'Referral' variable // Assign the 'Referral' variable
 IF TransactionUDFIsAssigned('Referred By Customer') THEN IF TransactionUDFIsAssigned('Referred By Customer') THEN
   Referral := TransactionUDFObject('Reffered By Customer');   Referral := TransactionUDFObject('Reffered By Customer');
 ENDIF; ENDIF;
- +
 // Assign the referring Sales person // Assign the referring Sales person
 Salesperson := Referral.Company.Salesperson1.IDAsString; Salesperson := Referral.Company.Salesperson1.IDAsString;
 SetTransactionUDFObjectID( "InitialSalesperson", Salesperson ); SetTransactionUDFObjectID( "InitialSalesperson", Salesperson );
- +
 // Output referral and salesperson // Output referral and salesperson
 Referral + "referred by " + Salesperson Referral + "referred by " + Salesperson
 </code> </code>
-\\ + 
-\\ +**Units** One of the most powerful features of CFL is the built-in support for units. Units are written in CFL just as in high-school science: after the number or variable they modify.
-**Units** +
-One of the most powerful features of CFL is the built-in support for units. Units are written in CFL just as in high-school science: after the number or variable they modify.+
 <code> <code>
 Declare WorkingPrice := Area in SqFeet * 5; Declare WorkingPrice := Area in SqFeet * 5;
-MaxSize :=      IF ( Height < 3 SqMeters  )+MaxSize :=      IF ( Height <3 SqMeters  )
 THEN 500 millimeters THEN 500 millimeters
 ELSE 0.95 meters ELSE 0.95 meters
 ENDIF ; ENDIF ;
-Declare TooBig := ( MaxSize*MaxSize > 24 SqInches ) ;+Declare TooBig := ( MaxSize*MaxSize> 24 SqInches ) ;
 IF ( 12 inches = 1 foot ) THEN "Elementary" IF ( 12 inches = 1 foot ) THEN "Elementary"
 ELSE "Error" ENDIF ELSE "Error" ENDIF
 </code> </code>
-\\ + 
-Here are some simple rules to remember about using units:\\ +Here are some simple rules to remember about using units: 
-  * Units apply to the number or variable immediately before them.\\ + 
-  * Variables are stored internally in their own units. Units are not needed when multiplying or adding variables, only when working with numbers or numbers compared to variables.\\+  * Units apply to the number or variable immediately before them. 
 +  * Variables are stored internally in their own units. Units are not needed when multiplying or adding variables, only when working with numbers or numbers compared to variables. 
 <code> <code>
-Area : Height * Width ; // Does not require units\\ +Area : Height * Width ; // Does not require \units 
-Area : Height * 12 inches ; //Numbers always need units\\ +Area : Height * 12 inches ; //Numbers always need \units 
-Area : 24 * 48 SqInches ; // Still a number, add the units\\ +Area : 24 * 48 SqInches ; // Still a number, add the \units 
-IF Height > 5 SqFeet THEN …//required here\\ +IF Height> 5 SqFeet THEN …//required \here 
-IF Height > 5 Feet*Feet THEN … // and here\\ +IF Height> 5 Feet*Feet THEN … // and \here 
-IF Height in SqFeet > 5 THEN …//here a different approach\\ +IF Height in SqFeet> 5 THEN …//here a different \approach 
-IF Height > Width THEN … // not here, both variables\\+IF Height> Width THEN … // not here, both \variables
 </code> </code>
-  * Either the singular form (like inch) or the plural form (like inches) can be used. Both are identical.\\ + 
-  * For square and cubic dimensions, precede the unit with "Sq" or "Cu" to make the square or cubic unit of that version. Alternately, "Unit*Unit" for the square or "Unit*Unit*Unit" for the cubic can be used.\\+  * Either the singular form (like inch) or the plural form (like inches) can be used. Both are identical. 
 +  * For square and cubic dimensions, precede the unit with "Sq" or "Cu" to make the square or cubic unit of that version. Alternately, "Unit*Unit" for the square or "Unit*Unit*Unit" for the cubic can be used. 
 <code> <code>
-9 SqFeet : 3 Feet * 3 Feet ; //Standard Form\\ +9 SqFeet : 3 Feet * 3 Feet ; //Standard \Form 
-9 SqFeet : 9 Feet*Feet ; // Alternate Form\\ +9 SqFeet : 9 Feet*Feet ; // Alternate \Form 
-27 CuFeet : 3 Feet * 3 Feet * 3 Feet; //Standard Form\\ +27 CuFeet : 3 Feet * 3 Feet * 3 Feet; //Standard \Form 
-27 CuFeet : 27 Feet*Feet*Feet ; // Alternate Form\\+27 CuFeet : 27 Feet*Feet*Feet ; // Alternate \Form
 </code> </code>
-  * The keywords IN and PER can be used to modify the meaning of the unit. These keywords can also be used to combine units with other units.  + 
-  +  * The keywords IN and PER can be used to modify the meaning of the unit. These keywords can also be used to combine units with other units. 
 <code> <code>
-Here is one set of equivalent expressions.\\ +Here is one set of equivalent expressions. 
-FinalPrice : Area * 5 PER SqFeet ;\\ +FinalPrice : Area * 5 PER SqFeet ; 
-FinalPrice : Area IN SqFeet * 5 ;\\ +FinalPrice : Area IN SqFeet * 5 ; 
-//Here is a slightly tougher form of equivalence …\\ +//Here is a slightly tougher form of equivalence … 
-ElapsedTime : Distance / 12 miles PER hour ;\\ +ElapsedTime : Distance / 12 miles PER hour ; 
-ElapsedTime : Distance IN Miles / 12 PER hour ;\\+ElapsedTime : Distance IN Miles / 12 PER hour ;
 </code> </code>
  
-The units defined in CFL include the following:\\ +The units defined in CFL include the following: 
-|| **Measure** || **Unit** || **Accepted Abbreviations** || + 
-|| Area || Square Centimeter || SqCentimeter, SqCentimeters, SqCentimetre, SqCentimetres || +|**Measure** ||**Unit** ||**Accepted Abbreviations** || 
-|| Area || Square Foot || SqFoot, SqFeet || +|Area||Square Centimeter||SqCentimeter, SqCentimeters, SqCentimetre, SqCentimetres|| 
-|| Area || Square Inch || SqInch, SqInches || +|Area||Square Foot||SqFoot, SqFeet|| 
-|| Area || Square Meter || SqMeter, SqMeters, SqMetre, SqMetres || +|Area||Square Inch||SqInch, SqInches|| 
-|| Area || Square Millimeter || SqMillimeter, SqMillimeters, SqMillimetre, SqMillimetres || +|Area||Square Meter||SqMeter, SqMeters, SqMetre, SqMetres|| 
-|| Area || Square Yard || SqYard, SqYards || +|Area||Square Millimeter||SqMillimeter, SqMillimeters, SqMillimetre, SqMillimetres|| 
-|| Discrete || (none) || N/A || +|Area||Square Yard||SqYard, SqYards|| 
-|| Discrete || Each || Each || +|Discrete||(none)||N/A|| 
-|| Discrete || Impression || Impression, Impressions || +|Discrete||Each||Each|| 
-|| Discrete || Page || Page, Pages || +|Discrete||Impression||Impression, Impressions|| 
-|| Discrete || Piece || Piece, Pieces || +|Discrete||Page||Page, Pages|| 
-|| Discrete || Sheet || Sheet, Sheets || +|Discrete||Piece||Piece, Pieces|| 
-|| Length || Centimeter || Centimeter, Centimeters, Centimetre, Centimetres || +|Discrete||Sheet||Sheet, Sheets|| 
-|| Length || Foot || Foot, Feet || +|Length||Centimeter||Centimeter, Centimeters, Centimetre, Centimetres|| 
-|| Length || Inch || Inch, Inches || +|Length||Foot||Foot, Feet|| 
-|| Length || Meter || Meter, Meters, Metre, Metres || +|Length||Inch||Inch, Inches|| 
-|| Length || Millimeter || Millimeter, Millimeters, Millimetre, Millimetres || +|Length||Meter||Meter, Meters, Metre, Metres|| 
-|| Length || Yard || Yard, Yards || +|Length||Millimeter||Millimeter, Millimeters, Millimetre, Millimetres|| 
-|| Time || Day || Day, Days || +|Length||Yard||Yard, Yards|| 
-|| Time || Hour || Hour, Hours || +|Time||Day||Day, Days|| 
-|| Time || Minute || Minute, Minutes || +|Time||Hour||Hour, Hours|| 
-|| Time || Second || Second, Seconds || +|Time||Minute||Minute, Minutes|| 
-|| Volume || Cubic Centimeter || CuCentimeter, CuCentimeters, CuCentimetre, CuCentimetres || +|Time||Second||Second, Seconds|| 
-|| Volume || Cubic Foot || CuFoot, CuFeet || +|Volume||Cubic Centimeter||CuCentimeter, CuCentimeters, CuCentimetre, CuCentimetres|| 
-|| Volume || Cubic Inch || CuInch, CuInches || +|Volume||Cubic Foot||CuFoot, CuFeet|| 
-|| Volume || Cubic Meter || CuMeter, CuMeters, CuMetre, CuMetres || +|Volume||Cubic Inch||CuInch, CuInches|| 
-|| Volume || Cubic Millimeter || CuMillimeter, CuMillimeters, CuMillimetre, CuMillimetres || +|Volume||Cubic Meter||CuMeter, CuMeters, CuMetre, CuMetres|| 
-|| Volume || Cubic Yard || CuYard, CuYards || +|Volume||Cubic Millimeter||CuMillimeter, CuMillimeters, CuMillimetre, CuMillimetres|| 
-|| Volume || Cup || Cup, Cups || +|Volume||Cubic Yard||CuYard, CuYards|| 
-|| Volume || Gallon || Gallon, Gallons || +|Volume||Cup||Cup, Cups|| 
-|| Volume || Liter || Liter, Liters, Litre, Litres || +|Volume||Gallon||Gallon, Gallons|| 
-|| Volume || Milliliter || Milliliter, Milliliters, Millilitre, Millilitres || +|Volume||Liter||Liter, Liters, Litre, Litres|| 
-|| Volume || Pint || Pint, Pints || +|Volume||Milliliter||Milliliter, Milliliters, Millilitre, Millilitres|| 
-|| Volume || Quart || Quart, Quarts || +|Volume||Pint||Pint, Pints|| 
-|| Weight || FluidOunce || FluidOunce, FluidOunces || +|Volume||Quart||Quart, Quarts|| 
-|| Weight || Gram || Gram, Grams || +|Weight||FluidOunce||FluidOunce, FluidOunces|| 
-|| Weight || Kilogram || Kilogram, Kilograms || +|Weight||Gram||Gram, Grams|| 
-|| Weight || Milligram || Milligram, Milligrams || +|Weight||Kilogram||Kilogram, Kilograms|| 
-|| Weight || Ounce || Ounce, Ounces || +|Weight||Milligram||Milligram, Milligrams|| 
-|| Weight || Pound || Pound, Pounds || +|Weight||Ounce||Ounce, Ounces|| 
-|| Weight || Ton || Ton, Tons || +|Weight||Pound||Pound, Pounds|| 
 +|Weight||Ton||Ton, Tons|| 
 + 
 +Expressions using units are found throughout the rest of this reference. After a bit of practice with using units, CFL's easy-to-use unit syntax is mastered in no time. 
 + 
 +==== CONTROL (BRANCHING) OPERATIONS ====
  
-Expressions using units are found throughout the rest of this reference. After a bit of practice with using units, CFL's easy-to-use unit syntax is mastered in no time. +=== IF THEN ===
  
-==== CONTROL (BRANCHING) OPERATIONS ==== +Using **IF**  statements can alter the path calculations use to determine their result. The IF statement enables a user to test for a Boolean logical condition in the program, and if that condition is true, the program returns some expression contained in that branch. If the condition is false, then the program returns an expression in a different branch. The syntax for the IF statement is as follows. Since white space does not matter, a different style can be used.
  
-=== IF THEN ===  
-Using **IF** statements can alter the path calculations use to determine their result. The IF statement enables a user to test for a Boolean logical condition in the program, and if that condition is true, the program returns some expression contained in that branch. If the condition is false, then the program returns an expression in a different branch. The syntax for the IF statement is as follows. Since white space does not matter, a different style can be used.  
 <code> <code>
 IF condition THEN IF condition THEN
Line 383: Line 392:
 ENDIF ENDIF
 </code> </code>
-Translation: If the condition is true, then TrueExpression will be evaluated. If condition is false, then FalseExpression will be evaluated. The condition can be any expression that returns a Boolean value. An example of the IF statement may help illustrate the how this all works in practice. + 
 +Translation: If the condition is true, then TrueExpression will be evaluated. If condition is false, then FalseExpression will be evaluated. The condition can be any expression that returns a Boolean value. An example of the IF statement may help illustrate the how this all works in practice. 
 <code> <code>
-IF      (Height > SheetHeight) or (Width > SheetWidth)+IF      (Height> SheetHeight) or (Width> SheetWidth)
 THEN    PiecesPerSheet := 0 ; THEN    PiecesPerSheet := 0 ;
 ELSE    Declare SheetsHigh = Int( SheetHeight / Height ) ; ELSE    Declare SheetsHigh = Int( SheetHeight / Height ) ;
Line 394: Line 405:
 PiecesPerSheet ; PiecesPerSheet ;
 </code> </code>
 +
 There is no limit to one expression for TrueExpression or FalseExpression. Rather, CFL uses everything between THEN and ELSE as the TrueExpression and everything between the ELSE and ENDIF as the FalseExpression. There is no limit to one expression for TrueExpression or FalseExpression. Rather, CFL uses everything between THEN and ELSE as the TrueExpression and everything between the ELSE and ENDIF as the FalseExpression.
  
-An IF statement can also be placed within another IF statement; the inner IF is then said to be **nested** within the other. The following syntax shows a nested IF statement.+An IF statement can also be placed within another IF statement; the inner IF is then said to be **nested**  within the other. The following syntax shows a nested IF statement. 
 <code> <code>
 IF condition THEN IF condition THEN
Line 412: Line 425:
  
 ==== CASE ==== ==== CASE ====
-The **CASE** statement is similar to an IF statement, but provides an unlimited number of branches instead of just two. The syntax of the CASE statement is as follows:+ 
 +The **CASE**  statement is similar to an IF statement, but provides an unlimited number of branches instead of just two. The syntax of the CASE statement is as follows: 
 <code> <code>
 CASE  [ TestExpression  ] IS CASE  [ TestExpression  ] IS
Line 494: Line 509:
 Declare i; Declare i;
 Declare S := ''; Declare S := '';
- +
 FOR i := 0 TO Parts.SonCount-1 DO FOR i := 0 TO Parts.SonCount-1 DO
   IF (Parts[i].TrackInventory = "True")   IF (Parts[i].TrackInventory = "True")
-     AND (Parts[i].QuantityAvailable < Parts[i].YellowNotificationPoint)+     AND (Parts[i].QuantityAvailable <Parts[i].YellowNotificationPoint)
   THEN   THEN
       S:= S + (Parts[i].PartCode) + " is below the yellow level of "       S:= S + (Parts[i].PartCode) + " is below the yellow level of "
Line 504: Line 519:
   ENDIF;   ENDIF;
 ENDFOR; ENDFOR;
- +
 // The value of any CFL statement is the value of the last computation/display // The value of any CFL statement is the value of the last computation/display
 // Now we need to return our value as the value of this function. // Now we need to return our value as the value of this function.
Line 518: Line 533:
 Declare i; Declare i;
 Declare S := ''; Declare S := '';
- +
 FOR i := 0 TO Parts.SonCount-1 DO FOR i := 0 TO Parts.SonCount-1 DO
       S:= S + (Parts[i].PartCode) + " is the part name and " + (Parts[i].Description) + " is the description of the part. " + HTMLRETURN       S:= S + (Parts[i].PartCode) + " is the part name and " + (Parts[i].Description) + " is the description of the part. " + HTMLRETURN
 ENDFOR; ENDFOR;
- +
 // To display the results of our FOR statement we need to notate S; below since it was a declared variable above. // To display the results of our FOR statement we need to notate S; below since it was a declared variable above.
- +
 S; S;
 </code> </code>
Line 539: Line 554:
  
 ==== REPEAT UNTIL ==== ==== REPEAT UNTIL ====
-Use **REPEAT** statements to create loops that executes once and then continues as long as some condition is true. \\ + 
-The syntax for the REPEAT statement is as follows. Since white space does not matter, a different style can be used.+Use **REPEAT**  statements to create loops that executes once and then continues as long as some condition is true. \\ The syntax for the REPEAT statement is as follows. Since white space does not matter, a different style can be used. 
 <code> <code>
 REPEAT REPEAT
Line 546: Line 562:
 UNTIL (condition) [MAXCOUNT = maxloops]; UNTIL (condition) [MAXCOUNT = maxloops];
 </code> </code>
-The pieces of the WHILE statement are: \\+ 
 +The pieces of the WHILE statement are: 
   * **condition**.   * **condition**.
   * **maxloops**. This optional identifier sets a maximum number of loops that the loop will perform. If this limit is reached, execution automatically moved to the line of CFL following the loop.   * **maxloops**. This optional identifier sets a maximum number of loops that the loop will perform. If this limit is reached, execution automatically moved to the line of CFL following the loop.
-\\ + \\ An example of the WHILE statement follows: 
-An example of the WHILE statement follows:+
 <code> <code>
 +[[code|]]
 +
 +===WHILE===
 +
 +Use **WHILE** statements to create loops that execute if and while something is true.
 +The syntax for the WHILE statement is as follows. Since white space does not matter, a different style can be used.
 +</code>
 +
 WHILE (condition) [MAXCOUNT = maxloops] DO WHILE (condition) [MAXCOUNT = maxloops] DO
-ExpressionBlock ;+ 
 +ExpressionBlock; 
 ENDWHILE; ENDWHILE;
 +
 <code> <code>
 +The pieces of the WHILE statement are:
 +* **condition**.
 +* **maxloops**. This optional identifier sets a maximum number of loops that the loop will perform. If this limit is reached, execution automatically moved to the line of CFL following the loop.
 +</code>
 +
 +\\
 +