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:08]
admin
cfl_ch_2-the_cfl_language [2019/02/20 10:41]
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 (}).
 <code> <code>
Line 229: Line 231:
 |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, 
-Here are some simple rules to remember about using units:\\ + 
-* Units apply to the number or variable immediately before them.\\ +<code> 
-* 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.\\ +3 * 4 / 0 * 5 
-\\ +</code> 
-Area : Height * Width ; // Does not require units\+ 
-Area : Height * 12 inches ; //Numbers always need units\\ +is equivalent to ( ( ( 3 * 4 ) / 0 ) * 5 ), and gives an error, due to division by zero, whereas the expression 
-Area : 24 * 48 SqInches ; // Still a number, add the units\\ + 
-IF Height > 5 SqFeet THEN …//required here\\ +<code> 
-IF Height > 5 Feet*Feet THEN … // and here\\ +3 * 4 / 5 * 0 
-IF Height in SqFeet > 5 THEN …//here a different approach\+</code> 
-IF Height > Width THEN … // not here, both variables\+ 
-\\ +will not give an error. 
-* 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.\\ +**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: 
-9 SqFeet : 3 Feet * 3 Feet ; //Standard Form\+ 
-9 SqFeet : 9 Feet*Feet ; // Alternate Form\\ +<code> 
-27 CuFeet : 3 Feet * 3 Feet * 3 Feet; //Standard Form\\ +// First, convert the temperature Global Variable to Centigrade 
-27 CuFeet : 27 Feet*Feet*Feet ; // Alternate Form\+Declare Centigrade := (Temperature – 32) * 5/9 ; 
-\\ +Declare ExpansionText ; 
-* 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. // \\ +// Calculate the expansion coefficient for the C temperature 
-\\ +Declare Expansion := \Centigrade^1.5 / 6.17323 ; 
-Here is one set of equivalent expressions.\\ +ExpansionText := "Expansion of " + ToString( Expansion ) + "nm / Y" 
-FinalPrice : Area * 5 PER SqFeet ;\\ +// Now repeat the expansion text 2 times as the result 
-FinalPrice : Area IN SqFeet * 5 ;\\ +ExpansionText + " ! " + ExpansionText + " ! " 
-//Here is a slightly tougher form of equivalence …\\ +</code> 
-ElapsedTime : Distance / 12 miles PER hour ;\\ + 
-ElapsedTime : Distance IN Miles / 12 PER hour ;\\ +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! 
-The units defined in CFL include the following:\\ + 
-|| **Measure** || **Unit** || **Accepted Abbreviations** ||| Area || Square Centimeter || SqCentimeter, SqCentimeters, SqCentimetre, SqCentimetres ||| Area || Square Foot || SqFoot, SqFeet ||| Area || Square Inch || SqInch, SqInches ||| Area || Square Meter || SqMeter, SqMeters, SqMetre, SqMetres ||| Area || Square Millimeter || SqMillimeter, SqMillimeters, SqMillimetre, SqMillimetres ||| Area || Square Yard || SqYard, SqYards ||| Discrete || (none) || N/A ||| Discrete || Each || Each ||| Discrete || Impression || Impression, Impressions ||| Discrete || Page || Page, Pages ||| Discrete || Piece || Piece, Pieces ||| Discrete || Sheet || Sheet, Sheets ||| Length || Centimeter || Centimeter, Centimeters, Centimetre, Centimetres ||| Length || Foot || Foot, Feet ||| Length || Inch || Inch, Inches ||| Length || Meter || Meter, Meters, Metre, Metres ||| Length || Millimeter || Millimeter, Millimeters, Millimetre, Millimetres ||| Length || Yard || Yard, Yards ||| Time || Day || Day, Days ||| Time || Hour || Hour, Hours ||| Time || Minute || Minute, Minutes ||| Time || Second || Second, Seconds ||| Volume || Cubic Centimeter || CuCentimeter, CuCentimeters, CuCentimetre, CuCentimetres ||| Volume || Cubic Foot || CuFoot, CuFeet ||| Volume || Cubic Inch || CuInch, CuInches ||| Volume || Cubic Meter || CuMeter, CuMeters, CuMetre, CuMetres ||| Volume || Cubic Millimeter || CuMillimeter, CuMillimeters, CuMillimetre, CuMillimetres ||| Volume || Cubic Yard || CuYard, CuYards ||| Volume || Cup || Cup, Cups ||| Volume || Gallon || Gallon, Gallons ||| Volume || Liter || Liter, Liters, Litre, Litres ||| Volume || Milliliter || Milliliter, Milliliters, Millilitre, Millilitres ||| Volume || Pint || Pint, Pints ||| Volume || Quart || Quart, Quarts ||| Weight || FluidOunce || FluidOunce, FluidOunces ||| Weight || Gram || Gram, Grams ||| Weight || Kilogram || Kilogram, Kilograms ||| Weight || Milligram || Milligram, Milligrams ||| Weight || Ounce || Ounce, Ounces ||| 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 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. '' IF condition THEN TrueExpression ; ELSE FalseExpression ; ENDIF '' 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. '' IF (Height > SheetHeight) or (Width > SheetWidth) THEN PiecesPerSheet : 0 ; ELSE Declare SheetsHigh Int( SheetHeight / Height ) ; Declare SheetsAcross Int( SheetWidth / Width ) ; PiecesPerSheet : SheetsHigh * SheetsAcross ; ENDIF ; '' //'' Now return PiecesPerSheet as our Answer PiecesPerSheet ; ''+<code> 
 +// First, define our local object reference variables 
 +Declare Referral := 'None'; 
 +Declare Salesperson := 'None'; 
 + 
 +// Assign the 'Referral' variable 
 +IF TransactionUDFIsAssigned('Referred By Customer') THEN 
 +  Referral := TransactionUDFObject('Reffered By Customer'); 
 +ENDIF; 
 + 
 +// Assign the referring Sales person 
 +Salesperson := Referral.Company.Salesperson1.IDAsString; 
 +SetTransactionUDFObjectID( "InitialSalesperson", Salesperson ); 
 + 
 +// Output referral and salesperson 
 +Referral + "referred by " + Salesperson 
 +</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. 
 +<code> 
 +Declare WorkingPrice := Area in SqFeet * 5; 
 +MaxSize :=      IF ( Height <3 SqMeters 
 +THEN 500 millimeters 
 +ELSE 0.95 meters 
 +ENDIF ; 
 +Declare TooBig := ( MaxSize*MaxSize> 24 SqInches ) ; 
 +IF ( 12 inches = 1 foot ) THEN "Elementary" 
 +ELSE "Error" ENDIF 
 +</code> 
 + 
 + 
 +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. 
 + 
 +<code> 
 +Area : Height * Width ; // Does not require \units 
 +Area : Height * 12 inches ; //Numbers always need \units 
 +Area : 24 * 48 SqInches ; // Still a number, add the \units 
 +IF Height> 5 SqFeet THEN …//required \here 
 +IF Height> 5 Feet*Feet THEN … // and \here 
 +IF Height in SqFeet> 5 THEN …//here a different \approach 
 +IF Height> Width THEN … // not here, both \variables 
 +</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. 
 + 
 +<code> 
 +9 SqFeet : 3 Feet * 3 Feet ; //Standard \Form 
 +9 SqFeet : 9 Feet*Feet ; // Alternate \Form 
 +27 CuFeet : 3 Feet * 3 Feet * 3 Feet; //Standard \Form 
 +27 CuFeet : 27 Feet*Feet*Feet ; // Alternate \Form 
 +</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. 
 + 
 +<code> 
 +Here is one set of equivalent expressions. 
 +FinalPrice : Area * 5 PER SqFeet ; 
 +FinalPrice : Area IN SqFeet * 5 ; 
 +//Here is a slightly tougher form of equivalence … 
 +ElapsedTime : Distance / 12 miles PER hour ; 
 +ElapsedTime : Distance IN Miles / 12 PER hour ; 
 +</code> 
 + 
 +The units defined in CFL include the following: 
 + 
 +|**Measure** ||**Unit** ||**Accepted Abbreviations** || 
 +|Area||Square Centimeter||SqCentimeter, SqCentimeters, SqCentimetre, SqCentimetres|| 
 +|Area||Square Foot||SqFoot, SqFeet|| 
 +|Area||Square Inch||SqInch, SqInches|| 
 +|Area||Square Meter||SqMeter, SqMeters, SqMetre, SqMetres|| 
 +|Area||Square Millimeter||SqMillimeter, SqMillimeters, SqMillimetre, SqMillimetres|| 
 +|Area||Square Yard||SqYard, SqYards|| 
 +|Discrete||(none)||N/A|| 
 +|Discrete||Each||Each|| 
 +|Discrete||Impression||Impression, Impressions|| 
 +|Discrete||Page||Page, Pages|| 
 +|Discrete||Piece||Piece, Pieces|| 
 +|Discrete||Sheet||Sheet, Sheets|| 
 +|Length||Centimeter||Centimeter, Centimeters, Centimetre, Centimetres|| 
 +|Length||Foot||Foot, Feet|| 
 +|Length||Inch||Inch, Inches|| 
 +|Length||Meter||Meter, Meters, Metre, Metres|| 
 +|Length||Millimeter||Millimeter, Millimeters, Millimetre, Millimetres|| 
 +|Length||Yard||Yard, Yards|| 
 +|Time||Day||Day, Days|| 
 +|Time||Hour||Hour, Hours|| 
 +|Time||Minute||Minute, Minutes|| 
 +|Time||Second||Second, Seconds|| 
 +|Volume||Cubic Centimeter||CuCentimeter, CuCentimeters, CuCentimetre, CuCentimetres|| 
 +|Volume||Cubic Foot||CuFoot, CuFeet|| 
 +|Volume||Cubic Inch||CuInch, CuInches|| 
 +|Volume||Cubic Meter||CuMeter, CuMeters, CuMetre, CuMetres|| 
 +|Volume||Cubic Millimeter||CuMillimeter, CuMillimeters, CuMillimetre, CuMillimetres|| 
 +|Volume||Cubic Yard||CuYard, CuYards|| 
 +|Volume||Cup||Cup, Cups|| 
 +|Volume||Gallon||Gallon, Gallons|| 
 +|Volume||Liter||Liter, Liters, Litre, Litres|| 
 +|Volume||Milliliter||Milliliter, Milliliters, Millilitre, Millilitres|| 
 +|Volume||Pint||Pint, Pints|| 
 +|Volume||Quart||Quart, Quarts|| 
 +|Weight||FluidOunce||FluidOunce, FluidOunces|| 
 +|Weight||Gram||Gram, Grams|| 
 +|Weight||Kilogram||Kilogram, Kilograms|| 
 +|Weight||Milligram||Milligram, Milligrams|| 
 +|Weight||Ounce||Ounce, Ounces|| 
 +|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 ==== 
 + 
 +=== 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> 
 +IF condition THEN 
 +TrueExpression ; 
 +ELSE 
 +FalseExpression ; 
 +ENDIF 
 +</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. 
 + 
 +<code> 
 +IF      (Height> SheetHeight) or (Width> SheetWidth) 
 +THEN    PiecesPerSheet :0 ; 
 +ELSE    Declare SheetsHigh Int( SheetHeight / Height ) ; 
 +Declare SheetsAcross Int( SheetWidth / Width ) ; 
 +PiecesPerSheet :SheetsHigh * SheetsAcross ; 
 +ENDIF ; 
 +// Now return PiecesPerSheet as our Answer 
 +PiecesPerSheet ; 
 +</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 285: Line 429:
 It is considered good syntax to index nested IF's so that they can be easily followed. There is no limit to the number of nested statements that can be created in CFL. It is considered good syntax to index nested IF's so that they can be easily followed. There is no limit to the number of nested statements that can be created in CFL.
  
-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 332: Line 477:
 </code> </code>
  
-LOOPING OPERATIONS+==== LOOPING OPERATIONS ====
  
-FOR+=== FOR ===
  
 Use **For**  statements to create a loop that that executes a fixed number of times. This is most often used for looping through child items, parts, or modifiers on a line item. Use **For**  statements to create a loop that that executes a fixed number of times. This is most often used for looping through child items, parts, or modifiers on a line item.
Line 368: Line 513:
 //// This is some helpful code to put in the products warning message //// This is some helpful code to put in the products warning message
 Declare i; Declare i;
-Declare S : ''; +Declare S :''; 
-FOR i : 0 TO Parts.SonCount-1 DO + 
-  IF (Parts[i].TrackInventory  "True")+FOR i :0 TO Parts.SonCount-1 DO 
 +  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 "
                + ToString(Parts[i].YellowNotificationPoint )                + ToString(Parts[i].YellowNotificationPoint )
   ELSE ""   ELSE ""
   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 390: Line 537:
 // Additional CFL can be embedded as needed, you can use IF statements and other things to filter the results that appear. // Additional CFL can be embedded as needed, you can use IF statements and other things to filter the results that appear.
 Declare i; Declare i;
-Declare S : ''; +Declare S :''; 
-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+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
 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 400: Line 550:
 The increasing FOR statement can be rewritten using a WHILE loop as follows: The increasing FOR statement can be rewritten using a WHILE loop as follows:
  
-''variable : startingnumber; WHILE variable ''+<code> 
 +variable :startingnumber; 
 +WHILE variable <= endingnumber DO 
 +  ExpressionBlock; 
 +  variable := variable + increment; 
 +ENDWHILE 
 +</code>
  
-----+==== 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. 
 + 
 +<code> 
 +REPEAT 
 +  ExpressionBlock ; 
 +UNTIL (condition) [MAXCOUNT = maxloops]; 
 +</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. 
 + \\ An example of the WHILE statement follows: '' WHILE (condition) [MAXCOUNT = maxloops] DO ExpressionBlock ; ENDWHILE; '' '''' 
 + 
 +''''''''
  
 ---- ----
 +
 +''''''''
 +
 +''''
 +
 +''''
 +
 +''''
 +
 +''''
 +
 +''''
  
 \\ \\