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