Subversion Repositories wimsdev

Rev

Rev 1091 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <h4>Definition and substitution of variables</h4>
  2.  
  3. Wims variables has only one type: they are all string variables. Numerical
  4. evaluation can be done on variables via the variable command
  5. $(ref1)cmdlist_eval_&cmd_choose=all$(ref2)cmdlist_eval_>!eval</a>.
  6. <p>
  7. A variable may be defined or modified in a variable processing file, or by
  8. the commands
  9. $(ref1)cmdlist_let_&cmd_choose=all$(ref2)cmdlist_let_>!let</a> and
  10. $(ref1)cmdlist_default_&cmd_choose=all$(ref2)cmdlist_default_>!default</a>.
  11. <p>
  12. Variable names can contain any alphanumeric character, as well as the
  13. underscore character $(emph)_$emphend. There is a limit to the length of
  14. variable names, and a limit to the length of values. (Limits depending on
  15. server configuration.)
  16. <p>
  17. Variable substitution can be done anywhere in a variable processing file or
  18. a phtml file (even in the name field of a variable definition
  19. line). A word preceeded by the character $emph$$$emphend
  20. is considered to be a variable name, and will be replaced by its value when
  21. the line containing it is processed.
  22. <p>
  23. Special rules of variable substitution:
  24. <ul>
  25.  <li>If the character $emph$$$emphend is followed by a space, it will be
  26.   discarded.
  27.  <li>The string $emph$$$$$emphend is replaced by a single $emph$$$emphend.
  28.  <li>If the character $emph$$$emphend is followed by the left parenthesis
  29.   $emph($emphend, the matching $emph)$emphend will be located, the content
  30.   of the pair of parentheses substituted. The result of the substitution
  31.   will then be used as the name of variable, and finally the whole thing
  32.   will be replaced by the value of the last variable. This allows nested
  33.   substitutions, as well as substitution of a variable which is followed
  34.   by an alphanumeric character.
  35.   <br>Example: if the variable $(emph)i$emphend has value $(emph)3$emphend
  36.   and the variable $(emph)alpha3beta$emphend has value $(emph)pi$emphend,
  37.   the string<pre>
  38.   3*$$(alpha$$(i)beta)*x</pre>will become<pre>
  39.   3*pi*x</pre>after substitution.
  40.   <p>
  41.   Array addressing: if the variable $(emph)l$emphend contains a
  42.   comma-separated list $(emph)a,b,c,d,e$emphend, then the string
  43.   <tt>$$(i[3])</tt> gives <tt>c</tt> after substitution, and
  44.   <tt>$$(i[2 to 4])</tt> tives <tt>b,c,d</tt>, etc.
  45.   <p>
  46.   Two-dimensional array addressing is also available: if
  47.   <p><center><tt>$$M=x,y,z;a,b,c</tt>
  48.   </center> <p>
  49.   (a 2x3 matrix), then
  50.   <p><center>
  51.   <tt> $$(M[1;3,2])=z,y </tt>
  52.   </center> <p>
  53.  <li>If the character $emph$$$emphend is followed by the left bracket
  54.   $emph[$emphend, the matching $emph]$emphend will be located, the content
  55.   of the pair of brackets substituted then evaluated to a real number value whose
  56.   precision depends on the value of $emph print_precision$emphend.
  57.   This value will replace the whole thing
  58.   together with the leading $emph$$$emphend. <br>
  59.   It can be used for array subscripts.
  60.   <br>Example: if the variable $(emph)i$emphend has value $(emph)3$emphend
  61.   and the variables <br>
  62.   $(emph)a1$emphend has value $(emph)3$emphend and <br>
  63.   $(emph)a2$emphend has value $(emph)pi$emphend, <br>
  64.   then the string<pre>
  65.   $$(a$$[$$i-1])*x+$$(a$$[$$i-2])</pre>will become<pre>
  66.   pi*x+3</pre>after substitution.
  67.  <li>If the value of a variable being substituted contains the character
  68.   $emph$$$emphend, this value will again be substituted, until no more
  69.   substitution is needed. The server has a built-in limit of nested
  70.   substitutions; infinite nested substitions will violate this limit and
  71.   generate an error message.
  72. </ul>
  73.  
  74. <hr><h4>Reserved variable names</h4>
  75.  
  76. The following names are reserved for their special meanings. They should not be
  77. used for internal needs of any module.
  78.  
  79. <ul>
  80.  <li>Do not use variables with names consisting only of numbers. They are
  81.   reserved for future enhancements of the language.
  82.  <li>Variables named
  83.   !for i in cmd,module,session,lang,special_parm,user,useropts,worksheet
  84.    $emph$i$emphend,
  85.   !next i
  86.   are reserved for special parameter passing by the user. A module's variable
  87.  processing files or phtml files can read but cannot set them. <br>
  88.  Refer to the section $emph$title_structure$emphend for the meaning of
  89.  these variables.
  90. <li>The variable $emph no_name$emphend has a special use: <br>
  91.  Parameters in the user query string with no name (for example when the
  92.  coordinate of a mappable image is passed this way to the http server) will
  93.  be registered under this variable. For this reason, it should not be used
  94.  for other purposes.
  95. <li>All variable names starting with $emph wims_$emphend will have special
  96.  meanings for wims server. A module should read or write them only for the
  97.  special meanings they are designed for.
  98. <li>Variable names starting with $emph m_$emphend are reserved for inline
  99.  mathematical fonts. The module programmer may redefine them, but then their
  100.  original meaning will be lost.
  101. <li>The variable $emph module_dir$emphend has a value preset to the directory
  102.  of the current module (with respect to the public home directory of the
  103.  server). This value is usually $emph $$module_dir=module/$$module $emphend
  104.  (but may vary with the config of the installation).
  105. <li>Variable names starting with $emph module_$emphend will have special
  106.  meanings: they are used to hold variables defined in the module's INDEX
  107.   file. Currently implemented variables:
  108.   <center><table border=0 cellspacing=10>
  109.    <tr><td>$emph module_title<td>title of the module
  110.    <tr><td>$emph module_description<td>short description of the module
  111.    <tr><td>$emph module_author<td>name(s) of author(s) of the module
  112.    <tr><td>$emph module_address<td>e-mail address of the (principal) author
  113.    <tr><td>$emph module_copyright<td>copyright notice of the module
  114.    <tr><td>$emph module_version<td>current version of the module
  115.    <tr><td>$emph module_wims_version<td>minimal wims version required<br>
  116.         to run this module
  117.    <tr><td>$emph module_language<td>language of the module<br>(en, fr, de, or ...)
  118.    <tr><td>$emph module_category<td>category of the module<br>
  119.         (exercise, tool, course, pedia, recreation, adm, other)
  120.    <tr><td>$emph module_level<td>level of the module
  121.    <tr><td>$emph module_domain<td>algebra, analysis, geometry, ...
  122.    <tr><td>$emph module_keywords<td>keywords, to be placed in the html header
  123.    <tr><td>$emph module_scoring<td>= yes if the module gives scores according
  124.         to wims standard
  125.   </table></center>
  126.   Also, variables $emph module_has_intro$emphend,
  127.   $emph module_has_help$emphend and
  128.   $emph module_has_about$emphend
  129.   have value "yes" if the module's directory contains the respective
  130.  .phtml file. These variables are used in the command <tt>!homeref</tt>.
  131. <li>Certain environment variables setup by httpd are readable by wims
  132.  modules under names starting with $emph httpd_$emphend. For example, the
  133.  environment variable $emph REMOTE_HOST$emphend becomes
  134.  $emph httpd_REMOTE_HOST$emphend under wims. <br>
  135.  Please refer to httpd protocol specifications for details of such variables.
  136. <li>All variable names starting with $emph ins_$emphend, $emph
  137.  insplot_$emphend, $emph instex_$emphend will have special meanings for the
  138.  corresponding dynamic insertion engines. A module should read or write them
  139.  only for the special meanings they are designed for.
  140. <li>If your module uses an external package (e.g. $emph pari$emphend),
  141.  variable names starting with the name of the interface to that external
  142.  package followed by $emph _$emphend will have special meanings for that
  143.  interface, and should be reserved for that purpose.
  144. </ul>
  145.  
  146.