prosper/README.md

83 lines
1.3 KiB
Markdown
Raw Normal View History

2021-02-21 17:22:08 +00:00
# Prosper
Prosper is a Forth-like stack-based language. While taking specific influence from Forth, it does not attempt to emulate or implement the ANS Forth standards.
Currently, the language is entirely interactive -- to explore, simply run `go run .` in the root of this project and an interactive session will begin.
## Syntax
Prosper is stack-based, as mentioned, so all the standard stack semantics are present:
```
> 1 2 3 4 + * -
ok
> .
-13 ok
```
New words can be defined using `: ;`:
```
> : SQUARE DUP * ;
ok
> 10 SQUARE .
100 ok
```
It has a single loop construct, `DO LOOP`:
```
> : TOFIVE 5 0 DO I . LOOP ;
ok
> TOFIVE
0 1 2 3 4 ok
```
Branches using `IF ELSE THEN` work:
```
> : EMOJI 0 < IF 128201 EMIT ELSE 128200 EMIT THEN ;
ok
> 100 EMOJI
📈 ok
> -100 EMOJI
📉 ok
```
2021-02-22 21:55:33 +00:00
Here's a Fibonacci implementation:
```
> : FIB 2DUP + ;
ok
> : FIBN 0 1 ROT 1 DO FIB ROT DROP LOOP SWAP DROP ;
ok
> 10 FIBN .
55 ok
```
2021-02-26 02:04:35 +00:00
Propser also has a basic off-stack memory model using variables, constants, and pointers:
2021-02-25 02:27:52 +00:00
```
> VARIABLE FOO
ok
> 10 FOO !
ok
> FOO @
ok
> .
10 ok
2021-02-26 02:04:35 +00:00
> 100 CONSTANT HUNDRED
ok
> HUNDRED HUNDRED * .
10000 ok
2021-02-25 02:27:52 +00:00
```
2021-02-21 17:22:08 +00:00
And, of course, it knows how to quit:
```
> BYE
bye
```
## Future Plans
* Add much better readline behaviors in the interactive console (up-arrow for history, cursor movement...)