# Kalkar

It will be a general purpose text based calculator/calculator component written in Delphi.

Users can define variables and functions. Functions can be defined in 2 ways:

1. with a minimal functional language (inspired by Haskell) built in Kalkar. Examples:
```fact n = if n == 0 then 1 else fact (n-1)
sum List = if empty List then 0 else head List + sum Tail List
SomeList = 1,2,3
sum (SomeList, 4, 5) - (2^2)
```
last line would print 11

2. with any external programming language which is able to read input (arguments) from command-line and to print answer on stdout. If user uses some function not defined in Kalkar, then Kalkar looks for a script with same name from a designated folder, runs it with arguments and reads output.
Something is already done -- simple expressions and defining variables and lists and exernal functions. And there is an user interface for it.

Missing:

• implementation of functional language. Grammar is ready.
• configuration part -- what program to use for executing different scripts.
• better user interface -- main problem with current ui is that one can get previous expression back with down arrow and this is unnatural for people used with terminals.

Grammar

```Input       -> List
List        -> Sum [, List]
Sum         -> Term {('+'|'-') Term}
Term        -> Factor {('*'|'/') Factor}
Factor      -> SignedStuff ['^' Factor]
SignedStuff -> {('-'|'/')} Stuff
Stuff       -> ( posnum | Ident | '(' [List] ')' )
Ident       -> name [Stuff | '=' List]
```
'/' on the line of SignedStuff is unary division operator: '/2' means '1/2'. It's good for constructing root operator '^/' so you can write '4^/2' instead of '4^(1/2)'

Variables holding lists and functions returning lists must begin with uppercase letter.