Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jdan/scheme-to-js
a scheme->js compiler written in scheme
https://github.com/jdan/scheme-to-js
compiler scheme
Last synced: 9 days ago
JSON representation
a scheme->js compiler written in scheme
- Host: GitHub
- URL: https://github.com/jdan/scheme-to-js
- Owner: jdan
- Created: 2018-07-07T10:22:06.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-07T17:41:45.000Z (over 6 years ago)
- Last Synced: 2024-11-08T13:40:59.246Z (2 months ago)
- Topics: compiler, scheme
- Language: Scheme
- Homepage:
- Size: 44.9 KB
- Stars: 17
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## scheme-to-js
a scheme->js compiler written in scheme### Hi 👋
This is a Scheme compiler written in Scheme that produces JavaScript.
I've done this before (in JavaScript) - https://github.com/jdan/lispjs. You'll find that writing the
compiler in Scheme itself means I can effectively skip parsing.### Running
I've written this repository with [Chez Scheme](https://github.com/cisco/ChezScheme) in mind. It's pretty
tiny and easy to install. I typically [build it without X11](https://github.com/cisco/ChezScheme/issues/84#issuecomment-401233680).### Example
```
$ cat example.scm
(load "compiler.scm")(display
(scheme->js
(begin
(define (string-join strs joiner)
(define (helper strs acc)
(if (null? strs)
acc
(helper (cdr strs)
(+ acc
(+ joiner (car strs))))))
(if (null? strs)
""
(helper (cdr strs) (car strs))))
(println (string-join (Array "apples" "bananas" "cucumbers") ",")))))
$ scheme --script example.scm | prettier --parser babylon
(() => {
function string$join(strs, joiner) {
return (() => {
function helper(strs, acc) {
return 0 === strs.length
? acc
: helper(strs.slice(1), acc + (joiner + strs[0]));
}
return 0 === strs.length ? "" : helper(strs.slice(1), strs[0]);
})();
}
return console.log(string$join(Array("apples", "bananas", "cucumbers"), ","));
})();
$ scheme --script example.scm | prettier --parser babylon | node
apples,bananas,cucumbers
```