jsonnet-microkanren

microKanren implementation in Jsonnet
git clone https://ccx.te2000.cz/git/jsonnet-microkanren
Log | Files | Refs

example.jsonnet (717B)


      1 local uK = import 'microkanren.libsonnet';
      2 local uKc = import 'microkanren_checks.libsonnet';
      3 
      4 {
      5   justFive:
      6     local goal = uK.callFresh(function(q) q.eq(5));
      7     assert uKc.Goal(goal);
      8     assert uKc.trace('goal', goal, true);
      9     local stream = goal.pursue(uK.emptyState);
     10     assert uKc.Stream(stream);
     11     stream.takeAll(),
     12 
     13   reifiedFive: uK.runSingleVar(function(q) uK.eq(q, 5)),
     14 
     15   a_and_b: uK.takeAll(uK.conj(
     16     uK.callFresh(function(a) ['eq', a, 7]),
     17     uK.callFresh(function(b) ['or', b.eq(5), ['eq', b, 6]]),
     18   )),
     19 
     20   reified_a_and_b: uK.runWithVars(['a', 'b'], function(vars)
     21     ['and',
     22       ['eq', vars.a, 7],
     23       ['or', vars.b.eq(5), ['eq', vars.b, 6]],
     24     ]
     25   ),
     26 }
     27 // vim: sts=2 ts=2 sw=2 et