scl/README.md

72 lines
1.2 KiB
Markdown
Raw Permalink Normal View History

2024-12-14 20:35:36 -05:00
# SCL: Simple CAS Language
2025-01-18 10:47:10 -05:00
Version v1.0-alpha
2025-01-18 10:44:13 -05:00
2024-12-28 19:02:36 -05:00
## Usage
```bash
2025-01-18 11:05:15 -05:00
git clone https://git.signorovitch.org/jacob/scl -b stable
cd scl
2025-01-18 11:01:56 -05:00
make release
2025-01-18 11:05:58 -05:00
./scl.out
2025-01-18 11:01:56 -05:00
```
### For Development
```bash
git clone git@signorovitch.org:jacob/scl --recurse-submodules && cd scl
2025-01-18 11:05:15 -05:00
make all test
2025-01-18 11:05:58 -05:00
./scl.out
2024-12-28 19:02:36 -05:00
```
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
```