Go library for Common Lisp format style output

Build Status codecov dependencies

playground

format

This library has the goal to bring the Common Lisp format directive to Go. This is work-in-progress, see the summary implementation table below for an overview on what is working and what not.

For a nice introduction to the Common Lisp format see https://en.wikipedia.org/wiki/Format_(Common_Lisp).

Example Code

import "github.com/ragnaroek/format/pkg"

ft.Sformat("~8r", 8) //returns "10"
ft.Sformat("~10,'#,'πŸ₯­,2:@X", 4099) //returns "####+10πŸ₯­03"

ft.Sformat("~r", 4343637058903381868) //returns "four quintillion three hundred forty-three quadrillion six hundred thirty-seven trillion fifty-eight billion nine hundred three million three hundred eighty-one thousand eight hundred sixty-eight"
ft.Sformat("~:@r", 2799) //returns "MMDCCLXXXXVIIII"
ft.Sformat("~@r", 2799) //returns "MMDCCXCIX"

Playground

Since the format directives can get complicated and the best way to figure them output is to play around with them the format playground was created:

playground.png

The playground is hosted here: https://ragnaroek.github.io/format/ The library is compiled to WASM to make it run on the browser.

Implementation Status

The directives listed below are already implemented:

~ Name Prefix args : @ :@ Note
~c Char Pretty Escape :@ not yet implemented
~% Newline # newline
~& Freshline # lines
~| Page # pages
~~ Tilde # ~
~r Radix mincol, padchar, comma-char, comma-interval Ordinal Roman Old Roman
~d Decimal mincol, padchar, comma-char, comma-interval
~b Binary mincol, padchar, comma-char, comma-interval
~o Octal mincol, padchar, comma-char, comma-interval
~x Hexadecimal mincol, padchar, comma-char, comma-interval
~f Float width, decimals, scale, overflow, pad Sign
~{ ~} Iteration : and @ not yet implemented

This table is derived from https://www.hexstreamsoft.com/articles/common-lisp-format-reference/clhs-summary/#subsections-summary-table, which was also a great help in the implementation of the directives so far. Many thanks to Jean-Philippe Paradis.

All other directives not mentioned in the table are not implemented yet.

Current work-in-progress

Implementing more directives.

Optimisation! format is currently 16% to 22% times slower than fmt for the standard cases. Currently 47% slower in the float performance.

BenchmarkFmtSimple-12       	18412630	        59.0 ns/op
BenchmarkFmtLong-12         	 5016384	       235 ns/op
BenchmarkFmtFloat-12        	 4191775	       293 ns/op
BenchmarkFormatSimple-12    	17161602	        68.5 ns/op
BenchmarkFormatLong-12      	 4237104	       286 ns/op
BenchmarkFormatFloat-12     	 2731093	       429 ns/op

You can run the benchmarks yourself with make bench. A history of benchmark results is collected in BENCHMARK.md.

Thanks

This software is open source (LGPLv3) and was made while listening to a lot of Rage against the Machine ✊🏿

Owner
Michael Bohn
hacker, loves coding, loves rust, likes golang, loves everything open-source
Michael Bohn
Similar Resources

πŸƒβ€β™‚οΈ A new way to execute commands and manipulate command output in Go

πŸƒβ€β™‚οΈ A new way to execute commands and manipulate command output in Go

Nov 11, 2022

A minimalist Go PDF writer in 1982 lines. Draws text, images and shapes. Helps understand the PDF format. Used in production for reports.

A minimalist Go PDF writer in 1982 lines. Draws text, images and shapes. Helps understand the PDF format. Used in production for reports.

one-file-pdf - A minimalist PDF generator in 2K lines and 1 file The main idea behind this project was: "How small can I make a PDF generator for it

Dec 11, 2022

The kprobe package allows construction of dynamic struct based on kprobe event format descriptions.

The kprobe package allows construction of dynamic struct based on kprobe event format descriptions.

Oct 27, 2021

Program to solve sudokus given in JSON Format, written in Go

Program to solve sudokus given in JSON Format, written in Go

May 2, 2022

Go code to generate Captcha letters for any TrueType font format files.

Go code to generate Captcha letters for any TrueType font format files. The code can be modified for the background and font colors. The code can be easily upgraded for distorted and rotated letters. These generated lettes can be stiched together to make captcha string.

Jan 31, 2022

Seekable ZSTD compression format implemented in Golang.

ZSTD seekable compression format implementation in Go Seekable ZSTD compression format implemented in Golang. This library provides a random access re

Jan 7, 2023

Library to work with MimeHeaders and another mime types. Library support wildcards and parameters.

Mime header Motivation This library created to help people to parse media type data, like headers, and store and match it. The main features of the li

Nov 9, 2022

Evolutionary optimization library for Go (genetic algorithm, partical swarm optimization, differential evolution)

Evolutionary optimization library for Go (genetic algorithm, partical swarm optimization, differential evolution)

eaopt is an evolutionary optimization library Table of Contents Changelog Example Background Features Usage General advice Genetic algorithms Overview

Dec 30, 2022

cross-platform, normalized battery information library

battery Cross-platform, normalized battery information library. Gives access to a system independent, typed battery state, capacity, charge and voltag

Dec 22, 2022
Related tags
Parse a shell script and output all export declarations in an easy to read format

Find Exports Parse a shell script and output all export declarations in an easy to read format. Usage Example $ findexports ~/.bashrc PATH=$PATH:/usr/

Jan 13, 2022
Go library for hardware I/O control, in the programming style of Arduino

hwio Introduction hwio is a Go library for interfacing with hardware I/O, particularly on SoC-based boards such as BeagleBone Black, Raspberry Pi and

Dec 9, 2022
Shared library of common DTOs for Neo

Shared library of common DTOs for Neo

Dec 20, 2021
Hack this repo and add your name to the list above. Creativity and style encouraged in both endeavors.

Hack this repo and add your name to the list above. Creativity and style encouraged in both endeavors.

Oct 1, 2021
Shows your recent browser history in tree style. ζ ‘ηŠΆε±•η€Ίζ΅θ§ˆε™¨εŽ†ε² (For Edge / Chromium / Chrome)
Shows your recent browser history in tree style. ζ ‘ηŠΆε±•η€Ίζ΅θ§ˆε™¨εŽ†ε²  (For Edge / Chromium / Chrome)

Tree Style Histyle This extension shows your recent browser history in tree style. When you browser pages from internet, you always jump from one page

Jan 3, 2023
Colorize (highlight) `go build` command output
Colorize (highlight) `go build` command output

colorgo colorgo is a wrapper to go command that colorizes output from go build and go test. Installation go get -u github.com/songgao/colorgo Usage c

Dec 18, 2022
A cli for fetching the status and full output of CircleCI jobs.

CCI A cli for fetching the status and full output of CircleCI jobs. Install go install github.com/tmessi/cci/cci@latest Usage cci is designed to have

Oct 29, 2021
rsync wrapper (or output parser) that pushes metrics to prometheus

rsync-prom An rsync wrapper (or output parser) that pushes metrics to prometheus. This allows you to then build dashboards and alerting for your rsync

Dec 11, 2022
Run The World. Command aggregator output. Define many services watch them in one place.

Run The World. Command aggregator output. Define many services watch them in one place.

Feb 2, 2022
Generic mapStringInterface tool for extracting of data for CSV output

Generic mapStringInterface tool for extracting of data for CSV output

Nov 2, 2021