User Tools

Site Tools


en:cachevariables

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:cachevariables [2022/02/22 10:09] – [Variable section] lineflyeren:cachevariables [2022/11/25 11:58] (current) – [Range expressions] New syntax for range expressions lineflyer
Line 1: Line 1:
-**FIXME** This will be used to describe the new tab on cache details used for cache variables. 
- 
-**FIXME** We could add a chapter with some practical How-To examples (e.g. typical lettervalue case) 
- 
 ====== Cache Variables ====== ====== Cache Variables ======
  
Line 38: Line 34:
  
 ^ Button ^ Action ^ ^ Button ^ Action ^
-|{{:en:cachevariables_variable.png?nolink&200|}}|Click on the variable name to change it.| +|{{:en:cachevariables_variable.png?nolink&30|}}|Click on the variable name to change it.| 
-|{{:en:cachevariables_functions.png?nolink&200|}}|Click on the "function" button to prefill the value field with the desired [[.:cachevariables#functions|supported function]].|+|{{:en:cachevariables_functions.png?nolink&30|}}|Click on the "function" button to prefill the value field with the desired [[.:cachevariables#functions|supported function]].|
 |{{:en:cachevariables_value.png?nolink&200|}}|Fill in the value field manually with a value or some formula using the [[.:cachevariables#formula_syntax|formula syntax]].| |{{:en:cachevariables_value.png?nolink&200|}}|Fill in the value field manually with a value or some formula using the [[.:cachevariables#formula_syntax|formula syntax]].|
-|{{:en:cachevariables_delete.png?nolink&200|}}|Use the trash can icon to delete the variable.|+|{{:en:cachevariables_delete.png?nolink&50|}}|Use the trash can icon to delete the variable.|
  
 The text below the value field will show a result preview. This can either be the concrete result of the formula or hints regarding syntax errors or missing values. The text below the value field will show a result preview. This can either be the concrete result of the formula or hints regarding syntax errors or missing values.
Line 55: Line 51:
  
 The syntax will be explained in detail in the following sub-chapters.  The syntax will be explained in detail in the following sub-chapters. 
-However as a quick overview or syntax reminder about what is supported, you will find a list of examples here:+However as a quick overview about what is supported, you will find a list of examples here:
  
   * ''2*2+3'' will evaluate to ''7''   * ''2*2+3'' will evaluate to ''7''
   * ''2*(2+3)'' will evaluate to ''10''   * ''2*(2+3)'' will evaluate to ''10''
   * ''3*sin(90)'' will evaluate to ''3''   * ''3*sin(90)'' will evaluate to ''3''
 +
   * ''4+length('test')'' will evaluate to ''8''   * ''4+length('test')'' will evaluate to ''8''
   * ''rot13('abc')'' will evaluate to ''nop''   * ''rot13('abc')'' will evaluate to ''nop''
 +  * ''lettervalue('cache')'' will evaluate to ''20''
 +  * ''checksum(lettervalue('cache'))'' will evaluate to ''2''
 +
   * ''A + A*2'' with ''A=3'' will evaluate to ''9''   * ''A + A*2'' with ''A=3'' will evaluate to ''9''
   * ''AA(A+1)'' with ''A=3'' will evaluate to ''334''   * ''AA(A+1)'' with ''A=3'' will evaluate to ''334''
Line 68: Line 68:
   * ''${hello}8A'' with ''A=3'' and ''hello=24'' will evaluate to ''2483''   * ''${hello}8A'' with ''A=3'' and ''hello=24'' will evaluate to ''2483''
  
-**FIXME** Add wordvalue to examples 
  
-**FIXME** Aren't some of the examples to complex (or might need interim steps written down) to understand?+
 ==== Value types ==== ==== Value types ====
  
Line 79: Line 78:
 |Integer | Number without decimal places | Use digits | ''1234'', ''-3''| |Integer | Number without decimal places | Use digits | ''1234'', ''-3''|
 |Decimal | Number with decimal places | Use digits with decimal point or comma | ''3.14'', ''-3.14'', ''3,14''| |Decimal | Number with decimal places | Use digits with decimal point or comma | ''3.14'', ''-3.14'', ''3,14''|
-|String | Text | Surround value with '' ''' or ''"''\\  To use the '' ' '' or '' " '' their selves, type '' **FIXME** '' or '' "" ''| '' 'test''', ''"test"''\\ ''"He said ""yes""!"''|+|String | Text | Surround value with ''%%'%%'' or ''%%"%%''\\  To use the ''%%'...'%%'' or ''%%"..."%%'' their selves, type ''%%''%%'' or ''%%""%%''| ''%%'test'%%'', ''%%"test"%%''\\ ''"He said ""yes""!"''|
  
-**FIXME** using monotext does not work for ' in this table as its also part of the monotext syntax in Dokuwiki. :( 
  
 ==== Numeric operators ==== ==== Numeric operators ====
Line 88: Line 86:
  
 ^ Operator ^ Function ^ Example ^ ^ Operator ^ Function ^ Example ^
-|+|Addition|''2+4'' evaluates to '' 6''+|''+''|Addition|''2+4'' evaluates to '' 6''
-|-|Subtraction (or negating a number)|''6-4'' evaluates to ''2''\\ ''-(5-2)'' evaluates to ''-3''+|''-''|Subtraction\\ (or negating a number)|''6-4'' evaluates to ''2''\\ ''-(5-2)'' evaluates to ''-3''
-|*|Multiplication|''3*4'' evaluates to ''12''+|''*''|Multiplication|''3*4'' evaluates to ''12''
-|/|Division|''12/3'' evaluates to ''4''+|''/''|Division|''12/3'' evaluates to ''4''
-|%|Modulo|''12%5'' evaluates to ''2''+|''%''|Modulo|''12%5'' evaluates to ''2''
-|**FIXME**|Potentiate|''3^3'' evaluates to ''9''+|''^''|Potentiate|''3^3'' evaluates to ''27''
-|!|Factorize|''4!'' evaluates to ''24''|+|''!''|Factorize|''4!'' evaluates to ''24''|
  
 ==== Relational operators and conditions ==== ==== Relational operators and conditions ====
Line 111: Line 109:
 * Else the fifth parameter is returned * Else the fifth parameter is returned
  
-For example ''if(A==5;50;A==4;40;30)'' will evaluate to ''50'' if ''A=50'', to ''40'' if ''A=4'' and to ''30'' for any other value of ''A''.+For example ''if(A==5;50;A==4;40;30)'' will evaluate to ''50'' if ''A=5'', to ''40'' if ''A=4'' and to ''30'' for any other value of ''A''.
  
 ^ Operator ^ Meaning ^ Example ^ ^ Operator ^ Meaning ^ Example ^
Line 129: Line 127:
 The following functions are defined: The following functions are defined:
  
-^ Function ^ Synonyms ^ Description ^ Parameter1 ^ Parameter 2 ^ Example ^+^ Function ^ Synonyms ^ Description ^ Parameter 1 ^ Parameter 2 ^ Example ^
 |''sqrt''|-|calculates square root of given parameter|numeric parameter| - |''sqrt(9)'' evaluates to ''3''| |''sqrt''|-|calculates square root of given parameter|numeric parameter| - |''sqrt(9)'' evaluates to ''3''|
 |''sin''/''cos''/''tan'' |-| calculates sinus/cosinus/tangens of given parameter | numeric parameter in degree(!)| - | ''sin(90)'' evaluates to ''1''| |''sin''/''cos''/''tan'' |-| calculates sinus/cosinus/tangens of given parameter | numeric parameter in degree(!)| - | ''sin(90)'' evaluates to ''1''|
 |''abs''|-| calculates absolute value | numeric parameter | - | ''abs(-34)'' evaluates to ''34''| |''abs''|-| calculates absolute value | numeric parameter | - | ''abs(-34)'' evaluates to ''34''|
-|''round''|-| rounds decimal values mathematically | value to round | optional: number of places to round to | ''round(4.65)'' evaluates to ''5'', ''round(4.65; 1)'' evaluates to ''4.7''|+|''round''|-| rounds decimal values mathematically | value to round | optional: number of places to round to | ''round(4.65)'' evaluates to ''5'', ''round(4.65;1)'' evaluates to ''4.7''
 +|''trunc''|-| Truncates decimal values to the (optional) provided number of places | value to truncate | optional: Number of places to remain after truncation (default:0) | ''trunc(123.456)'' evaluates to ''123'', ''trunc(123.456;2)'' evaluates to ''123.45'' |
 |''if''|-| evaluates conditions and returns conditional values | list of if-then-else-values. See previous section for details | - | ''if(3<4;5;6)'' evaluates to ''5''| |''if''|-| evaluates conditions and returns conditional values | list of if-then-else-values. See previous section for details | - | ''if(3<4;5;6)'' evaluates to ''5''|
 |''checksum''|''cs''| calculates checksum of given numeric value. Calculates lettervalue if given paramter is of type text | positive integer or text | - | ''checksum(345)'' evaluates to ''12''| |''checksum''|''cs''| calculates checksum of given numeric value. Calculates lettervalue if given paramter is of type text | positive integer or text | - | ''checksum(345)'' evaluates to ''12''|
Line 142: Line 141:
 |''roman''|-| scans a given string value as a roman number and returns its decimal value | string | - | ''roman('VI')'' evaluates to ''6''.| |''roman''|-| scans a given string value as a roman number and returns its decimal value | string | - | ''roman('VI')'' evaluates to ''6''.|
 |''vanity''|''vanitycode'', ''vc''| returns the vanity code of a string | string | - | ''vanity('cgeo')'' evaluates to ''2436''.| |''vanity''|''vanitycode'', ''vc''| returns the vanity code of a string | string | - | ''vanity('cgeo')'' evaluates to ''2436''.|
- 
  
 ==== Variables ==== ==== Variables ====
Line 183: Line 181:
   * The Formula ''1_A'' with ''A=2'' will evaluate to ''102''   * The Formula ''1_A'' with ''A=2'' will evaluate to ''102''
   * The Formula ''1_A'' with ''A=23'' will evaluate to ''123''   * The Formula ''1_A'' with ''A=23'' will evaluate to ''123''
-  * The Formula ''1__A'' with ''A=23'' will evaluate to ''1023'' +  * The Formula ''%%1__A%%'' with ''A=23'' will evaluate to ''1023'' 
-  * The Formula ''1__A'' with ''A=234'' will evaluate to ''1234''+  * The Formula ''%%1__%%A'' with ''A=234'' will evaluate to ''1234'' 
  
-**FIXME** Double underscore is interpreted as underline by Dokuwiki 
 ==== Range expressions ==== ==== Range expressions ====
  
-You can specify ranges in formulas using ''[]''. This is needed when variables are used in a context where a range of values should be iterated over. A prominent example is the "Generate Waypointsfunction.+You can specify ranges in formulas using ''[:]''. This is needed when variables are used in a context where a range of values should be iterated over. A prominent example is the [[.:waypointcalculator|Generate Waypoints]] function.
  
-An example for a range expression is ''[0-9]''. This specifies a range with 10 values (the integer values 0 to 9).+**FIXME** Link to anchor on waypoint calc page as soon as its updated to cover waypoint generation with ranges. 
 + 
 +An example for a range expression is ''[:0-9]''. This specifies a range with 10 values (the integer values 0 to 9).
  
 You may specify consecutive values using '','' as a delimiter. You may exclude values or value ranges by prepending a ''^'' to it. Ranges are parsed from left-to-right, giving an order to the elements in the range. For example the following are valid range specifications: You may specify consecutive values using '','' as a delimiter. You may exclude values or value ranges by prepending a ''^'' to it. Ranges are parsed from left-to-right, giving an order to the elements in the range. For example the following are valid range specifications:
-  * ''[0-2, 4]'' evaluates to a range containing ''0'', ''1'', ''2'' and ''4''+  * ''[:0-2, 4]'' evaluates to a range containing ''0'', ''1'', ''2'' and ''4''
-  * ''[0-3, ^1-2]'' evaluates to a range containing ''0'' and ''3''+  * ''[:0-3, ^1-2]'' evaluates to a range containing ''0'' and ''3''
-  * ''[0-3, ^1-2, 5]'' evaluates to a range containing ''0'', ''3'' and ''5''.+  * ''[:0-3, ^1-2, 5]'' evaluates to a range containing ''0'', ''3'' and ''5''.
  
-When a range is used in a context where only one value is allowed (this is the case in normal calculation), the first range value is used for calculation. For example, the expression ''[8, 0-9]'' will evalulate to ''0'' in a normal calculation context, while ''[8, 0-9]'' will evalulate to ''8''.+When a range is used in a context where only one value is allowed (this is the case in normal calculation), the first range value is used for calculation. For example, the expression ''[:0-9]'' will evaluate to ''0'' in a normal calculation context, while ''[:8, 0-9]'' will evaluate to ''8''.
  
 Ranges currently support only positive constant integer values. A range must always be evaluate to at least 1 value and a range may not evaluate to more than 20 values. For example the following ranges are invalid: Ranges currently support only positive constant integer values. A range must always be evaluate to at least 1 value and a range may not evaluate to more than 20 values. For example the following ranges are invalid:
-  * ''[]'': empty +  * ''[:]'': empty 
-  * ''[5, ^0-9]'': evaluates to empty +  * ''[:5, ^0-9]'': evaluates to empty 
-  * ''[0-1000]'': evaluates to more than 20 entries +  * ''[:0-1000]'': evaluates to more than 20 entries 
-  * ''[-5]'': negative int not allowed +  * ''[:-5]'': negative int not allowed 
-  * ''[A]'': variables not allowed+  * ''[:A]'': variables not allowed
  
 A formula may include one or more range definitions mixed with normal other formula parts. For example the following formulas are valid: A formula may include one or more range definitions mixed with normal other formula parts. For example the following formulas are valid:
-  * ''3*[0-2]'': evaluates to values ''0'', ''3'' and ''6'' +  * ''3*[:0-2]'': evaluates to values ''0'', ''3'' and ''6'' 
-  * ''A*[4, 7]'': for ''A=3'' this evaluates to values ''12'' and ''21'' +  * ''A*[:4, 7]'': for ''A=3'' this evaluates to values ''12'' and ''21'' 
-  * ''[1-2]*[3-4]'': evaluates to ''3'', ''6'', ''4'' and ''8''.+  * ''[:1-2]*[:3-4]'': evaluates to ''3'', ''6'', ''4'' and ''8''. 
 + 
 + 
 +==== Comments ==== 
 + 
 +You may enter comments into formula expressions using the ''#'' character. Comments end at next ''#'' or at end of expressions. Everything in a comment is ignored during evaluation. For example: 
 +  * ''A * 5 # test comment'' for ''A=3'' evaluates to ''15'' 
 +  * ''3.14 # this is pi # * 2 # and this is two'' evaluates to ''6.28''
en/cachevariables.1645520987.txt.gz · Last modified: 2022/02/22 10:09 by lineflyer