More Array Troubles: Syntax Subtlety That I'm Missing

Friday, 17 July 2015 · 2 messages
EK
Eliot Kimber17 Jul 2015 18:30 #
I have this recursive function that takes an array as its second parameter:
declare function lmm:applyScopesToNames(
   $keyNames as xs:string+,
   $keyScopes as array(*),
   $qualifiedNames as xs:string*) as xs:string* {
  let $result :=
      if (array:size($keyScopes) = 0)
         then $qualifiedNames
         else
           let $newNames :=
               for $name in $keyNames
                   return for $scopeName in $keyScopes(1)
                          return $scopeName || "." || $name
           return lmm:applyScopesToNames(
                        $newNames,
                        array:tail($keyScopes),
                        ($qualifiedNames, $newNames)
                   )
   return $result
};
Testing with this input:
let $keyName := "base"
$keyScopes := [("s3", "s4"), ("s1", "s2")]
This call:
let $qualifiedNames :=
   lmm:applyScopesToNames(
      ($keyName),
      $keyScopes,
      ())
Results in the message "Item expected, sequence found: [("s3", "s4"), ("s1", "s2")]." Unfortunately, the BaseX interactive query tool doesn't report the line that produces the message, but the only place I'm passing the full array is in the initial call to the function from my test query. I've also verified that if I pass in [] as the keyScopes parameter then I get the expected result (that is, the value of the 3rd parameter is returned). I've verified that $keyScopes is an array of two sequences and as far as I can tell I'm passing arrays where arrays are expected so I'm not sure what my error is, but there must be one. Thanks, Eliot ---- Eliot Kimber, Owner Contrext, LLC http://contrext.com
EK
Eliot Kimber17 Jul 2015 18:45 #
Please ignore my question: apparently I hadn't saved the module that corrected my bug. So sorry for the noise. Cheers, Eliot ---- Eliot Kimber, Owner Contrext, LLC http://contrext.com On 7/17/15, 9:30 AM, "Eliot Kimber" <basex-talk-bounces at mailman.uni-konstanz.de on behalf of
Quoted text · Eliot Kimber · 68 lines
ekimber at contrext.com> wrote: >I have this recursive function that takes an array as its second >parameter: > > >declare function lmm:applyScopesToNames( > $keyNames as xs:string+, > $keyScopes as array(*), > $qualifiedNames as xs:string*) as xs:string* { > let $result := > if (array:size($keyScopes) = 0) > then $qualifiedNames > else > let $newNames := > for $name in $keyNames > return for $scopeName in $keyScopes(1) > return $scopeName || "." || $name > return lmm:applyScopesToNames( > $newNames, > array:tail($keyScopes), > ($qualifiedNames, $newNames) > ) > return $result >}; > > > >Testing with this input: > >let $keyName := "base" >$keyScopes := [("s3", "s4"), ("s1", "s2")] > >This call: > >let $qualifiedNames := > lmm:applyScopesToNames( > ($keyName), > $keyScopes, > ()) > > >Results in the message "Item expected, sequence found: [("s3", "s4"), >("s1", "s2")]." > >Unfortunately, the BaseX interactive query tool doesn't report the line >that produces the message, but the only place I'm passing the full array >is in the initial call to the function from my test query. > >I've also verified that if I pass in [] as the keyScopes parameter then I >get the expected result (that is, the value of the 3rd parameter is >returned). > >I've verified that $keyScopes is an array of two sequences and as far as I >can tell I'm passing arrays where arrays are expected so I'm not sure what >my error is, but there must be one. > >Thanks, > >Eliot > >---- >Eliot Kimber, Owner >Contrext, LLC >http://contrext.com > > > >

⚡Generated with XQuery