Subversion Repositories wimsdev

Rev

Rev 32 | Rev 1978 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
32 reyssat 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
1091 bpr 5
$(ref1)cmdlist_eval_&+cmd_choose=all$(ref2)cmdlist_eval_">!eval</a>.
32 reyssat 6
<p>
7
A variable may be defined or modified in a variable processing file, or by
8
the commands
1091 bpr 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>.
32 reyssat 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>
1091 bpr 52
  </center> <li><p>If the character $emph$$$emphend is followed by the left bracket
32 reyssat 53
  $emph[$emphend, the matching $emph]$emphend will be located, the content
54
  of the pair of brackets substituted then evaluated to a real number value whose
55
  precision depends on the value of $emph print_precision$emphend.
56
  This value will replace the whole thing
57
  together with the leading $emph$$$emphend. <br>
58
  It can be used for array subscripts.
59
  <br>Example: if the variable $(emph)i$emphend has value $(emph)3$emphend
60
  and the variables <br>
61
  $(emph)a1$emphend has value $(emph)3$emphend and <br>
62
  $(emph)a2$emphend has value $(emph)pi$emphend, <br>
63
  then the string<pre>
64
  $$(a$$[$$i-1])*x+$$(a$$[$$i-2])</pre>will become<pre>
65
  pi*x+3</pre>after substitution.
66
 <li>If the value of a variable being substituted contains the character
67
  $emph$$$emphend, this value will again be substituted, until no more
68
  substitution is needed. The server has a built-in limit of nested
69
  substitutions; infinite nested substitions will violate this limit and
70
  generate an error message.
71
</ul>
72
 
73
<hr><h4>Reserved variable names</h4>
74
 
75
The following names are reserved for their special meanings. They should not be
76
used for internal needs of any module.
77
 
78
<ul>
79
 <li>Do not use variables with names consisting only of numbers. They are
80
  reserved for future enhancements of the language.
81
 <li>Variables named
82
  !for i in cmd,module,session,lang,special_parm,user,useropts,worksheet
83
   $emph$i$emphend,
84
  !next i
85
  are reserved for special parameter passing by the user. A module's variable
86
  processing files or phtml files can read but cannot set them. <br>
87
  Refer to the section $emph$title_structure$emphend for the meaning of
88
  these variables.
89
 <li>The variable $emph no_name$emphend has a special use: <br>
90
  Parameters in the user query string with no name (for example when the
91
  coordinate of a mappable image is passed this way to the http server) will
92
  be registered under this variable. For this reason, it should not be used
93
  for other purposes.
94
 <li>All variable names starting with $emph wims_$emphend will have special
95
  meanings for wims server. A module should read or write them only for the
96
  special meanings they are designed for.
97
 <li>Variable names starting with $emph m_$emphend are reserved for inline
98
  mathematical fonts. The module programmer may redefine them, but then their
99
  original meaning will be lost.
100
 <li>The variable $emph module_dir$emphend has a value preset to the directory
101
  of the current module (with respect to the public home directory of the
102
  server). This value is usually $emph $$module_dir=module/$$module $emphend
103
  (but may vary with the config of the installation).
104
 <li>Variable names starting with $emph module_$emphend will have special
105
  meanings: they are used to hold variables defined in the module's INDEX
106
  file. Currently implemented variables:
107
  <center><table border=0 cellspacing=10>
1091 bpr 108
   <tr><td>$emph module_title$emphend<td>title of the module
109
   <tr><td>$emph module_description$emphend<td>short description of the module
110
   <tr><td>$emph module_author$emphend<td>name(s) of author(s) of the module
111
   <tr><td>$emph module_address$emphend<td>e-mail address of the (principal) author
112
   <tr><td>$emph module_copyright$emphend<td>copyright notice of the module
113
   <tr><td>$emph module_version$emphend<td>current version of the module
114
   <tr><td>$emph module_wims_version$emphend<td>minimal wims version required<br>
32 reyssat 115
        to run this module
1091 bpr 116
   <tr><td>$emph module_language$emphend<td>language of the module<br>(en, fr, de, or ...)
117
   <tr><td>$emph module_category$emphend<td>category of the module<br>
32 reyssat 118
        (exercise, tool, course, pedia, recreation, adm, other)
1091 bpr 119
   <tr><td>$emph module_level$emphend<td>level of the module
120
   <tr><td>$emph module_domain$emphend<td>algebra, analysis, geometry, ...
121
   <tr><td>$emph module_keywords$emphend<td>keywords, to be placed in the html header
122
   <tr><td>$emph module_scoring$emphend<td>= yes if the module gives scores according
32 reyssat 123
        to wims standard
124
  </table></center>
125
  Also, variables $emph module_has_intro$emphend,
126
  $emph module_has_help$emphend and
127
  $emph module_has_about$emphend
128
  have value "yes" if the module's directory contains the respective
129
  .phtml file. These variables are used in the command <tt>!homeref</tt>.
130
 <li>Certain environment variables setup by httpd are readable by wims
131
  modules under names starting with $emph httpd_$emphend. For example, the
132
  environment variable $emph REMOTE_HOST$emphend becomes
133
  $emph httpd_REMOTE_HOST$emphend under wims. <br>
134
  Please refer to httpd protocol specifications for details of such variables.
135
 <li>All variable names starting with $emph ins_$emphend, $emph
136
  insplot_$emphend, $emph instex_$emphend will have special meanings for the
137
  corresponding dynamic insertion engines. A module should read or write them
138
  only for the special meanings they are designed for.
139
 <li>If your module uses an external package (e.g. $emph pari$emphend),
140
  variable names starting with the name of the interface to that external
141
  package followed by $emph _$emphend will have special meanings for that
142
  interface, and should be reserved for that purpose.
143
</ul>
144