• Stars
    star
    1,636
  • Rank 28,579 (Top 0.6 %)
  • Language
    Go
  • License
    BSD 2-Clause "Sim...
  • Created almost 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Zygo is a Lisp interpreter written in 100% Go. Central use case: dynamically compose Go struct trees in a zygo script, then invoke compiled Go functions on those trees. Makes Go reflection easy.

Image of Gopher flying

zygomys - an embedded scripting language for Go

Quick examples...

Note that parenthesis always mean a function call or native lisp form, and function calls always use outer-parentheses.

Traditional lisp style:

// tail recursion; tail-call optimization works, so this won't overflow the stack.
zygo> (defn factTc [n accum]
        (cond (== n 0) accum
          (let [newn (- n 1)
                newaccum (* accum n)]
            (factTc newn newaccum))))
zygo> (factTc 11 1) // compute factorial of 11, aka 11! aka 11*10*9*8*7*6*5*4*3*2
(factTc 11 1)
39916800
zygo> 

An optional infix syntax is layered on top. The infix syntax is a subset of Go. Anything inside curly braces is infix. Outer parenthesis are still always used for function calls. The zygo REPL is in infix mode by default to facilitate math.

// show off the infix parser
zygo> x := 3; y := 5; if x + y == 8 { (println "we add up") } else { (println "wat?" ) }
we add up
zygo>

quickly create a mini-language to drive your project

zygomys is an embeddable scripting language. It is a modernized Lisp with an object-oriented flavor, and provides an interpreter and REPL (Read-Eval-Print-Loop; that is, it comes with a command line interactive interface).

why use zygomys?

zygomys allows you to create a Domain Specific Language to drive your program with minimal fuss and maximum convenience.

It is written in Go and plays nicely with Go programs and Go structs, using reflection to instantiate trees of Go structs from the scripted configuration. These data structures are native Go, and Go methods will run on them at compiled-Go speed.

Because it speaks JSON and Msgpack fluently, zygomys is ideally suited for driving complex configurations and providing projects with a domain specific language customized to your problem domain.

