Skip to content

Instantly share code, notes, and snippets.

View okram's full-sized avatar
🏠
Working from home

Marko A. Rodriguez okram

🏠
Working from home
View GitHub Profile
@okram
okram / mqtt.c
Created February 24, 2022 18:40
static JsonObject toJson(const byte *payload, const uint32_t length) {
char *json = (char *)malloc(length);
memcpy(json, payload, length);
if (json[0] == NULL) {
json = json + 2;
}
json[length - 1] = NULL;
StaticJsonDocument<256> doc;
DeserializationError error = deserializeJson(doc, json);
if (error) {
mmlang> 5 => int+2-<(nat;nat+10)=(vertex;vertex)=>edge
==>edge:('outV'->vertex:('id'->nat:7),'inV'->vertex:('id'->nat:17))
mmlang> int => int+2-<(nat;nat+10)=(vertex;vertex)=>edge
==>edge<=int[plus,2]
[split,(nat{?}<=int[is,bool<=int[gt,0]];nat{?}<=int[is,bool<=int[gt,0]][plus,10])]
[combine,(vertex;vertex)]
[as,edge<=(vertex;vertex)
[split,('outV'->vertex<=(vertex;vertex)[get,0,_],
'inV'->vertex<=(vertex;vertex)[get,1,_])]]
mmlang> int => vertex
==>vertex<=int[is,bool<=int[gt,0]]
[coerce,vertex{?}<=nat{?}[split,('id'->nat)]]
mmlang> int => vertex => -<(_;_)
==>(vertex:('id'->nat);vertex:('id'->nat))<=int[is,bool<=int[gt,0]]
[coerce,vertex{?}<=nat{?}[split,('id'->nat)]]
[split,(vertex:('id'->nat);vertex:('id'->nat))]
mmlang> int => vertex => -<(_;_) => edge
mmlang> [1,2,3] // a stream of 3 ints
==>1
==>2
==>3
mmlang> [1,2,3][id] // passing the stream through the [id] instruction (ring *)
==>1
==>2
==>3
mmlang> [1,2,3][[id],[id]] // passing the stream across two branches with [id] instructions (ring +)
==>1{2}
// all cascading coercion is completely determined within the obj graph and thus, realized as instructions.
mmlang> :[model,digraph]
==>_
mmlang> int
==>int
mmlang> int => nat
==>nat<=int[is,bool<=int[gt,0]]
mmlang> int => nat => vertex
==>vertex<=int[is,bool<=int[gt,0]][split,('id'->nat)]
mmlang> int => nat => vertex -<(_;_)
int => nat[plus,1] => vertex => -<(_;_) => edge
nat <=int[is>0][plus,1]
vertex <=int[is>0][plus,1][split,('id'->nat)]
(vertex;vertex) <=int[is>0][plus,1][split,('id'->nat)][split,(vertex;vertex)]
edge <=int[is>0][plus,1][split,('id'->nat)][split,(vertex;vertex)][combine,[split,('outV'->[get,0],'inV'->[get,1])]]
@okram
okram / paths.java
Last active October 15, 2020 09:40
mmlang> :[model,pg_2] // load property graph demo model #2
==>_
mmlang> 4 ~~> int // what is the path from 4 to int? simply int.
==>((int))<=4[walk,int]
mmlang> 4 ~~> str // what is the path from 4 to str? this is none. no ".toString()"
==>( )
mmlang> :[model,pg_2][define,str<=int] // lets define ".toString()"
==>_[define,str<=int]
mmlang> 4 ~~> str // what is the path from 4 to str? int then str
==>((int;str))<=4[walk,str]
(int;int) => (nat;nat)
..yields:
(nat;nat)<=(int;int)[combine,(nat<=int[is,bool<=int[gt,0]];nat<=int[is,bool<=int[gt,0]])]
(nat;nat)<=(int;int)[combine,(nat<=int[is,bool<=int[gt,0]];nat<=int[is,bool<=int[gt,0]])]
Given [model,tp3], a graph traversal can be expressed as:
vertex[get,outE][is,[get,label][eq,'knows']][get,inV]
or w/ corresponding mmlang sugar syntax:
vertex.outE[is.label=='knows'].inV
or using auto-coercion over the following type definition:
(nat;attr);(nat;attr) => edge
((nat;attr);(nat;attr)),
(vertex;vertex),
[combine,(vertex<=(nat;attr)[split,('id'->nat<=(nat;attr)[get,0,_],
'attrs'->attr<=(nat;attr)[get,1,_])];
vertex<=(nat;attr)[split,('id'->nat<=(nat;attr)[get,0,_],
'attrs'->attr<=(nat;attr)[get,1,_])])],
[split,('outV'->vertex<=(vertex;vertex)[get,0,_],
'inV'->vertex<=(vertex;vertex)[get,1,_])],