government / gov2lisp / gov2lisp.go

@ 18e20f574cf1ffbd092fda0b63e7b07430be77dc | history


// Package gov2lisp turns a decoded program back into Lisp source text.
package gov2lisp

import (
	"strings"

	"government/sexpr"
)

// Decompile prints one top-level form per line. The output is source in
// normal form: the printer's spelling, so 'x comes back as (quote x),
// 3.10 as 3.1, and comments are gone until notes carry them (Phase 7).
// Reading it gives exactly the forms that were decoded.
func Decompile(forms []sexpr.Value) string {
	var b strings.Builder
	for _, f := range forms {
		b.WriteString(sexpr.Print(f))
		b.WriteByte('\n')
	}
	return b.String()
}