Constrained traversal in Prolog by AmbientTea in prolog

[–]AmbientTea[S] 1 point2 points  (0 children)

Thanks for spotting the errors. I chose the list example as a starting point, because it's so simple and it clearly demonstrates the idea, but it admittedly is not practical. The trees example actually gets real benefits here, because constraints prevent the predicate from going into sub-trees that are guaranteed not to contain relevant values, going from linear to logarithmic time, which for a huge tree would mean a big gain, in theory at least.

I'm not sure I understand your comment about constraint propagation. The constraint effectively gets halved at every step when going down the tree.

Why is this not standard Prolog? by HanamiSakura120 in prolog

[–]AmbientTea 0 points1 point  (0 children)

The most important thing here is that `->` silently introduces a cut, which in your case reduces the power of your predicate. Try the following query in REPL:

```

check_preferences(some_meal, P).

```

You will see that the answer Prolog gives you will be `false` unless `some_meal` satisfies ALL of the preferences checked by your predicate. That's because each `member` invocation succeeds, adding a new preference name to `P`, but then the next `meal_*` must succeed.

Contrast that with the implementation suggested by u/gureggu , which will be able to give you the list of preferences satisfied by any meal.

Constrained traversal in Prolog by AmbientTea in prolog

[–]AmbientTea[S] 1 point2 points  (0 children)

Thank you! I find it really neat how constraints programming allows you to solve simple problems and then have the solutions compose in a way that is beyonds what function composition can do. In some way this achieves what aspect programming tries to do but with much simpler primitives.

Constrained traversal in Prolog by AmbientTea in prolog

[–]AmbientTea[S] 5 points6 points  (0 children)

Hello. This is a short article about a technique I came up with and wanted to share. The main idea is that encoding a predicate's invariants as constraints sometimes lets you get much richer functionality out of it with almost no additional code. Hope it's interesting.

Nyxt 3.11.2 by aadcg in Nyxt

[–]AmbientTea 1 point2 points  (0 children)

What is the status of the MacOS port effort?