[xquery-talk] Hashes

Jonathan Robie jonathan.robie at datadirect.com
Wed Sep 20 17:15:48 PDT 2006


Tim Finney wrote:
> Sometimes I wish that XQuery had hashes:
>
> Clunky XQuery 1.0 way:
>
> if ($n = "a") then "aardvark"
> else if ($n = "b") then "bandicoot"
> ...
> else if ($n = "z") then "zebra"
> else ()
>
> Declunked way:
>
> define variable $animals as xqy:hash {
>   "a" => "aardvark", "b" => "bandicoot", ... , "z" => "zebra"
> }
>
> $animals[$n]
>   

Seems reasonable - but why not just use a switch like in other languages?

  switch ($n) {
     case "a": "aardvark"
     case "b": "bandicoot"
     case "z": "zebra"
    default: "say, what?"
  }

Obviously, not a candidate for XQuery 1.0, which is already a Candidate 
Recommendation. And which has great implementation experience, so I'm 
guessing we'll be a Proposed Recommendation soon.

Jonathan

-- 
Read my Blog: http://blogs.datadirect.com/jonathan_robie/
Learn XQuery: http://media.datadirect.com/download/docs/ddxquery/tutorial_query.html
Learn XQJ (the JDBC for XQuery): http://www.datadirect.com/developer/xquery/topics/xqj_tutorial/
Get DataDirect XQuery: http://www.datadirect.com/products/xquery/




More information about the talk mailing list