67 lines
1.4 KiB
Markdown
67 lines
1.4 KiB
Markdown
# SCL
|
|
|
|
*v1.0*
|
|
|
|
I began this project in my junior year of highschool, originally intending to
|
|
write a computer algebra system to do my calculus homework for me. Turns out, I
|
|
first needed to write an expression-oriented functional programming language.
|
|
This ended up being such an enjoyable process in its own right that the idea of
|
|
a CAS faded away and now SCL (**S**imple **C**alculator **L**anguage) is a
|
|
(roughly) complete 2,500-line general-purpose programming language.
|
|
|
|
## Usage
|
|
|
|
To download and run:
|
|
|
|
```bash
|
|
git clone https://git.signorovitch.org/scl/scl -b stable && cd scl
|
|
make release
|
|
./scl.out
|
|
```
|
|
|
|
## Syntax
|
|
|
|
SCL's syntax will feel familiar to other functional programming languages.
|
|
|
|
```scl
|
|
> x = 3 + 3 * 3; (!x) + 1
|
|
= 13
|
|
> f(x) = x + 1
|
|
> f(1)
|
|
= 2
|
|
> \x, y 2 * x + y $ (2, 3)
|
|
= 7
|
|
> f(g) = g(2)
|
|
> f(\x 2 * x)
|
|
= 4
|
|
```
|
|
|
|
Here's a simple factorial function, using recursion:
|
|
|
|
```scl
|
|
> fac(n) = {
|
|
> f(n, a) = {
|
|
> if n == 1
|
|
> a
|
|
> else
|
|
> f(n - 1, a * n);
|
|
> }
|
|
>
|
|
> f(n, 1);
|
|
> }
|
|
```
|
|
|
|
SCL's syntax is quite flexible. The above function could be more concisely
|
|
written as:
|
|
|
|
```scl
|
|
> fac(n) = (n, 1) -> f(n, a) = ? n == 1 a f(n - 1, a * n); fac(5)
|
|
```
|
|
|
|
## Testing
|
|
|
|
Run `make test` for unit and integration tests. Python 3 is required for
|
|
integration tests, in addition to the C compiler and Bison.
|
|
|
|
More on running and adding tests in [TESTING.md](TESTING.md).
|