{?L a rdf:List;
rdf:first ?Z;
rdf:rest rdf:nil.
?Z :hasValue ?V.
:sum :hasValue ?X.
(?X ?V) math:sum ?Y.
}
=> {?Z a :final;
a :selected.
:sum :hasFinalValue ?Y.
}.
But it fails into a dead loop. I guess the problem occurs when updating :sum's value, but cannot find a way to make it work. Is there a way to compute this sum in n3, or is it just not suitable for n3 to do such thing?
(Here is the full code: .n3 file)
If you have a SPARQL 1.1 processor, you can do the following:
SELECT sum(?elem)
WHERE
{ ?list rdf:rest*/rdf:first ?elem
}
...where ?list is bound to the list node.
I think there have been warnings here and elsewhere not to get too tied up in N3 and/or n3logic. It's not a standard and its features aren't faring all that well in the RDF 2 working group. Standards compliance-speaking, it's best to stick with Turtle/SPARQL, at least in the short term.