[Versa] EBNF (start) (functions)

Uche Ogbuji uche.ogbuji at fourthought.com
Thu Sep 15 13:58:37 MDT 2005


On Thu, 2005-09-15 at 12:02 -0600, Michael Olson wrote:
> Note, I have broken this into a couple of threads to help keep things  
> straight.
> 
> >
> >> [1] versa-query ::= declaration-list? query
> >>
> >> [2] declaration-list ::= declaration ';' declaration-list ?
> >>
> >> [3] declaration ::= variable-declaration
> >>                      | function-declaration
> >>                      | prefix-declarion
> >>                      | context-declaration
> >>
> >> [4] variable-declaration ::= "@variable" qname '=' query
> >>
> >> [5] function-declaration  ::= "@function" qname '(' ( qname ( ','  
> >> qname
> >> ) * ) * ')' = query-expression
> >
> > I think we should add defaulted (keyword) argument support here.
> > Perhaps
> >
> > [5] function-declaration  ::= "@function" qname '(' ( qname ( '='
> > query-expression )? ( ',' qname ( '=' query-expression )? ) * ) * ')' =
> > query-expression
> 
> I'm not sure I agree that these need support for that.  These function  
> definitions are very closely bound to the query.  They have no life  
> outside of this query and are most likely written to clean up the  
> actual query.
> 
> Granted, you can do a few new things with a function now that were  
> probably not (easily) possible in versa-1 (recursion in versa???) even  
> so, I think that having them so bound to the local context means there  
> is not a lot of need for defaulted or key word arguments.

I'll have to think about that.


> >> [20] filter-expression ::= '(' filter-expression ')'
> >>                             | filter-expression slice-operator
> >>                             | function-call
> >
> > Do we need to add function (i.e. function name)?
> >
> 
> 
> What is a function name and how does it differ from a function call?

It's back to our discussion about first class functions.

To use a Python analog:

def spam(x)
   return x + 1

map(spam, [1,2,3])
    ^^^^

Thats'a  function reference (better way to say it than "function name").

But you can still do:

def spam(x)
   return lambda x: x + 1

map(spam(), [1,2,3])
    ^^^^^^

That's a function call (or invocation).


> 
> >>                             | anonymous-function-call
> >
> > Isn't this just the same '{' query '}' as above?  i.e. anonymous
> > equivalent to the named function I mention above?
> 
> No, I'm gong with your syntax of (!x : $x) for now.
> 
> The '{' query '}' above is a way to nest traversals with out the parser  
> getting confused.  This is the main reason for may initial statement of  
> "I added symbols..."

Can you give an example?

> >>                             | pattern
> >>                             | operator-expression
> >>                             | variable-reference
> >
> >> [21] function_call ::= qname '(' ( argument-expression ( ','
> >> argument-expression ) * ) ? ')'
> >
> > ditto passing kwargs here

I think if we support kwargs at all we should support them in both
definition and invocation.


> This one I agree with because these functions could be defined  
> externally and used across queries.
> 
> >> [23] argument-expression ::= argument-expression slice-operator
> >>                               | '(' argument-expression ')'
> >>                               | filter
> >>                               | traverse
> >>                               | pattern
> >>                               | function-call
> >>                               | anonymous-function-call
> >
> > again this should be function name and anonymous function defn.
> >
> 
> I agree that changing "anonymous-function-call" to just  
> "anonymous-function" may clean up some confusion.  So in the grammar  
> where I said "anonymous-function-call" I meant (!x :$x)

OK.  That makes more sense.  Yes, I don't see that as a "call".  I see
that as  a definition, or "function reference" or even just "anonymous
function".


-- 
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