The example snippets in the tests/*.zy provide many examples. The full documentation can be found in the Wiki. zygomys blends traditional and new. While the s-expression syntax defines a Lisp, zygomys borrows some syntax from Clojure, and some (notably the for-loop style) directly from the Go/C tradition.

The standalone REPL is called simply zygo. zygo is also shorthand for the whole project when speaking aloud. In writing, the full zygomys is used to aid searchability.

installation

$ go get github.com/glycerine/zygomys/cmd/zygo

not your average parentheses... features in zygomys 5.1.1 include

  • package mechanism that supports modularity and isolation of scripts/packages/libraries from each other. See tests/package.zy for examples.
  • NaN handing that matches typical expectations/Go's answers.
  • struct defintion and type checking. See tests/declare.zy for examples.
  • Readable nested method calls: (a.b.c.Fly) calls method Fly on object c that lives within objects a and b.
  • Use zygo to configure trees of Go structs, and then run methods on them at natively-compiled speed (since you are calling into Go code).
  • sandbox-able environment; try zygo -sandbox and see the NewGlispSandbox() function.
  • emacs/zygo.el emacs mode provides one-keypress stepping through code.
  • Command-line editing, with tab-complete for keywords (courtesy of https://github.com/peterh/liner)
  • JSON and Msgpack interop: serialization and deserialization
  • (range key value hash_or_array (body)) range loops act like Go for-range loops: iterate through hashes or arrays.
  • (for [(initializer) (test) (advance)] (body)) for-loops match those in C and Go. Both (break) and (continue) are available for additional loop control, and can be labeled to break out of nested loops.
  • Raw bytes type (raw string) lets you do zero-copy []byte manipulation.
  • Record definitions (defmap) make configuration a breeze.
  • Files can be recursively sourced with (source "path-string").
  • Go style raw string literals, using `backticks`, can contain newlines and " double quotes directly. Easy templating.
  • Easy to extend. See the repl/random.go, repl/regexp.go, and repl/time.go files for examples.
  • Clojure-like threading (-> hash field1: field2:) and (:field hash) selection.
  • Lisp-style macros for your DSL.
  • optional infix notation within {} curly braces. Expressions typed at the REPL are assumed to be infix (wrapped in {} implicitly), enhancing the REPL experience for dealing with math.

obligatory XKCD

Obligatory XKCD: "elegant weapons... for a more civilized age"

additional features

  • Go-style comments, both /*block*/ and //through end-of-line.
  • zygomys is a small Go library, easy to integrate and use/extend.
  • Float (float64), Int (int64), Char, String, Symbol, List, Array, and Hash datatypes builtin.
  • Arithmetic (+, -, *, /, mod, **)
  • Shift Operators (sll, srl, sra)
  • Bitwise operations (bitAnd, bitOr, bitXor)
  • Comparison operations (<, >, <=, >=, ==, !=)
  • Short-circuit boolean operators (and and or)
  • Conditionals (cond)
  • Lambdas (fn)
  • Bindings (def, defn, let, letseq)
  • Standalone and embedable REPL.
  • Tail-call optimization
  • Go API
  • Macro System with macexpand (macexpand (yourMacro)) makes writing/debugging macros easier.
  • Syntax quoting -- with caret ^() instead of backtick.
  • Backticks used for raw multiline strings, as in Go.
  • Lisp-expression quoting uses % (not '; which delimits runes as in Go).
  • Channel and goroutine support
  • Full closures with lexical scope.

See the wiki for lots of details and a full description of the zygomys language..

where did the name zygomys come from?

zygomys is a contraction of Zygogeomys, a genus of pocket gophers. The Michoacan pocket gopher (Zygogeomys trichopus) finds its natural habitat in high-altitude forests.

The term is also descriptive. The stem zygo comes from the Greek for yoke, indicating a pair or a union of two things, and mys comes from the Greek for mouse. The union of Go and Lisp in a small cute package, that is zygomys.

users of note

https://github.com/metacurrency/holochain

license

Two-clause BSD, see LICENSE file.

author

Jason E. Aten, Ph.D.

credits

The ancestor dialect, Glisp, was designed and implemented by Howard Mao.

The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/) The design is licensed under the Creative Commons 3.0 Attributions license. Read this article for more details: https://blog.golang.org/gopher

XKCD https://xkcd.com/297/ licensed under a Creative Commons Attribution-NonCommercial 2.5 License(https://xkcd.com/license.html).

More Repositories

1

offheap

an off-heap hash-table in Go. Used to be called go-offheap-hashtable, but we shortened it.
Go
349
star
2

rbuf

a small circular ring buffer library in go / golang
Go
182
star
3

sshego

golang/Go library for ssh tunneling (secure port forwarding)
Go
171
star
4

zebrapack

ZebraPack format is like gobs version 2: serialization in Go, *but* extremely fast and friendly to other languages. Use Go as your schema. Strong typing. Well documented (and msgpack2 compatible) format so other languages can be readily supported. See also https://github.com/glycerine/greenpack for a more recent alternative. Docs:
Go
168
star
5

greenpack

