https://github.com/rootmos/silly-k
silly-k is an experimental language inspired by K and APL
https://github.com/rootmos/silly-k
apl k lambda-calculus malfunction nanopass scheme
Last synced: 3 months ago
JSON representation
silly-k is an experimental language inspired by K and APL
- Host: GitHub
- URL: https://github.com/rootmos/silly-k
- Owner: rootmos
- Created: 2017-04-23T19:07:12.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-27T04:54:46.000Z (about 1 year ago)
- Last Synced: 2025-08-10T23:51:34.740Z (5 months ago)
- Topics: apl, k, lambda-calculus, malfunction, nanopass, scheme
- Language: Scheme
- Homepage: https://rootmos.io/2017-06-08-implementing-a-k-like-language-targeting-malfunction.html
- Size: 128 KB
- Stars: 16
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# silly-k
[](https://github.com/rootmos/silly-k/actions/workflows/build-test-push.yaml)
`silly-k` is an experimental language inspired by [K](https://web.archive.org/web/20230411111549/https://kparc.com/k.txt)
and [APL](https://en.wikipedia.org/wiki/APL_(programming_language)),
with an [accompanying post](https://rootmos.io/2017-06-08-implementing-a-k-like-language-targeting-malfunction.html).
The silly prefix is meant to indicate that this is project is nothing more than an experiment
to see how these languages would perform when described in lambda calculus terms.
The compiler is written for the [nanopass framework](https://github.com/nanopass/nanopass-framework-scheme)
using the following structure:
* the `K`-like, `APL` inspired, syntax is translated into something like
[simply typed lambda calculus](https://en.wikipedia.org/wiki/Simply_typed_lambda_calculus)
which is used to resolve the overloaded symbols from K,
* after that, the types are thrown away and is compiled to
[Malfunction](https://github.com/stedolan/malfunction) or to
[Scheme](https://en.wikipedia.org/wiki/Scheme_(programming_language)) (which is used mainly for
quick tests and the REPL).
## Usage
Easiest way to play around with it is to run the [Docker image](https://hub.docker.com/r/rootmos/silly-k/):
```
rlwrap docker run --rm -it rootmos/silly-k
```
which starts the REPL (under [rlwrap](https://github.com/hanslub42/rlwrap)).
## Examples
Here's some examples of the syntax, taken directly from the [tests](https://github.com/rootmos/silly-k/blob/master/tests.scm):
Code | Stdin | Stdout
---- | ----- | ------
`]7` | | `7`
`]1 2 3` | | `1 2 3`
`]1=2` | | `0`
`]2=2` | | `1`
`]2<3` | | `1`
`]2<2` | | `0`
`]3<2` | | `0`
`]1<1 2 3` | | `0 1 1`
`]1 2 3>2` | | `0 0 1`
`]2>3` | | `0`
`]2>2` | | `0`
`]3>2` | | `1`
`]{w>1}'1 2 3` | | `0 1 1`
`]3>1 2 3` | | `1 1 0`
`]1 2 3>2` | | `0 0 1`
`]1=2` | | `0`
`]2=2` | | `1`
`]{w=2}'1 2 3` | | `0 1 0`
`]1 2 3=3` | | `0 0 1`
`]1=1 2 3` | | `1 0 0`
`]~1=2` | | `1`
`]~2=2` | | `0`
`]~0` | | `1`
`]~7` | | `0`
`]~2=1 2 3` | | `1 0 1`
`](1=2)\|2=3` | | `0`
`](1=2)\|2=2` | | `1`
`](2=2)\|2=3` | | `1`
`](2=2)\|3=3` | | `1`
`](1=2)&2=3` | | `0`
`](1=2)&2=2` | | `0`
`](2=2)&2=3` | | `0`
`](2=2)&3=3` | | `1`
`]2&3` | | `2`
`]2\|3` | | `3`
`]1+2` | | `3`
`]1+2 3` | | `3 4`
`]1 2+3 4` | | `4 6`
`]1 2+3` | | `4 5`
`](1=1)+(2=2)` | | `2`
`]1+(2=2)` | | `2`
`]1+2=1 2 3` | | `1 2 1`
`](2=1 2 3)+1` | | `1 2 1`
`]2-3` | | `-1`
`]1-(-2)` | | `3`
`]1 2-3 4` | | `-2 -2`
`]-7` | | `-7`
`]-(-2)` | | `2`
`]1-2 3` | | `-1 -2`
`]1 2-3` | | `-2 -1`
`]2*3` | | `6`
`]1 2*3` | | `3 6`
`]4*2 3` | | `8 12`
`]1 2*3 4` | | `3 8`
`]!1` | | `0`
`]!4` | | `0 1 2 3`
`]*1 2 3` | | `1`
`]*0=0 1` | | `1`
`]*0=1 0` | | `0`
`](*0=0 1;7;8)` | | `7`
`](*0=1 0;7;8)` | | `8`
`]#1 2 3` | | `3`
`]#1 2 3 4` | | `4`
`]4#1 2` | | `1 2 1 2`
`]3#1` | | `1 1 1`
`]1 2 3@1` | | `2`
`]((2=1 2 3)@1;7;8)` | | `7`
`]((2=1 2 3)@2;7;8)` | | `8`
`]1 2 3@0 2` | | `1 3`
`]&1 2 3` | | `0 1 1 2 2 2`
`]7 8@&2 3` | | `7 7 8 8 8`
`]{w+1}'1 2 3` | | `2 3 4`
`]{1-w}'3 4 5` | | `-2 -3 -4`
`]2{a+w}'3 4 5` | | `5 6 7`
`]2{w-a}'3 4 5` | | `1 2 3`
`]2+'3 4 5` | | `5 6 7`
`]2-'3 4 5` | | `-1 -2 -3`
`]{w@1}'{+w}'1 2 3` | | `2 3 4`
`]{w@1}'{-w}'1 2 3` | | `0 -1 -2`
`]+/1 2 3` | | `6`
`]-/1 2 3` | | `2`
`]{w-a}/1 2 3` | | `0`
`]+/2