cozodb / cozo

A transactional, relational-graph-vector database that uses Datalog for query. The hippocampus for AI!
https://cozodb.org
Mozilla Public License 2.0
3.36k stars 100 forks source link

List methods don't work on Validity #246

Open andrewbaxter opened 7 months ago

andrewbaxter commented 7 months ago

Right now list methods don't work with tuples (error about not being a list value) and there are no tuple-specific methods.

I think I saw it mentioned somewhere else, but there's no way to extract values from a tuple AFAICT. Validities are a special case where to_bool and to_int will extract the second and first values, but for user generated tuples there's no such option (and really, first and last or get(, 0) get(, 1) would probably be clearer for those anyway).

andrewbaxter commented 7 months ago

Sorry, I think I was somewhat confused here. first/last/get don't work on Validity data, despite being described as a tuple:

{:create hos {state: String, year: Validity => hos: String}}
{
?[state, year, hos] <- [['US', [2001, true], 'Bush'],
                        ['US', [2005, true], 'Bush'],
                        ['US', [2009, true], 'Obama'],
                        ['US', [2013, true], 'Obama'],
                        ['US', [2017, true], 'Trump'],
                        ['US', [2021, true], 'Biden']]

:put hos {state, year => hos}
}
{?[state, year] := *hos{state:state, year:year_}, year = first(year_)}

returns

  help: 'first' requires lists

They seem to work fine for user-generated tuples.