Scheme

Siag uses Scheme for commands and expressions. This means that the program can be easily extended with new functions. When Load is chosen from the File menu, for instance, the Lisp function (load-buffer) is called. It is thus possible to make File - Load do something completely different by writing a new load-buffer function, perhaps adding the ability to read other file formats.

Documentation for Siod, the Scheme interpreter used in Siag

Cell references

References to cells in the sheet can be done using r1c1 notation. Note that this is a nonstandard extension to the Scheme language which means that symbols cannot have names that start with an 'r', continues with one or more digits, a 'c', and finishes with one or more digits.

When lines and columns are inserted or removed, the references are automatically updated.

There is also a functional interface to the spreadsheet contents.

(get-cell row column)
Returns the value of the cell.
(x-get-cell row column buffer)
Cross-references between buffers are possible by specifying the buffer name. The buffer must be loaded.
(get-string row column)
Returns the value of the cell in the form of a string, regardless of what's actually there: a string, a number, a label, an error or nothing.
(x-get-string row column buffer)
The same as get-string, but references another buffer.
(href n)
Refers to a cell n columns to the right (left for negative n) of the current cell.
(vref n)
Refers to a cell n rows below (above for negative cell) the current cell.
(area-sum r1 c1 r2 c2)
The sum of all cells from (r1,c1) to (r2,c2)
(area-min r1 c1 r2 c2)
The minimum of all cells from (r1,c1) to (r2,c2)
(area-max r1 c1 r2 c2)
The maximum of all cells from (r1,c1) to (r2,c2)
(area-avg r1 c1 r2 c2)
The average of all cells from (r1,c1) to (r2,c2)
Additional functions can be defined in $SIAGHOME/siag/siag.scm, where they will be available for all users, or in $HOME/.siagrc, where they will be available for one user only.

Ranges

Certain functions can handle not only numbers and references, but whole ranges of cells. Such ranges are written as, for example, r1c1..r2c3. In this case, the range consists of all cells from row 1, column 1 to row 2, column 3 (6 cells altogether). Not all fuctions can handle ranges.

Ranges update when lines and columns are inserted or deleted, just like the references described above.

Functions

Siag adds the following functions to those defined by SIOD:
(backward-cell)
Move point one cell to the left.
(forward-cell)
Move point one cell to the right.
(next-line)
Move point one line down.
(previous-line)
Move point one line up.
(beginning-of-line)
Move point to column 1.
(end-of-line)
Move point to the last used cell in the current line.
(beginning-of-buffer)
Move point to column 1, line 1.
(end-of-buffer)
Move point to the last used cell in the last used line.
(top-of-buffer)
Move point to line 1 without changing the column.
(bottom-of-buffer)
Move point to the last used line without changing the column.
(scroll-up)
Move the window up one windowful.
(scroll-cell-up)
Move the window up one line.
(scroll-down)
Move the window down one windowful.
(scroll-cell-down)
Move the window down one line.
(scroll-left)
Move the window left one windowful.
(scroll-cell-left)
Move the window left one column.
(scroll-right)
Move the window right one windowful.
(scroll-cell-right)
Move the window right one column.
(what-cursor-position)
Prints information about the contents of the current cell on the status bar.
(delete-cell)
Delete the contents of the current cell.
(insert-line)
Insert an empty line, moving the rest of the document down.
(edit-label)
Create a label in the current cell.
(edit-expression)
Create an expression in the current cell.
(set-mark-command)
Move mark to the current cell.
(exchange-point-and-mark)
Swap point and mark.
(kill-region)
Should delete everything between point and mark for compatibility with Emacs, but currently does nothing. Block commands are available for that purpose.
(copy-block)
Copy the block to the rectangular area with its top left corner in the current cell. If the block overlaps the destination area, useful fill operations can be achieved.
(intelligent-copy-block)
Copies the block in such a way that overlapping areas are handled correctly.
(delete-block)
Deletes all the cells in block.
(print-block)
Dumps the block to a text file.
(set-block)
Sets the block to be the area between mark and point.
(save-block-file)
What does this do?
(new-siag)
Loads a new Siag window.
(load-buffer)
Loads a Siag document into a new buffer.
(save-buffer)
Saves the current buffer as a Siag document.
(save-buffer-as)
Saves the current buffer using a new file name.
(print-version)
Prints version information on the status bar.
(help-contents)
Starts the Chimera program with siag.html as argument.
(help-search)
Search for keyword. Currently not implemented.
(help-for-help)
Starts the Chimera program with siaghelp.html as argument.
(recenter)
Redraws the screen.
(recalc-matrix)
Recalculates all the cells once. If the are circular references, this may need to be repeated.
(execute-extended-command)
Read and execute a Scheme command.
(keyboard-quit)
Abort a multi-key command sequence.
(quit-siag)
Exit from Siag. If there are any unsaved changes, asks if they should be saved.
(no-op)
Does nothing. Sometimes useful for debugging.

Functions available for expressions

There are also bindings to a number of standard floating-point functions. There are three ways to execute Scheme code:
  1. Enter it as an expression in a cell
  2. Pressing ( and typing it in the input window
  3. Loading it from a file using (load "filename")
A file can be loaded on startup by giving the option -iFilename on the command line. A useful file to load is siod.scm which adds common functions like caar, cadr and the like.

There is no difference between functions that are intended for commands and those that are intended for expressions. It is quite possible to enter the function (forward-cell) into a cell, making the point move forward every time the sheet is recalculated (a command cannot be entered directly as it returns nil and an expression must return a number, but it can be entered as (begin (forward-cell) 0), which returns 0).

It is also possible to make the program compute the sum (+ 1 2) every time a certain key is pressed. Not very useful (except for debugging), but possible. This is done by changing the keybindings in the resource file.

Examples

123.4
The constant 123.4
(- (+ 1 2) 3)
This evaluates to 0
(get-cell 3 4)
The contents of the cell in row 3, column 4
(get-cell R (- C 1))
The contents of the cell immediately to the left of the current cell
(href -1)
The same as above
(+ r2c3 r2c4)
The sum of the value in row 2, column 3 and the value in row 2, column 4
(acos r3c1)
Arc cosine of the value in row 3, column 1.
(tan r2c2)
Tangent of r2c2.
(/ (sin r2c2) (cos r2c2))
Also tangent of r2c2.
(pow temp 0.25)
The variable temp raised to the power of 1/4.
(pow temp (/ 1 4))
The same as above.
(asin (sin 1.59))
This evaluates to 1.59
(r_sum r2c2..r5c6 r1c1 12)
The sum of all numbers between row 2, column 2 and row 5, column 6; the number in row 1, column 1; and the number 12.

Ulric Eriksson - October 1997 - ulric@edu.stockholm.se