[Versa] statements function
Uche Ogbuji
uche.ogbuji at fourthought.com
Tue Sep 13 16:54:18 MDT 2005
On Tue, 2005-09-13 at 10:38 -0600, Michael Olson wrote:
> >> { statements(type(rss:item)|-dc:creator-> <mailto:foo at yahoo.com>) }
> >>
> >>> The query I would use would be
> >>>
> >>> subgraph o1 = statements ( all() - rdfs:isDefiniedBy -> <Ontology
> >>> 1>,rdf:value,*);
> >>> subgraph o2 = statements ( all() - rdfs:isDefiniedBy -> <Ontology
> >>> 2>,rdf:value,*);
> >>> list( {o1} all() |- * -> {o2}ground(.),
> >>> {o2} all() |- * -> {o1}ground(.) )
> >>
> >> or wouldn't those queries be statements ( all() |- rdfs:isDefiniedBy
> >> -> <Ontology1>,rdf:value,*)
> >>
> >> if the statements function works the way I suggested?
> >
> > I think I lost track somewhere. Why put a traversal expression within
> > the statements function? Why not just
> >
> > statements(type(rss:item), dc:creator, <mailto:foo at yahoo.com>)
> >
> > If I recall correctly, what we'd discussed is that each argument to the
> > function can be a pattern or a predicate? A list is a pattern by
> > enumeration?
>
> This is how I remember it.
>
> > But we lose some of the functional power of traversal expressions if
> > so.
> >
> > type(rss:item) - ns:age -> gt(18)
> >
> > No way to express this in statements() form as discussed so far. One
> > approach would be to have currying:
>
> Right. Is this supported in the current traverse function?
No, but traverse is understood to be weaker than a traversal expression
(no special syntax support).
> Though you would be able to express it as
>
> statements( type (rss:item), ns:age, . > 18)
I don't see how this would work. Do you mean:
statements( type (rss:item), ns:age, ". > 18")
?
if so, how do we flag the difference between string and subquery? I
never liked the conflation of string and subquery in Versa 1.0, which is
why I want to make subqueries first class constructs in 2.0.
> > statements(type(rss:item), dc:creator, curry(gt, 18))
> >
> > But yeah right the average Versa punter will have that much comfort
> > with
> > hard core functional language techniques such as currying.
> >
> > I think this is a good time to bring up what I think is a need in Versa
> > for less clumsy first-class functions.
> >
> > Right now functions such as distribute and filter can take a string and
> > basically cast it to a dynamic expression. I think we should tie this
> > up more neatly. For example:
> >
> > filter(type(ns:Person), (!x: $x - ns:age -> gt(18))
> >
> > Basically
> >
> > anon-function ::= '(!' param-list ':' expr ')'
> >
> > Or to give an example using the statements function:
> >
> > statements(type(rss:item), dc:creator, (!x: $x - ns:age -> gt(18))
> >
> > I prefer naming the parameter (functional macro-like) rather than using
> > the magic "." particle. We also then get the flexibility of functions
> > with multiple parameters, etc.
>
> I like this better then currying, though I don't see how you would
> specify an anon function with more then one parameter. Maybe
>
> ( !x = ., !y = "foo" : $x - ns:age -> gt($y)
>
> and the default of (!x : query) would default "x" to the current
> context.
Well, based on the grammar snippet above:
anon-function ::= '(!' param-list ':' expr ')'
You wouldn't have a ! in front of each parameter. For 2 parameters:
(! x, y: $x - ns:age -> gt($y))
You're right that I haven't accounted for a syntax for "defaulting" a
parameter, but considering that anon functions will probably only be
passed in at the spot they're used, is this such a big deal?
What I mean is that in every spot you might want to type
(! x, y=18: $x - ns:age -> gt($y))
Wouldn't you already know well enough to just write
(! x: $x - ns:age -> gt(18))
When I was talking about multiple parameters, I honestly didn't have a
use case for it, but I guess I should think that through as part of this
whole exercise.
I did consider that if you did want to do such things as defaulting
functions, you could go back to the state (formerly known as
context? :-) ) operations we've been discussing:
@def f(x, y=18): $x - ns:age -> gt($y)
> In the current grammar, I supported something similar to this with the
> reuse of the "{}" symbols. It just did not support parameters.
OK. I kind of wondered whether these two uses were compatible, but I
wasn't sure, so I went with new symbols. Maybe we should generalize {}
a bit and also use it for the anon funct syntax:
{x: $x - ns:age -> gt(18)}
--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://fourthought.com
http://copia.ogbuji.net http://4Suite.org
Use CSS to display XML, part 2 - http://www-128.ibm.com/developerworks/edu/x-dw-x-xmlcss2-i.html
XML Output with 4Suite & Amara - http://www.xml.com/pub/a/2005/04/20/py-xml.html
Use XSLT to prepare XML for import into OpenOffice Calc - http://www.ibm.com/developerworks/xml/library/x-oocalc/
Schema standardization for top-down semantic transparency - http://www-128.ibm.com/developerworks/xml/library/x-think31.html
More information about the Versa
mailing list