Cross-language serialization for Golang: greenpack adds versioning, stronger typing, and optional schema atop msgpack2. `greenpack -msgpack2` produces classic msgpack2, and handles nils. Cousin to ZebraPack (https://github.com/glycerine/zebrapack), greenpack's advantage is fully self-describing data. Oh, and faster than protobufs.
Go
113
star
6

goq

goq: a job queuing system written in go (golang). "Pronounced Go-Queue. Don't Gawk at this!"
Go
86
star
7

bambam

auto-generate capnproto schema from your golang source files. Depends on go-capnproto-1.0 at https://github.com/glycerine/go-capnproto
Go
67
star
8

sofia-ml

Automatically exported from code.google.com/p/sofia-ml
C++
61
star
9

go-sliding-window

a library for reliable and flow-controlled nats sessions using the sliding window protocol. Written in golang.
Go
58
star
10

golang-thrift-minimal-example

the apache thrift starter tutorial for golang, as a standalone repo
Go
44
star
11

gozbus

nanocap based messaging system
Go
43
star
12

grpc-demo

code to stream arbitrarily large files between hosts using gRPC and golang
Go
39
star
13

fast-elliptic-curve-p256

repackage the golang elliptic library enhancements by Vlad Krasnov and Shay Gueron as a stand alone library. Works with Go 1.4 or Go 1.5.
Go
35
star
14

tmframe

TMFRAME, pronounced "time frame", is a binary standard for compactly encoding time series data
Go
28
star
15

xcryptossh

golang.org/x/crypto/ssh the next generation: provide idle timeouts, avoid memory leaks, and gracefully cancel connections
Go
27
star
16

rmq

R package providing msgpack and websockets; demonstrates how to utilize Go libraries from R.
Go
24
star
17

libzipfs

Ship a zip file of media resources inside your golang web-app for complete standalone one-binary deployment
Go
21
star
18

golang-embed-julia

simple example of calling julia from Go
Go
20
star
19

thinkgo

Think Go. Pointers and resources for learning Go. Go (golang) is an elegant, fast, and rapid development language.
19
star
20

nack-oriented-reliable-multicast

NACK-Oriented Reliable Multicast (NORM): http://www.nrl.navy.mil/itd/ncs/products/norm
C++
15
star
21

hello_gio

hello world for Gio graphics for Golang. Gio runs on macOS, Windows, Wayland (linux), X11, WebASM, iOS, and Android. All in Go, no bridge C/Java to write.
Go
14
star
22

arogue

A Go-Repl using R underneath
Go
9
star
23

go-unsnap-stream

small golang library for decoding the snappy streaming format https://github.com/google/snappy/blob/master/framing_format.txt
Go
9
star
24

truepack

like https://github.com/glycerine/greenpack, but no integer compression based on the int's value
Go
8
star
25

lush2

Lush2 sources from svn 908, starting point -- https://lush.svn.sourceforge.net/svnroot/lush -- Last Changed Date: 2011-03-20 16:29:13 -0500 (Sun, 20 Mar 2011). Now patched for OSX 10.6 and up.
C
7
star
26

PrattParserInC

An implementation of Pratt Parsing (Vaughn Pratt 1973 "Top Down Operator Precedence") in C/C++
7
star
27

ruid

ruid: a really unique id
Go
6
star
28

webiperf

webiperf is a web-app that makes it easy to generate iperf commands
JavaScript
6
star
29

rustxi

rust + transactions + interpreter = rustxi. rustxi is a transactional jit-compilation-based REPL for the Rust language.
C
5
star
30

liblmdb

git clone -b mdb.master git://git.openldap.org/openldap.git # on June 11, 2014 / 17c09fa476a7dbd49aca5e4caf0384cb1c3d244a
C
5
star
31

monotime

Go library for monotonic time source on platforms where one is available to the Go runtime.
Go
4
star
32

low-level-lush

(LLL) : Low-Level-Lush with Lisp is a combination of Lush2.0.1 and LLVM2.8 to bring out the best in both.
C++
4
star
33

swig-cpp-to-cffi-for-common-lisp-enhancements

forking from SWIG svn 12570 to generate better common lisp bindings from c++
C++
4
star
34

gopass

Go
4
star
35

idem

idem.Halter: a pattern for halting goroutines in Go
Go
4
star
36

muse

golang code to convert from go/types.Type to reflect.Type
Go
3
star
37

crack-language

Crack programming language
C++
3
star
38

buzz

broadcasting channels in Go
Go
3
star
39

json2msgpack

convert from newline delimited json to size-header based msgpack frames
Go
3
star
40

shore-mt

shore-mt (Scalable Heterogeneous Object REpository - MultiThreaded version), import of the 6.0.2 release of 03-Jan-2012 http://research.cs.wisc.edu/shore-mt/ ( differs from the DIAS version from http://diaswww.epfl.ch/shore-mt/ )
C++
3
star
41

configs-in-golang

demonstrate pattern for command line flag handling that allows library configuration/reuse and testing
Go
3
star
42

golang-fisher-exact

Fisher's exact test for 2x2 contingency tables, in Golang
Go
2
star
43

vprint

debug Go faster with this simple print library. prints show timestamp and file location
Go
2
star
44

selfie

generate and validate self-signed public keys
Go
2
star
45

nanomsgardvark

R bindings for nanomsg
C
2
star
46

justinjuddeasyssh

Go
2
star
47

golang-hex-dumper

Go
2
star
48

libcmm

Ralf Juengling's libcmm: a C Memory Management Library, last commit f980fd1715780c99f54ebad8b49dbc10befe192d from Thu Nov 12 13:35:24 2009. Obtained from the sourceforge git repos on 28 April 2011 by: git clone git://libcmm.git.sourceforge.net/gitroot/libcmm/libcmm
C++
2
star
49

xml2csv

Parse an XML file on stdin, write csv to stdout. No schema, no structs required.
Go
2
star
50

gossainterpdemo

demonstration of the go ssa interpreter
Go
2
star
51

pingbuf

a minimal ring buffer
Go
2
star
52

spread-src-4.4.0

An open source implementation of virtual synchrony, package spread-src-4.4.0, from Spread Concepts LLC. Details at http://www.spread.org See also https://github.com/glycerine/spread-src-5.0.1
C
2
star
53

ugorji-go-codec

Go
1
star
54

spread-src-5.0.1

see motivation https://github.com/glycerine/spread-src-4.4.0
C
1
star
55

latch

Go
1
star
56

dyg

Go
1
star
57

rogue

use R as a repl and worker under golang master
Go
1
star
58

mps-kit-1.108.0-x86_64-linux-port

See if the excellent Memory Pool System (MPS) can be ported to x86_64 on Linux
C
1
star
59

basic-bolt

basic boltdb example
Go
1
star
60

avfs

a virtual filesystem. mirror from http://avf.sourceforge.net/ and http://sourceforge.net/projects/avf/
C
1
star
61

vpython-emacs-mode

my vpython.el mode for ipython
Emacs Lisp
1
star
62

verb

Go
1
star
63

iris2

Community driven successor of the iris web framework
Go
1
star
64

yield

C++ web application server
C++
1
star
65

lcon

local pipe that looks like net.Conn
Go
1
star
66

pelican-protocol

In ancient Egypt the pelican was believed to possess the ability to prophesy safe passage in the underworld. Pelicans are ferocious eaters of fish.
Go
1
star
67

nats

friendly fork of nats-io/nats for use with glycerine/hnatsd
Go
1
star
68

go-inthash

go version of basic hash map, open addressing with linear probing. uint64 keys. Inspired by http://preshing.com/20130107/this-hash-table-is-faster-than-a-judy-array/
Go
1
star
69

fastbit

fastbit-2.0.3 from https://sdm.lbl.gov/fastbit/, BSD licensed.
C++
1
star
70

geist

the geist script runner turns golang into a scripting language
Go
1
star
71

gopls-emacs-how-to

how to get gopls in emacs with golang go-mode working
1
star
72

golang-repl

Go
1
star
73

double-messages-received-bug

Go
1
star
74

python-extension-in-golang

code for https://hackernoon.com/extending-python-3-in-go-78f3a69552ac
Makefile
1
star
75

L3

L3: experiments in aggressive Garbage-collection and interpreter implementation based on the Pratt parser. Uses protocol buffers for serialization, and Judy arrays for fast, sparse arrays/hashtables. Linux and OSX.
1
star
76

SchemeTL

Scheme To Learn : Learning Scheme by implementing STL data structure equivalents
Common Lisp
1
star