Querying a Session ❔

Once we've created a session, we can query it for any data our components might need. Querying using the same language we learned for writing axioms.

As an example, here are some function signatures from our todo list specification:

fluents
basic
...
active_filter: filters
...
defined
...
visible : todos -> booleans
...

This means that, at any given state, our session has some facts about the active filter and visible todos.

We can access those facts with a query using the useQuery hook.

useQuery("visible(Todo). active_filter = ActiveFilter.")

This query says: "Find me all the values of the variables Todo and ActiveFilter that make visible(Todo) and activeFilter = ActiveFilter true. Flamingo will think about it and then package them up in a nice object for you, where each variable is a key:

const { ActiveFilter, Todo } = useQuery("visible(Todo). active_filter = ActiveFilter.");

If the variable is in the return position of a function, its key will contain a single value, since, by definition, a function can only yield one value at a time. Conversely, if the variable is an an argument position of a function, its key will contain an array of the results, since there are potentially many values.