Skip to content

Instantly share code, notes, and snippets.

@akollegger
Last active August 30, 2019 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akollegger/8e8d2f14cc97db9a055faaa3e995194e to your computer and use it in GitHub Desktop.
Save akollegger/8e8d2f14cc97db9a055faaa3e995194e to your computer and use it in GitHub Desktop.
Gram - a lightweight graph exchange format
// gram is a lightweight graph exchange format.
//
// gram is a series of path updates.
//
// identified path elements may be introduced and referenced in a later update
// node shapes
() // anonymous node
(a) // identified node
(1) // numerically identified node
(a1) // alphanumerically identified node
(:Person) // anonymous node with a label
(:Person:Stealthy) // another anonymous node, with multiple labels
(2:Person) // new identified Person, with a label
(a:Person) // update to node 'a' with a label
(3 {ordinal:'third'}) // new identified node, with a single property
(4 {ordinal:'fourth', since:date`1999` })
// anonymous nodes with just properties
{org:'anonymous',size:5}
{name:'dan'}-{likes}->{name:'ann'}
// fun with number values
// In exponential notation, e or E defines a power-of-ten exponent for decimal values, and p or P defines a power-of-two exponent for non-decimal values, i.e. binary, hexadecimal or octal.
({size:4}) // integer
({cm:180.6}) // decimal number
({:.375}) // decimal without whole number
({bigDecimal:5032485723458348569331745.33434346346912144534543})
({science:4.321e+4) // scientific notation is always a decimal '43210.0'
({science:-735.0918e-430) // science can be negsative '-7.350918e-428'
({trailing:5.6700000}) // drop trailing zeroes '5.67'
// decimals within tagged string, containing digits or constants
// https://en.wikipedia.org/wiki/Mathematical_constant#Table_of_selected_mathematical_constants
({a:decimal`3.14`}) // decimal string using full tag
({a:d`3.1495`}) // decimal string with shorthand tag
({a:d`Infinity`})
({a:d`NaN`})
({a:d`tau`}) // 2*pi https://en.wikipedia.org/wiki/Turn_(angle)#Tau_proposals
({a:d`phi`}) // golden ratio
({a:d`golden`})
({a:d`e`})
({a:d`i`})
({a:d`pi`})
////
// alternate base representation of numbers
// 8-bit aligned
// hexadecimal
({guid:0x1337c001c4fe}) // hexadecimal integer values of arbitrary length
({toDecimal:0xff.8}) // hexadecimal decimal value '255.5'
({science:0x1.8p-5}) // '0.046875'
// binary
({mask:0b00110011}) // binary integer
({mask:0b110011}) // left-padded nibble '0b00110011'
({toDecimal:0b0.000011') // '0.046875'
({science:0b1.1p-5}) // '0.046875'
// octal
({toDecimal:0o0.03) // '0.046875'
({science:0o1.4p-5}) // '0.046875'
////
// fractions
({portion:frac`1/4`})
({rating:f`1/10`})
({ratio:f`1:1`})
({music:f`4/4`})
({precis:f`1/3`})
// Date, Time, Interval
// ISO 8601 compatible https://en.wikipedia.org/wiki/ISO_8601
// year
({year:date`1999`}) // Date Year, always four digits
// year month day
({yearMonthDay:date`2020-01-01`}) // YYYY-MM-DD
{{yearMonthDay:date`20200101`}} // YYYYMMDD drop hyphens
// year month
({yearMonth:date`2020-01`}) // YYYY-MM without day
({illegal:date:`202001`}) // YYYMM is illegal.
// month day
({monthDay:date`--12-30`}) // --MM-DD without year
({monthDay:date`--1230`}) // --MMDD without year is also ok
// week dates in the gregorian calendar
// week days are numbered 1-7
({weekDate:date`2020-W10`}) // YYYY-Www
({weekDate:date`2020W10`}) // YYYYWww drop hyphens but keep explicit 'W'
({weekDate:date`2020-W10-3`}) // YYYY-Www-D
({weekDate:date`2020W103`}) // YYYYWwwD drop hyphens
// ordinal dates
// days are numbered 1-366 (to accept leap years)
({ordinalDate:date`2020-001`}) // YYYY-DDD
({ordinalDate:date`2020001`}) // YYYYDDD
// CSS
({color:#daB671}) // css friendly hex colors
({color:color`blue`}) // css color names as tagged string
({color:color`#FF33DA}) // css hex color in tagged string
({lineHeight:unit`12 px`}) // numbers with units
({margin:u`0.5 em`}) // abbreviated unit tag
// text within text
({homepage:url`http://`}) // this string is a url
({readme:md`# Mark down my words`}) // this string is in markdown format
({page:html`<p>Wow, such stucture inside here!</p>`}) // or html
({math:tex`This formula $f(x) = x^2$ is an example.`}) // or latex
// template pattern lists. a template pattern followed by a list of value patterns
// For example:
// - a single node pattern
// - every node will get a `:Person` label
// - property tuples will be of the form:
// - name, a string
// - birth, a Year
// - favoriteColor, a css hex value
// - home, a url string
$(:Person {name:``, birth:0y, favoriteColor:# home:url})
// begin list of value patternsd
(5 {'Leonhard Euler', 1707, 4d9Eda, 'http://euler.org'}) // all values present
(6 {'Bob',_,_'http://neo4j.com'}) // some values missing (using `_` placeholder)
(7:Employee {'ABK'}) // extra label
8,'ann',1998,'goldenrod','http://somewhere.com/ann'
$()-[:KNOWS]->() // change template
(5)-->(6)
$() // resets to no template (normal operation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment