Make the expression code a little nicer and fix bugs found
[pspp-builds.git] / TODO
1 Time-stamp: <2004-03-26 00:07:35 blp>
2
3 What Ben's working on now.
4 --------------------------
5
6 Procedures need to be able to make multiple passes.
7
8 Write a better descriptive stats evaluator based on NR two-pass technique,
9 revise all existing code to use it.
10
11 Update q2c input format description.
12
13 Rewrite output subsystem, break into multiple processes.
14
15 CROSSTABS needs to be re-examined.
16
17 TODO
18 ----
19
20 The expression tests need tests for XDATE and a few others, see
21 tests/xforms/expressions.sh comments for details.
22
23 Expressions need random distribution functions.
24
25 There needs to be another layer onto the lexer, which should probably be
26 entirely rewritten anyway.  The lexer needs to read entire *commands* at a
27 time, not just a *line* at a time.  It also needs to support arbitrary putback,
28 probably by just backing up the "current position" in the command buffer.
29
30 Scratch variables should not be available for use following TEMPORARY.
31
32 Details of N OF CASES, SAMPLE, FILTER, PROCESS IF, TEMPORARY, etc., need to be
33 checked against the documentation.  See notes on these at end of file for a
34 start.
35
36 Check our results against the NIST StRD benchmark results at
37 strd.itl.nist.gov/div898/strd
38
39 In debug mode hash table code should verify that collisions are reasonably low.
40
41 Use posix_fadvise(POSIX_FADV_SEQUENTIAL) where available.
42
43 Use AFM files instead of Groff font files, and include AFMs for our default
44 fonts with the distribution.
45
46 Add libplot output driver.  Suggested by Robert S. Maier
47 <rsm@math.arizona.edu>: "it produces output in idraw-editable PS format, PCL5
48 format, xfig-editable format, Illustrator format,..., and can draw vector
49 graphics on X11 displays also".
50
51 Storage of value labels on disk is inefficient.  Invent new data structure.
52
53 Add an output flag which would cause a page break if a table segment could fit
54 vertically on a page but it just happens to be positioned such that it won't.
55
56 Fix spanned joint cells, i.e., EDLEVEL on crosstabs.stat.
57
58 Cell footnotes.
59
60 PostScript driver should emit thin lines, then thick lines, to optimize time
61 and space.
62
63 New functions?  var_name_or_label(), tab_value_or_label()
64
65 Should be able to bottom-justify cells.  It'll be expensive, though, by
66 requiring an extra metrics call.
67
68 Perhaps instead of the current lines we should define the following line types:
69 null, thin, thick, double.  It might look pretty classy.
70
71 Perhaps thick table borders that are cut off by a page break should decay to
72 thin borders.  (i.e., on a thick bordered table that's longer than one page,
73 but narrow, the bottom border would be thin on the first page, and the top and
74 bottom borders on middle pages.)
75
76 Support multi-line titles on tables. (For the first page only, presumably.)
77
78 Rewrite the convert_F() function in data-out.c to be nicer code.
79
80 In addition to searching the source directory, we should search the current
81 directory (for data files).  (Yuck!)
82
83 Fix line-too-long problems in PostScript code, instead of covering them up.
84 setlinecap is *not* a proper solution.
85
86 Need a better way than MAX_WORKSPACE to detect low-memory conditions.
87
88 When malloc() returns 0, page to disk and free() unnecessary data.
89
90 Remove ccase * argument from procfunc argument to procedure().
91
92 See if process_active_file() has wider applicability.
93
94 Eliminate private data in struct variable through use of pointers.
95
96 Fix som_columns().
97
98 Has glob.c been pared down enough?
99
100 Improve interactivity of output by allowing a `commit' function for a page.
101 This will also allow for infinite-length pages.
102
103 All the tests need to be looked over.  Some of the SET calls don't make sense
104 any more.
105
106 Implement thin single lines, should be pretty easy now.
107
108 SELECT IF should be moved before other transformations whenever possible.  It
109 should only be impossible when one of the variables referred to in SELECT IF is
110 created or modified by a previous transformation.
111
112 The manual: add text, add index entries, add examples.
113
114 The inline file should be improved: There should be *real* detection of whether
115 it is used (in dfm.c:cmd_begin_data), not after-the-fact detection.
116
117 Figure out a stylesheet for messages displayed by PSPP: i.e., what quotation
118 marks around filenames, etc.
119
120 Data input and data output are currently arranged in reciprocal pairs: input is
121 done directly, with write_record() or whatever; output is done on a callback
122 event-driven basis.  It would definitely be easier if both could be done on a
123 direct basis, with read_record() and write_record() routines, with a coroutine
124 implementation (see Knuth).  But I'm not sure that coroutines can be
125 implemented in ANSI C.  This will require some thought.  Perhaps 0.4.0 can do
126 this.
127
128 New SET subcommand: OUTPUT.  i.e., SET OUTPUT="filename" to send output to that
129 file; SET OUTPUT="filename"(APPEND) to append to that file; SET OUTPUT=DEFAULT
130 to reset everything.  There might be a better approach, though--think about it.
131
132 HDF export capabilities (http://hdf.ncsa.uiuc.edu).  Suggested by Marcus
133 G. Daniels <mgd@santafe.edu>.
134
135 From Zvi Grauer <z.grauer@csuohio.edu> and <zvi@mail.ohio.net>:
136
137    1. design of experiments software, specifically Factorial, response surface
138    methodology and mixrture design.
139
140    These would be EXTREMELY USEFUL for chemists, engineeris, and anyone
141    involved in the production of chemicals or formulations.
142
143    2. Multidimensional Scaling analysis (for market analysis) -
144
145    3. Preference mapping software for market analysis
146
147    4. Hierarchical clustering (as well as partition clustering)
148
149    5. Conjoint analysis
150
151    6. Categorical data analsys ?
152
153 IDEAS
154 -----
155
156 In addition to an "infinite journal", we should keep a number of
157 individual-session journals, pspp.jnl-1 through pspp.jnl-X, renaming and
158 deleting as needed.  All of the journals should have date/time comments.
159
160 Qualifiers for variables giving type--categorical, ordinal, ...
161
162 Analysis Wizard
163
164 Consider consequences of xmalloc(), fail(), hcf() in interactive
165 use:
166 a. Can we safely just use setjmp()/longjmp()?
167 b. Will that leak memory?
168 i. I don't think so: all procedure-created memory is either
169 garbage-collected or globally-accessible.
170 ii. But you never know... esp. w/o Checker.
171 c. Is this too early to worry? too late?
172
173 Need to implement a shared buffer for funny functions that require relatively
174 large permanent transient buffers (1024 bytes or so), that is, buffers that are
175 permanent in the sense that they probably shouldn't be deallocated but are only
176 used from time to time, buffers that can't be allocated on the stack because
177 they are of variable and unpredictable but usually relatively small (usually
178 line buffers).  There are too many of these lurking around; can save a sizeable
179 amount of space at very little overhead and with very little effort by merging
180 them.
181
182 Clever multiplatform GUI idea (due partly to John Williams): write a GUI in
183 Java where each statistical procedure dialog box could be downloaded from the
184 server independently.  The statistical procedures would run on (the/a) server
185 and results would be reported through HTML tables viewed with the user's choice
186 of web browsers.  Help could be implemented through the browser as well.
187
188 Design a plotting API, with scatterplots, line plots, pie charts, barcharts,
189 Pareto plots, etc., as subclasses of the plot superclass.
190
191 HOWTOs
192 ------
193
194 1. How to add an operator for use in PSPP expressions:
195
196 a. Add the operator to the enumerated type at the top of expr.h.  If the
197 operator has arguments (i.e., it's not a terminal) then add it *before*
198 OP_TERMINAL; otherwise, add it *after* OP_TERMINAL.  All these begin with OP_.
199
200 b. If the operator's a terminal then you'll want to design a structure to hold
201 its content.  Add the structure to the union any_node.  (You can also reuse one
202 of the prefab structures, of course.)
203
204 c. Now switch to expr-prs.c--the module for expression parsing.  Insert the
205 operator somewhere in the precedence hierarchy.
206
207 (1) If you're adding a operator that is a function (like ACOS, ABS, etc.) then
208 add the function to functab in `void init_functab(void)'.  Order is not
209 important here.  The first element is the function name, like "ACOS".  The
210 second is the operator enumerator you added in expr.h, like OP_ARCOS.  The
211 third element is the C function to parse the PSPP function.  The predefined
212 functions will probably suit your needs, but if not, you can write your own.
213 The fourth element is an argument to the parsing function; it's only used
214 currently by generic_str_func(), which handles a rather general syntax for
215 functions that return strings; see the comment at the beginning of its code for
216 details.
217
218 (2) If you're adding an actual operator you'll have to put a function in
219 between two of the operators there already in functions `exprtype
220 parse_*(any_node **n)'.  Each of these stores the tree for its result into *n,
221 and returns the result type, or EX_ERROR on error.  Be sure to delete all the
222 allocated memory on error before returning.
223
224 d. Add the operator to the table `op_desc ops[OP_SENTINEL+1]' in expr-prs.c,
225 which has an entry for every operator.  These entries *must* be in the same
226 order as they are in expr.h.  The entries have the form `op(A,B,C,D)'.  A is
227 the name of the operator as it should be printed in a postfix output format.
228 For example, the addition operator is printed as `plus'.  B is a bitmapped set
229 of flags:
230
231 * Set the 001 bit (OP_VAR_ARGS) if the operator takes a variable number of
232 arguments.  If a function can take, say, two args or three args, but no other
233 numbers of args, this is a poor way to do it--instead implement the operator as
234 two separate operators, one with two args, the other with three.  (The main
235 effect of this bit is to cause the number of arguments to be output to the
236 postfix form so that the expression evaluator can know how many args the
237 operator takes.  It also causes the expression optimizer to calculate the
238 needed stack height differently, without referencing C.)
239
240 * Set the 002 bit (OP_MIN_ARGS) if the operator can take an optional `dotted
241 argument' that specified the minimum number of non-SYSMIS arguments in order to
242 have a non-SYSMIS result.  For instance, MIN.3(e1,e2,e3,e4,e5) returns a
243 non-SYSMIS result only if at least 3 out of 5 of the expressions e1 to e5 are
244 not missing.
245
246 Minargs are passed in the nonterm_node structure in `arg[]''s elements past
247 `n'--search expr-prs.c for the words `terrible crock' for an example of this.
248
249 Minargs are output to the postfix form.  A default value is output if none was
250 specified by the user.
251
252 You can use minargs for anything you want--they're not limited to actually
253 describing a minimum number of valid arguments; that's just what they're most
254 *commonly* used for.
255
256 * Set the 004 bit (OP_FMT_SPEC) if the operator has an argument that is a
257 format specifier.  (This causes the format specifier to be output to the
258 postfix representation.)
259
260 Format specs are passed in the nonterm_node structure in the same way as
261 minargs, except that there are three args, in this order: type, width, # of
262 decimals--search expr-prs.c for the words `is a crock' for an example of this.
263
264 * Set the 010 bit (OP_ABSORB_MISS) if the operator can *ever* have a result of
265 other than SYSMIS when given one or more arguments of SYSMIS.  Operators
266 lacking this bit and known to have a SYSMIS argument are short-circuited to
267 SYSMIS by the expression optimizer.
268
269 * If your operator doesn't fit easily into the existing categories,
270 congratulations, you get to write lots of code to adjust everything to cope
271 with this new operator.  Are you really sure you want to do that?
272
273 C is the effect the operator has on stack height.  Set this to `varies' if the
274 operator has a variable number of arguments.  Otherwise this 1, minus the
275 number of arguments the operator has.  (Since terminals have no arguments, they
276 have a value of +1 for this; other operators have a value of 0 or less.)
277
278 D is the number of items output to the postfix form after the operator proper.
279 This is 0, plus 1 if the operator has varargs, plus 1 if the operator has
280 minargs, plus 3 if the operator has a format spec.  Note that minargs/varargs
281 can't coexist with a format spec on the same operator as currently coded.  Some
282 terminals also have a nonzero value for this but don't fit into the above
283 categories.
284
285 e. Switch to expr-opt.c.  Add code to evaluate_tree() to evaluate the
286 expression when all arguments are known to be constants.  Pseudo-random
287 functions can't be evaluated even if their arguments are constants.  If the
288 function can be optimized even if its arguments aren't all known constants, add
289 code to optimize_tree() to do it.
290
291 f. Switch to expr-evl.c.  Add code to evaluate_expression() to evaluate the
292 expression.  You must be absolutely certain that the code in evaluate_tree(),
293 optimize_tree(), and evaluate_expression() will always return the same results,
294 otherwise users will get inconsistent results, a Bad Thing.  You must be
295 certain that even on boundary conditions users will get identical results, for
296 instance for the values 0, 1, -1, SYSMIS, or, for string functions, the null
297 string, 1-char strings, and 255-char strings.
298
299 g. Test the code.  Write some test syntax files.  Examine the output carefully.
300
301 NOTES ON SEARCH ALGORITHMS
302 --------------------------
303
304 1. Trees are nicer when you want a sorted table.  However, you can always
305 sort a hash table after you're done adding values.
306
307 2. Brent's variation of Algorithm D is best when the table is fixed: it's
308 memory-efficient, having small, fixed overhead.  It's easier to use
309 when you know in advance how many entries the table will contain.
310
311 3. Algorithm L is rather slow for a hash algorithm, however it's easy.
312
313 4. Chaining is best in terms of speed; ordered/self-ordering is even
314 better.
315
316 5. Rehashing is slow.
317
318 6. Might want to decide on an algorithm empirically since there are no
319 clear mathematical winners in some cases.
320
321 7. gprof?  Hey, it works!
322
323 MORE NOTES/IDEAS/BUGS
324 ---------------------
325
326 The behavior of converting a floating point to an integer when the value of the
327 float is out of range of the integer type is UNDEFINED!  See ANSI 6.2.1.3.
328
329 What should we do for *negative* times in expressions?
330
331 Sometimes very wide (or very tall) columns can occur in tables.  What is a good
332 way to truncate them?  It doesn't seem to cause problems for the ascii or
333 postscript drivers, but it's not good in the general case.  Should they be
334 split somehow?  (One way that wide columns can occur is through user request,
335 for instance through a wide PRINT request--try time-date.stat with a narrow
336 ascii page or with the postscript driver on letter size paper.)
337
338 NULs in input files break the products we're replacing: although it will input
339 them properly and display them properly as AHEX format, it truncates them in A
340 format.  Also, string-manipulation functions such as CONCAT truncate their
341 results after the first NUL.  This should simplify the result of PSPP design.
342 Perhaps those ugly a_string, b_string, ..., can all be eliminated.
343
344 From Moshe Braner <mbraner@nessie.vdh.state.vt.us>: An idea regarding MATCH
345 FILES, again getting BEYOND the state of SPSS: it always bothered me that if I
346 have a large data file and I want to match it to a small lookup table, via
347 MATCH FILES FILE= /TABLE= /BY key, I need to SORT the large file on key, do the
348 match, then (usually) re-sort back into the order I really want it.  There is
349 no reason to do this, when the lookup table is small.  Even a dumb sequential
350 search through the table, for every case in the big file, is better, in some
351 cases, than the sort.  So here's my idea: first look at the /TABLE file, if it
352 is "small enough", read it into memory, and create an index (or hash table,
353 whatever) for it.  Then read the /FILE and use the index to match to each case.
354 OTOH, if the /TABLE is too large, then do it the old way, complaining if either
355 file is not sorted on key.
356
357 ----------------------------------------------------------------------
358 Statistical procedures:
359
360 For each case we read from the input program:
361
362 1. Execute permanent transformations.  If these drop the case, stop.
363 2. N OF CASES.  If we have already written N cases, stop.
364 3. Write case to replacement active file.
365 4. Execute temporary transformations.  If these drop the case, stop.
366 5. Post-TEMPORARY N OF CASES.  If we have already analyzed N cases, stop.
367 6. FILTER, PROCESS IF.  If these drop the case, go to 5.
368 7. Pass case to procedure.
369
370 Ugly cases:
371
372 LAG records cases in step 3.
373
374 AGGREGATE: When output goes to an external file, this is just an ordinary
375 procedure.  When output goes to the active file, step 3 should be skipped,
376 because AGGREGATE creates its own case sink and writes to it in step 7.  Also,
377 TEMPORARY has no effect and we just cancel it.  Regardless of direction of
378 output, we should not implement AGGREGATE through a transformation because that
379 will fail to honor FILTER, PROCESS IF, N OF CASES.
380
381 ADD FILES: Essentially an input program.  It silently cancels unclosed LOOPs
382 and DO IFs.  If the active file is used for input, then runs EXECUTE (if there
383 are any transformations) and then steals vfm_source and encapsulates it.  If
384 the active file is not used for input, then it cancels all the transformations
385 and deletes the original active file.
386
387 CASESTOVARS: ???
388
389 FLIP:
390
391 MATCH FILES: Similar to AGGREGATE.  This is a procedure.  When the active file
392 is used for input, it reads the active file; otherwise, it just cancels all the
393 transformations and deletes the original active file.  Step 3 should be
394 skipped, because MATCH FILES creates its own case sink and writes to it in step
395 7.  TEMPORARY is not allowed.
396
397 MODIFY VARS:
398
399 REPEATING DATA:
400
401 SORT CASES:
402
403 UPDATE: same as ADD FILES.
404
405 VARSTOCASES: ???
406 ----------------------------------------------------------------------
407 N OF CASES
408
409   * Before TEMPORARY, limits number of cases sent to the sink.
410
411   * After TEMPORARY, limits number of cases sent to the procedure.
412
413   * Without TEMPORARY, those are the same cases, so it limits both.
414
415 SAMPLE
416
417   * Sample is just a transformation.  It has no special properties.
418
419 FILTER
420
421   * Always selects cases sent to the procedure.
422
423   * No effect on cases sent to sink.
424
425   * Before TEMPORARY, selection is permanent.  After TEMPORARY,
426     selection stops after a procedure.
427
428 PROCESS IF
429
430   * Always selects cases sent to the procedure.
431
432   * No effect on cases sent to sink.
433
434   * Always stops after a procedure.
435
436 SPLIT FILE
437
438   * Ignored by AGGREGATE.  Used when procedures write matrices.
439
440   * Always applies to the procedure.
441
442   * Before TEMPORARY, splitting is permanent.  After TEMPORARY,
443     splitting stops after a procedure.
444
445 TEMPORARY
446
447   * TEMPORARY has no effect on AGGREGATE when output goes to the active file.
448
449   * SORT CASES, ADD FILES, RENAME VARIABLES, CASESTOVARS, VARSTOCASES,
450     COMPUTE with a lag function cannot be used after TEMPORARY.
451
452   * Cannot be used in DO IF...END IF or LOOP...END LOOP.
453
454   * FLIP ignores TEMPORARY.  All transformations become permanent.
455
456   * MATCH FILES and UPDATE cannot be used after TEMPORARY if active
457     file is an input source.
458
459   * RENAME VARIABLES is invalid after TEMPORARY.
460
461   * WEIGHT, SPLIT FILE, N OF CASES, FILTER, PROCESS IF apply only to
462     the next procedure when used after TEMPORARY.
463
464 WEIGHT
465
466   * Always applies to the procedure.
467
468   * Before TEMPORARY, weighting is permanent.  After TEMPORARY,
469     weighting stops after a procedure.
470
471
472 -------------------------------------------------------------------------------
473 Local Variables:
474 mode: text
475 fill-column: 79
476 End: