Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xrlin/goscheme
Just another scheme interpreter.
https://github.com/xrlin/goscheme
golang interpreter scheme
Last synced: 2 months ago
JSON representation
Just another scheme interpreter.
- Host: GitHub
- URL: https://github.com/xrlin/goscheme
- Owner: xrlin
- License: gpl-3.0
- Created: 2019-01-14T10:58:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-03-02T03:31:54.000Z (over 5 years ago)
- Last Synced: 2024-06-21T12:50:29.330Z (3 months ago)
- Topics: golang, interpreter, scheme
- Language: Go
- Homepage:
- Size: 1.96 MB
- Stars: 41
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
GoScheme
Just another shceme interpreter written in Go.
## Installation
```bash
go get github.com/xrlin/goscheme/cmd/goscheme
```Or you can download the corresponding pre-compiled executable file in [release page](https://github.com/xrlin/goscheme/releases).
## Usage
```shell
# Just run goscheme to enter interactive shell
goscheme# Run a scheme file
goscheme test.scm
```## Examples
* Calculate nth fibonacci number
```scheme
; calculate nth fibonacci number
(define (fib n)
(if (<= n 2) 1 (+ (fib (- n 1)) (fib (- n 2)))))
(fib 10)
;#=> 55
; calculate nth fibnacci number in tail recursion
(define (fib2 n)
(begin (define (fib-iter a b n)
(if (= n 0) b (fib-iter b (+ a b) (- n 1))))
(fib-iter 0 1 (- n 1))))
(fib2 30)
;#=>832040
```* Mutually recursion
```scheme
(letrec (
(zero? (lambda (x) (= x 0)))
(even?
(lambda (n)
(if (zero? n)
#t
(odd? (- n 1)))))
(odd?
(lambda (n)
(if (zero? n)
#f
(even? (- n 1))))))
(even? 88))
;#=>#t
```Explore `example.scm` for more examples.
## Features
* Interactive REPL shell
* Tail recursion optimization
* Lazy evaluation
* Short circut logic
* Type: `String`, `Number`, `Quote`, `LambdaProcess`, `Pair`, `Bool` ...
* syntax, builtin functions and procedures
`load`
`define`
`let`
`let*`
`letrec`
`begin`
`lambda`
`and`
`or`
`not`
`if`
`cond`
`delay`
`map`
`reduce`
`force`
`+`
`-`
`*`
`/`
`=`
`cons`
`list`
`append`
`list-length`
`list-ref`
`quote`
`null?`
`'`
`eval`
`apply`
`set!`
`set-cdr!`
`set-car!`
... etcThough it is a toy project just for fun and practice, Feel free to open an issue or make a merge request is you find bugs or have some suggestions.
Happy coding...