Skip to content

Instantly share code, notes, and snippets.

@okram
Last active March 15, 2020 08:01
Show Gist options
  • Save okram/4157ad184acc00b00173edb4e772a66c to your computer and use it in GitHub Desktop.
Save okram/4157ad184acc00b00173edb4e772a66c to your computer and use it in GitHub Desktop.
When the traverser starts at a type (`obj{0}`), the traverser yields a type checked and compiled type.
The technique is called *abstract interpretation*.
```groovy
mmlang> obj{0}[=mmkv,'data/mmkv.mm'][get,'v'][is,[get,'age',int][gt,28]][get,'name'][plus,'!']
==>str{*}<=[=mmkv,'data/mmkv.mm'][get,'v'][is,bool{*}<=rec['name'->str,'age'->int]{*}[get,'age'][gt,28]][get,'name'][plus,'!']
```
When you append an `[explain]` instruction, the traverser walks his current type reference and creates a `str`
table representation of the domain/range of all the types used in the composition.
```groovy
mmlang> obj{0}[=mmkv,'data/mmkv.mm'][get,'v'][is,[get,'age',int][gt,28]][get,'name'][plus,'!'][explain]
==>str<=[start,'
str{*}<=[=mmkv,'data/mmkv.mm'][get,'v'][is,bool{*}<=rec['name'->str,'age'->int]{*}[get,'age'][gt,28]][get,'name'][plus,'!']
instruction domain range state
------------------------------------------------------------------------------------------------------------------------------------------------
[=mmkv,'data/mmkv.mm'] obj{0} => mmkv{*}
[get,'v'] mmkv{*} => rec['name'->str,'age'->int]{*}
[is,bool{*}<=rec['name'->str,'age'->int]{*}[get,'age'][gt,28]] rec['name'->str,'age'->int]{*} => rec['name'->str,'age'->int]{*}
[get,'age'] rec['name'->str,'age'->int]{*} => int{*}
[gt,28] int{*} => bool{*}
[get,'name'] rec['name'->str,'age'->int]{*} => str{*}
[plus,'!'] str{*} => str{*}
']
mmlang>
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment