Differences
This shows you the differences between two versions of the page.
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. '' | + | A **single-line comment** is created by typing in two slashes (//). Comments go at the end of a line of 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 229: | Line 231: | ||
|2nd Highest||Unary||+, | |2nd Highest||Unary||+, | ||
|3rd Highest||Units||Per, | |3rd Highest||Units||Per, | ||
- | |Exponentiation||\^ | + | |Exponentiation||\^ |
- | |Multiplicative||*, | + | |Multiplicative||*, |
|3rd Lowest||Additive||+, | |3rd Lowest||Additive||+, | ||
|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.\\ | + | < |
- | * 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 |
- | \\ | + | </ |
- | Area : Height * Width ; // Does not require | + | |
- | 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 …// | + | < |
- | IF Height > 5 Feet*Feet THEN … // and here\\ | + | 3 * 4 / 5 * 0 |
- | IF Height in SqFeet > 5 THEN …//here a different | + | </ |
- | 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 " | + | **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 " |
- | 9 SqFeet : 3 Feet * 3 Feet ; // | + | |
- | 9 SqFeet : 9 Feet*Feet ; // Alternate Form\\ | + | < |
- | 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 | + | 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 := " |
- | 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 …\\ | + | </ |
- | ElapsedTime : Distance / 12 miles PER hour ;\\ | + | |
- | ElapsedTime : Distance IN Miles / 12 PER hour ;\\ | + | Note that the assignment operator is the colon-equals, |
- | \\ | + | 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, | + | < |
+ | // First, define our local object reference variables | ||
+ | Declare Referral := ' | ||
+ | Declare Salesperson := ' | ||
+ | |||
+ | // Assign the ' | ||
+ | IF TransactionUDFIsAssigned(' | ||
+ | Referral := TransactionUDFObject(' | ||
+ | ENDIF; | ||
+ | |||
+ | // Assign the referring Sales person | ||
+ | Salesperson := Referral.Company.Salesperson1.IDAsString; | ||
+ | SetTransactionUDFObjectID( " | ||
+ | |||
+ | // Output referral and salesperson | ||
+ | Referral + " | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | **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. | ||
+ | < | ||
+ | Declare WorkingPrice := Area in SqFeet * 5; | ||
+ | MaxSize := IF ( Height <3 SqMeters | ||
+ | THEN 500 millimeters | ||
+ | ELSE 0.95 meters | ||
+ | ENDIF ; | ||
+ | Declare TooBig := ( MaxSize*MaxSize> | ||
+ | IF ( 12 inches = 1 foot ) THEN " | ||
+ | ELSE " | ||
+ | </ | ||
+ | |||
+ | |||
+ | Here are some simple rules to remember about using units: | ||
+ | |||
+ | | ||
+ | * 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. | ||
+ | |||
+ | < | ||
+ | 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 …// | ||
+ | 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 | ||
+ | </ | ||
+ | |||
+ | * 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 " | ||
+ | |||
+ | < | ||
+ | 9 SqFeet : 3 Feet * 3 Feet ; //Standard \Form | ||
+ | 9 SqFeet : 9 Feet*Feet ; // Alternate | ||
+ | 27 CuFeet : 3 Feet * 3 Feet * 3 Feet; // | ||
+ | 27 CuFeet : 27 Feet*Feet*Feet ; // Alternate \Form | ||
+ | </ | ||
+ | |||
+ | * 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. | ||
+ | |||
+ | < | ||
+ | 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 ; | ||
+ | </ | ||
+ | |||
+ | The units defined in CFL include the following: | ||
+ | |||
+ | |**Measure** ||**Unit** ||**Accepted Abbreviations** || | ||
+ | |Area||Square Centimeter||SqCentimeter, | ||
+ | |Area||Square Foot||SqFoot, | ||
+ | |Area||Square Inch||SqInch, | ||
+ | |Area||Square Meter||SqMeter, | ||
+ | |Area||Square Millimeter||SqMillimeter, | ||
+ | |Area||Square Yard||SqYard, | ||
+ | |Discrete||(none)||N/ | ||
+ | |Discrete||Each||Each|| | ||
+ | |Discrete||Impression||Impression, | ||
+ | |Discrete||Page||Page, | ||
+ | |Discrete||Piece||Piece, | ||
+ | |Discrete||Sheet||Sheet, | ||
+ | |Length||Centimeter||Centimeter, | ||
+ | |Length||Foot||Foot, | ||
+ | |Length||Inch||Inch, | ||
+ | |Length||Meter||Meter, | ||
+ | |Length||Millimeter||Millimeter, | ||
+ | |Length||Yard||Yard, | ||
+ | |Time||Day||Day, | ||
+ | |Time||Hour||Hour, | ||
+ | |Time||Minute||Minute, | ||
+ | |Time||Second||Second, | ||
+ | |Volume||Cubic Centimeter||CuCentimeter, | ||
+ | |Volume||Cubic Foot||CuFoot, | ||
+ | |Volume||Cubic Inch||CuInch, | ||
+ | |Volume||Cubic Meter||CuMeter, | ||
+ | |Volume||Cubic Millimeter||CuMillimeter, | ||
+ | |Volume||Cubic Yard||CuYard, | ||
+ | |Volume||Cup||Cup, | ||
+ | |Volume||Gallon||Gallon, | ||
+ | |Volume||Liter||Liter, | ||
+ | |Volume||Milliliter||Milliliter, | ||
+ | |Volume||Pint||Pint, | ||
+ | |Volume||Quart||Quart, | ||
+ | |Weight||FluidOunce||FluidOunce, | ||
+ | |Weight||Gram||Gram, | ||
+ | |Weight||Kilogram||Kilogram, | ||
+ | |Weight||Milligram||Milligram, | ||
+ | |Weight||Ounce||Ounce, | ||
+ | |Weight||Pound||Pound, | ||
+ | |Weight||Ton||Ton, | ||
+ | |||
+ | 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** | ||
+ | |||
+ | < | ||
+ | IF condition THEN | ||
+ | TrueExpression ; | ||
+ | ELSE | ||
+ | FalseExpression ; | ||
+ | ENDIF | ||
+ | </ | ||
+ | |||
+ | Translation: | ||
+ | |||
+ | < | ||
+ | IF (Height> SheetHeight) or (Width> SheetWidth) | ||
+ | THEN PiecesPerSheet := 0 ; | ||
+ | ELSE Declare SheetsHigh | ||
+ | Declare SheetsAcross | ||
+ | PiecesPerSheet := SheetsHigh * SheetsAcross ; | ||
+ | ENDIF ; | ||
+ | // Now return PiecesPerSheet as our Answer | ||
+ | PiecesPerSheet ; | ||
+ | </ | ||
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** |
< | < | ||
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** | ||
- | 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: | ||
< | < | ||
CASE [ TestExpression | CASE [ TestExpression | ||
Line 332: | Line 477: | ||
</ | </ | ||
- | LOOPING OPERATIONS | + | ==== LOOPING OPERATIONS |
- | FOR | + | === FOR === |
Use **For** | Use **For** | ||
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 | + | FOR i := 0 TO Parts.SonCount-1 DO |
+ | IF (Parts[i].TrackInventory | ||
AND (Parts[i].QuantityAvailable < | AND (Parts[i].QuantityAvailable < | ||
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/ | // The value of any CFL statement is the value of the last computation/ | ||
// 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; | ||
</ | </ | ||
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 | ||
+ | ExpressionBlock; | ||
+ | variable := variable + increment; | ||
+ | ENDWHILE | ||
+ | </ | ||
- | ---- | + | ==== REPEAT UNTIL ==== |
- | '' | + | Use **REPEAT** |
+ | |||
+ | < | ||
+ | REPEAT | ||
+ | ExpressionBlock ; | ||
+ | UNTIL (condition) [MAXCOUNT = maxloops]; | ||
+ | </ | ||
+ | |||
+ | 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: '' | ||
+ | |||
+ | '''''' | ||
---- | ---- | ||
+ | |||
+ | '''''''' | ||
+ | |||
+ | '''' | ||
+ | |||
+ | '''' | ||
+ | |||
+ | '''' | ||
+ | |||
+ | '''' | ||
+ | |||
+ | '''' | ||
\\ | \\ | ||