scl/README.md

63 lines
1.1 KiB
Markdown
Raw Normal View History

2024-12-14 20:35:36 -05:00
# SCL: Simple CAS Language
2025-01-18 10:44:13 -05:00
Version 0.0.1
2024-12-28 19:02:36 -05:00
## Usage
```bash
git clone https://git.signorovitch.org/jacob/scl && cd scl
make release # Build.
./scl # Run.
```
2025-01-09 11:42:06 -05:00
If you wish to run tests, make sure to run `git clone --recurse-submodules` to
include the [Unity](https://github.com/ThrowTheSwitch/Unity) test framework.
2025-01-09 11:42:06 -05:00
2024-12-21 11:10:01 -05:00
## Current State
2025-01-12 20:34:43 -05:00
See [STATUS.md](STATUS.md). Currently, one is able to use `scl` as a basic,
interactive, four-function calculator.
2024-12-21 11:10:01 -05:00
## Syntax (Planned)
2024-11-07 19:55:54 -05:00
As one would expect, you can evaluate simple infix expressions:
```scl
> 1 + 1
= 2
```
You can also define your own functions:
```scl
2024-12-14 20:35:36 -05:00
> f(x) = 2x
2024-11-07 19:55:54 -05:00
> f(2)
= 4
```
2024-12-14 20:35:36 -05:00
Symbolic algebra is done in the following manner:
```scl
2024-12-21 11:10:01 -05:00
> f(x) = x^4
2024-12-14 20:35:36 -05:00
> diff(f, x:sym, 2)
2024-12-21 11:10:01 -05:00
= 12x^2
2024-12-14 20:35:36 -05:00
```
2024-11-07 19:55:54 -05:00
SCL will dynamically decide on types, but you can state them explicitly as
well:
```scl
2024-12-14 20:35:36 -05:00
> f(x:int) = 2x
2024-11-07 19:55:54 -05:00
> f(2.2)
! f(x:int): x must be of type int.
```
Variables can be defined, with several attributes:
```scl
> a = 1 // Interpret type automatically.
> b:int = 1 // Must be int.
> c:const:int = 1 // Constant: value can never change.
2024-12-14 20:35:36 -05:00
> x:sym // Treated symbolicaly.
2024-11-07 19:55:54 -05:00
```