[xquery-talk] Empty or Null Array?

Eliot Kimber ekimber at contrext.com
Thu Jul 16 07:51:47 PDT 2015

I see my error: accessing a member that does not exist is a dynamic error,

let $array := []
let $item1 := $array(1)

Throws an error. 

I naively expected it to return an empty sequence. But upon reflection the
defined behavior in the spec is correct, otherwise you wouldn't be able to
distinguish the lack of a member and a member whose value is an empty

So array:size($array) := 0 is the correct way to test for an empty array.

It would be useful if the 3.1 spec had some examples of these cases--I'm
not seeing any examples of creating an empty array in the Array
Constructors section.


Eliot Kimber, Owner
Contrext, LLC

On 7/16/15, 9:31 AM, "John Snelson" <talk-bounces at x-query.com on behalf of
John.Snelson at marklogic.com> wrote:

>Hi Eliot,
>The grammar allows you to use both "[]" and "array{}" to create an empty
>On 16/07/2015 10:11, Eliot Kimber wrote:
>> I'm using an array to pass values down a recursive function call chain.
>> I noticed that, at least with BaseX but also based on my reading of the
>> 3.1 spec, that you cannot construct an empty array.
>> Is this correct?
>> If so, how can one have a function where the array is effectively empty?
>> E.g., given this function declaration:
>> declare ns:myFunc($arg1 as xs:string+, $arg2 as array(*)?, $arg3 as
>> xs:string) {};
>> How can I satisfy the second argument when in fact I have no items for
>> array?
>> I tried passing in () but BaseX says "Cannot cast empty-sequence() to
>> array(*)", which makes sense.
>> I would expect array{} to be a valid constructor, such that
>> array:size(array{}) = 0 is true but that does not appear to be allowed
>> in the 3.1 spec.
>> What have I missed?
>> Thanks,
>> Eliot
>> ----
>> Eliot Kimber, Owner
>> Contrext, LLC
>> http://contrext.com
>> _______________________________________________
>> talk at x-query.com
>> http://x-query.com/mailman/listinfo/talk
>John Snelson, Lead Engineer                    http://twitter.com/jpcs
>MarkLogic Corporation                         http://www.marklogic.com
>talk at x-query.com

More information about the talk mailing list