card { mae.earth/pkg/card }

Documentation Go Report Card

Symbolic-expression data storage card in golang.

Install with


go get mae.earth/pkg/card

Raw go file

package main

import (
	"mae.earth/pkg/sexpr"
	"mae.earth/pkg/card"
	"os"
	"fmt"
)

func main() {

	c,err := card.New("")
	if err != nil {
		fmt.Fprintf(os.Stderr,"error creating card -- %v",err)
		os.Exit(1)
	}

	c.Set("Alice", card.String("in wonderland"))
	c.Set("List of Things", card.DelimitedString{",", "Butterfly,Rabbit,Hamster"}) 	
	c.Set("Id", card.Byte(101)) 	
	c.Set("Number #", card.Number(405)) 	
	c.Set("Pi", card.Real(3.415)) 	
	c.Set("datetime", card.DatetimeNow()) 	

	com := card.NewCompound() 	
	com.Add(card.String("two")) 	
	com.Add(card.DelimitedString{";", "one;two;three;four;five"}) 	
	c.Set("option.1", com) 	

	com = card.NewCompound() 	
	com.Add(card.Number(2)) 	
	com.Add(card.DelimitedString{",", "Butterfly,Rabbit,Hamster"}) 	
	c.Set("option.2", com)

	out,err := sexpr.OutputString(c.Sexpr())
	if err != nil {
		fmt.Fprintf(os.Stderr,"error outputing string -- %v\n",err)
		os.Exit(2)
	}

	fmt.Fprintf(os.Stdout,"\n---\n\n%s\n\n---\n",out)

	c2,err := card.Parse(out)
	if err != nil {
		fmt.Fprintf(os.Stderr,"error parsing input -- %v\n",err)
		os.Exit(3)
	}

	fmt.Fprintf(os.Stdout,"%s\n",c2)
	fmt.Fprintf(os.Stdout,"attributes:\n")
	for key,value := range c2.Attributes {
		fmt.Fprintf(os.Stdout,"\t%20s\ttype=%20s\t%s\n",key,value.Name(),value)
	}
}



---

(card data b657b7db 1 "Fri Oct 26 12:49:55 +0100 2018" (A (a "Number #" (int 405))(a "Pi" (real 3.415))(a "datetime" (datetime "Fri Oct 26 12:49:55 +0100 2018"))(a "option.1" (C (string "two")(delimited-string ";" "one;two;three;four;five")))(a "option.2" (C (int 2)(delimited-string "," "Butterfly,Rabbit,Hamster")))(a "Alice" (string "in wonderland"))(a "List of Things" (delimited-string "," "Butterfly,Rabbit,Hamster"))(a "Id" (uint8 101))))

---
card type=data id=b657b7db version=1, 7 attribute(s)
attributes:
	               Alice	type=              string	in wonderland
	      List of Things	type=    delimited-string	Butterfly,Rabbit,Hamster
	                  Id	type=               uint8	101
	            Number #	type=                 int	405
	                  Pi	type=                real	3.415
	            option.1	type=                   C	() +two+one;two;three;four;five
	            option.2	type=                   C	() +2+Butterfly,Rabbit,Hamster