https://github.com/coyove/sc45
Sc45 is a relatively-small-basically-working Scheme dialect in Go
https://github.com/coyove/sc45
dependency-free golang interpreter scheme script
Last synced: 8 months ago
JSON representation
Sc45 is a relatively-small-basically-working Scheme dialect in Go
- Host: GitHub
- URL: https://github.com/coyove/sc45
- Owner: coyove
- Created: 2020-05-07T13:14:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-04T12:08:28.000Z (over 4 years ago)
- Last Synced: 2025-01-16T18:55:20.913Z (9 months ago)
- Topics: dependency-free, golang, interpreter, scheme, script
- Language: Go
- Homepage:
- Size: 596 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
Sc45 is a relatively-small-basically-working scheme dialect in Go, its core consists of only one file (sc45.go) with 1k LOC.
Sc45 serves one purpose: give your program an embedded REPL on-the-fly with minimal efforts:
```Go
func init() {
it := sc45.New()
it.Store("turn-on-flag1", sc45.V(func(v bool) { FLAG1 = v }))
it.Store("turn-on-flag2", sc45.V(func(v bool) { FLAG2 = v }))
it.Store("pre-setup", sc45.V(func(n int, kafkaTopic string) { RerouteMsg(n, kafkaTopic) }))
...// 1. If your server has debug/pprof enabled:
it.InjectDebugPProfREPL("Title")
// Navigate to http://.../debug/pprof/repl to use the REPL// 2. If you can access to the working directory where your server is running in:
it.RunSimplePipeREPL("/tmp/debug_pipe")
// This will output a 'repl' script in current working dir, you can: cd $CWD && ./repl to use the REPL
// Note that this script needs mkfifo and access to '/tmp/debug_pipe'...
}
```Inside REPL:
```Scheme
(turn-on-flag1 #t)
(pre-setup 10 "debug-topic")
...
(turn-on-flag1 #f)
(turn-on-flag2 true)
```# Language details
- `call/cc` is not supported, due to sc45's recursive evaluation intepreter, this is also impossible
- Numbers are float64 + int64 internally, int64 will be promoted to float64 when needed
- Macro definition syntax: `(define name (lambda-syntax (paramlist) body))`, macro is a legit function which takes expressions as inputs and outputs expressions, and it can also refer upper level symbols