Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vrmiguel/carcer
World's favorite `car/cdr` composition desugarer
https://github.com/vrmiguel/carcer
Last synced: about 2 months ago
JSON representation
World's favorite `car/cdr` composition desugarer
- Host: GitHub
- URL: https://github.com/vrmiguel/carcer
- Owner: vrmiguel
- License: mit
- Created: 2022-08-21T23:52:06.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-08-22T21:14:31.000Z (over 2 years ago)
- Last Synced: 2024-10-15T22:10:50.359Z (3 months ago)
- Language: Rust
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `carcer` (CAR Cdr dEsugaRer)
`carcer` is a silly expander for combinations of `car` and `cdr` operations.
```lisp
$ carcer "(car x)"
"(car x)" is equivalent to "(car x)"
$ carcer "(cadr x)"
"(cadr y)" is equivalent to "(car (cdr y))"
$ carcer "(cddadr x)"
"(cddadr y)" is equivalent to "(cdr (cdr (car (cdr y))))"
```Lisp implementations usually support compositions of up to four `car` and `cdr` operations. `carcer`, however, is braver.
```lisp
$ carcer "(cddadaddadadadaddddadaddddadaddr y)"
"(cddadaddadadadaddddadaddddadaddr y)" is equivalent to "(cdr (cdr (car (cdr (car (cdr (cdr (car (cdr (car (cdr (car (cdr (car (cdr (cdr (cdr (cdr (car (cdr (car (cdr (cdr (cdr (cdr (car (cdr (car (cdr (cdr y))))))))))))))))))))))))))))))"
```## Why?
`carcer` is an example of a small parser written with the [nom](https://crates.io/crates/nom) parser combinator library.
## Error messages
`carcer` supplies reasonably good error messages:
```
$ carcer "()"
0: at line 1:
()
^
expected 'c', found )1: at line 1, in car or cdr:
()
^$ carcer "(ca)"
0: at line 1:
(ca)
^
expected 'r', found )1: at line 1, in car or cdr:
(ca)
^$ carcer "(cdar x"
0: at line 1:
(cdar x
^
expected ')', found x1: at line 1, in closing parenthesis:
(cdar x
^
```## Building
This project requires Rust 1.58. You can get it at [rustup.rs](https://rustup.rs).
```bash
git clone https://github.com/vrmiguel/carcer
cargo install --path carcer
```