-
Notifications
You must be signed in to change notification settings - Fork 13
tamgucalc (en)
This extremely lightweight spreadsheet launches instantly into your terminal. It allows you to enter numbers, define labels, and most importantly, to enter numerical formulas in Lisp. You can then save your spreadsheets with their formulas in a CSV file. You can also export your worksheets, keeping only the raw data.
The code is less than 2000 lines long and is entirely modifiable at your convenience, if you want to add your own options.
The improved version adds new basic functions (see below) to make your spreadsheet even more powerful.
By default, the spreadsheet uses the dimensions of your terminal to define the number of rows and columns. The size of a column is 10 by default. All of these dimensions can be changed within the spreadsheet. Note that when you change these dimensions, they are saved in your worksheet.
To enter a value, simply position the cursor on a cell with the arrows and enter your value. You can then move to the next cell with the arrows or press the "enter" key. A cell can contain numbers, formulas or labels.
You can also use the mouse to position the cursor on a particular cell or to select a group of cells.
To enter a formula, simply position on a cell and type: '('. When your formula is complete, the system checks that the parentheses balance and displays the message: "Ready to compute".
Just press: "enter" and it will be calculated.
When you type a formula, you can use the arrows to select the cells that go into your formula. When you have selected a cell, press "enter" to save it in your formula.
You can use the mouse to select a range of cells or use the keyboard.
To choose a cell range, you must first choose a first cell, then type ".." (two points) and then choose a second cell. tamgucalc then replaces your selection automatically with the following rules:
The choice of a cell appears in the following form:
- mat[i:j]: a single cell at positions i,j.
- mat[:c][a:b]: 'c' is the column number, 'a,b' are the rows from 'a' to 'b' in column 'c'.
- mat[r:][a:b]: 'r' is the row number, 'a,b' are the columns from 'a' to 'b' in row 'r'.
Note, the use of "r:" and ":c" to identify rows and columns.
Note that when you define a domain that includes several rows and columns, tamgucalc introduces an "&&&" operator to merge all the selected rows into a single data vector. In this way, your selection becomes a single element.
(sum (&&& mat[1:][1:3] mat[2:][1:3])
Formulas in tamgucalc must be written in the Lisp defined for Tamgu (see documentation). You can define lambdas functions, functions (defun) or simply use the basic operators.
- By default, all numerical values are "double" in the C direction (float type for tamgu).
Traditional operators such as: +,-,/, * are of course available.
You can also use: "sum" and "product". Note that "+" is used for atomic values and that "sum" applies to both lists and atomic values.
The set of Lisp methods defined in Tamgu is also available, as well as the methods available for lists, such as "size" for example.
# addition
(+ mat[6:1] mat[7:1] mat[10:1] )
# Rest of a division
(% mat[6:1] mat[7:1])
# logarithm Nepean
(ln mat[9:1] )
# You can encapsulate your formulas
(* 2 (+ mat[6:1] mat[7:1] mat[10:1]))
# To test a cell content
(if (>= mat[8:2] 60) 20 0)
# Apply a change to a list and add it up #
(sum (_map '(* 2) mat[:1][6:10]))
# Filter the values on which to apply our sum
(sum (_filter '(> 20) mat[:1][6:10]))
You can also define lambda functions in your cells and perform any calculation you want including recursions.
# A simple function to calculate the average of a list
((lambda (x) (/ (sum x) (size x))) mat[1:][1:10])
# You can also implement recursions
( lambda (x)
(if (eq x ())
0
(+
(* 2 (car x))
(self (cdr (cdr x))))
mat[:1][6:10])
When you define a function with "defun" in a cell such as:
(defun avg(x) (/ (sum x) (size x))
The cell then takes the name of this function. You can now use it in your sheet as a new operator:
(avg mat[:1][1:8])
It is also possible to enter regular formulas by starting your definition with an "=" and ending with a ";".
= mat[1:2] + mat[2:4] - ln(mat[3:4];
Some values are available such as: pi, _phi, _tau and _e. You can use them directly in your code. Note that when you type one of these values in a formula, they are replaced by their Greek name.
Functions can also be defined directly in tamgucalc code and then used in your sheets. Note that if you want to share your leaves, you will need to share these functions as well. A number of them has already been added as examples:
average calculates the average of a selection: (average mat[:1][1:10])
fillcolumn fills the column starting at cell_i, cell_j with the contents of selection.
(fillcolumn (spell mat[:1][1:10] false) 1 2) fills column 2, starting from row 1 with the sorted data of the selection.
fillrow fills the line starting at cell_i, cell_j with the contents of the selection.
(fillrow (sort mat[:1][1:10] false) 1 2) fills row 1, from column 2 with the sorted data of the selection.
upto retrieves the sub-list in selection up to the value val.
(fillcolumn (sort (upto mat[:1][10:] 0) false) 1 2): fills column 2 with the list of values in column 1 up to the first 0.
Note the use of mat[:1][10:] to extract the full column from cell 10,1.
tamgucalc offers some options:
- Control+b: Black Mode (fom black background terminals) also -b on the commande line
- Control+i: Display/Hide indexes also -i on the command line
- Control+n: Display/Hide messages also -n on the command line
- Control+e: edit a formula
- Control+d: delete cells
- Control+k: copy a group of cells
- Control+x: move a group of cells
- Control+g: goto a cell. Separate row from column with a ",": r,c
- Control+s: Save
- Control+w: Save as
- Control+f: Save raw data.
- Control+r: allows you to change the number of rows and columns displayed on screen (r:c)
- Control+t: allows you to change the width of a column
- Control+q: Quit
You can find "tamgucalc" at: tamgucalc.tmg
A more advanced version with mouse control is available here: tamgucalc_mc.tmg
To run "tamgucalc" you must also get the "tamgu" interpreter, precompiled versions of which are available at:
- Mac OS: Version for macos
- Linux: Versions for linux: fedora, ubuntu, centos
To launch tamgucalc: tamgu tamgucalc.tmg (file)
Note that file is optional...