Skip to content

Instantly share code, notes, and snippets.

@okram
Last active December 23, 2019 01:08
Show Gist options
  • Save okram/71b6e68d3b507bb97b2b7b34424faf8d to your computer and use it in GitHub Desktop.
Save okram/71b6e68d3b507bb97b2b7b34424faf8d to your computer and use it in GitHub Desktop.
/***
create an obj with
1. the specified <= generator
2. the symbol 'cpu'
***/
cpu <=[choose,[
person -> ['name':str~name,'age':int] <= people~>[is,[get,'name'][eq,name]],
people -> person{*} <=[=mongo][get,'users'],
weight -> 0.0,
path -> [;],
inst -> [choose,[
people~> -> [choose,[
[dedup] -> [id],
[drop] -> [error]]]
person~> -> [choose,[
[drop,'name'] -> [error]]]]]]]
// ~> is a new sugar proposal -- people~> == [is,[domain][eq,people]]
// <~ is a new sugar proposal -- ~>people == [is,[range][eq,people]]
// everything else is through existing syntax.
// The cpu is an automata with an internal state.
mmlang> weight => cpu
==>0.0
mmlang> person => cpu
==>['name':str~name,'age':int] <=[=mongo][get,'users'][is,[get,'name'][eq,name]]
mmlang> people => cpu => [drop]
==>error
mmlang> people => cpu => [dedup][is,[get,'name'][eq,'marko']]
==>['name':'marko','age':29] <=[=mongo][get,'users'][is,[get,'name'][eq,'marko']]
/// BONUS MATERIAL ///
/// ALREADY EXISTING SYNTAX SUGAR FOR [choose] (a | separated rec as opposed to a , separated rec)
cpu <=[ person -> ['name':str~name,'age':int] <= people~>[is,[get,'name'][eq,name]]
| people -> person{*} <=[=mongo][get,'users']
| weight -> 0.0
| path -> [;]
| inst ->
[ people~> -> [
[ [dedup] -> [id]
| [drop] -> [error]]]]
| person~> -> [[drop,'name'] -> [error]]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment