Hi All,
I was wondering if there is a way to take full advantage of the arrow operator with file:write(). If I want to write the results of a query, it would be ideal, I think, if the first parameter of file:write() were the content to write and the second the path: in this case I could have: my query => file:write("myPath"), where I could easily comment out "=> file:write("myPath")", if needed. However, the first parameter of file:write() is the path, so I end up with using the function in the way I usually use all the other functions (this is not a big problem, but I was wondering if I could take advantage of the arrow operator here: wouldn't it be better to have the path as the second parameter in file:write()?).
Ciao, Giuseppe
Hi Giuseppe,
There has been some open discussion on the semantics of the XQuery arrow operator in the W3 XML Query Group [1]. Back then, it was decided that the left operand of the arrow operator is to be rewritten as the first argument of the invoked function.
If your query returns a single item, you can use the simple map operator:
your query ! file:write("yourPath", .)
If not, you will have to use a FLWOR expression or similar constructs.
Cheers, Christian
[1] https://www.w3.org/Bugs/Public/show_bug.cgi?id=26889
On Wed, Jul 4, 2018 at 6:21 PM Giuseppe Celano celano@informatik.uni-leipzig.de wrote:
Hi All,
I was wondering if there is a way to take full advantage of the arrow operator with file:write(). If I want to write the results of a query, it would be ideal, I think, if the first parameter of file:write() were the content to write and the second the path: in this case I could have: my query => file:write("myPath"), where I could easily comment out "=> file:write("myPath")", if needed. However, the first parameter of file:write() is the path, so I end up with using the function in the way I usually use all the other functions (this is not a big problem, but I was wondering if I could take advantage of the arrow operator here: wouldn't it be better to have the path as the second parameter in file:write()?).
Ciao, Giuseppe
Hi Guiseppe,
You could also write a helper library and simply switch the parameters yourself. So your module file.xqm would look something like that:
module namespace f = "http://guiseppe/file";
declare function f:write($items as item()*, $path as xs:string) as empty-sequence() { file:write($path, $items) };
And then in your code you could use that as you intended
import module namespace f="http://guiseppe/file"; "test" => f:write("out.txt")
If you use this frequently I think it is the most convenient way. Changing the function signature I think is not going to happen because it will break existing applications.
Cheers Dirk
Von meinem iPhone gesendet
Senacor Technologies Aktiengesellschaft - Sitz: Eschborn - Amtsgericht Frankfurt am Main - Reg.-Nr.: HRB 105546 Vorstand: Matthias Tomann, Marcus Purzer - Aufsichtsratsvorsitzender: Daniel Grözinger
Am 04.07.2018 um 18:28 schrieb Christian Grün <christian.gruen@gmail.commailto:christian.gruen@gmail.com>:
Hi Giuseppe,
There has been some open discussion on the semantics of the XQuery arrow operator in the W3 XML Query Group [1]. Back then, it was decided that the left operand of the arrow operator is to be rewritten as the first argument of the invoked function.
If your query returns a single item, you can use the simple map operator:
your query ! file:write("yourPath", .)
If not, you will have to use a FLWOR expression or similar constructs.
Cheers, Christian
[1] https://www.w3.org/Bugs/Public/show_bug.cgi?id=26889
On Wed, Jul 4, 2018 at 6:21 PM Giuseppe Celano <celano@informatik.uni-leipzig.demailto:celano@informatik.uni-leipzig.de> wrote:
Hi All,
I was wondering if there is a way to take full advantage of the arrow operator with file:write(). If I want to write the results of a query, it would be ideal, I think, if the first parameter of file:write() were the content to write and the second the path: in this case I could have: my query => file:write("myPath"), where I could easily comment out "=> file:write("myPath")", if needed. However, the first parameter of file:write() is the path, so I end up with using the function in the way I usually use all the other functions (this is not a big problem, but I was wondering if I could take advantage of the arrow operator here: wouldn't it be better to have the path as the second parameter in file:write()?).
Ciao, Giuseppe
Thanks to both of you! This is very helpful. I will experiment with both solutions.
Ciao, Giuseppe
On Jul 4, 2018, at 6:21 PM, Giuseppe Celano celano@informatik.uni-leipzig.de wrote:
Hi All,
I was wondering if there is a way to take full advantage of the arrow operator with file:write(). If I want to write the results of a query, it would be ideal, I think, if the first parameter of file:write() were the content to write and the second the path: in this case I could have: my query => file:write("myPath"), where I could easily comment out "=> file:write("myPath")", if needed. However, the first parameter of file:write() is the path, so I end up with using the function in the way I usually use all the other functions (this is not a big problem, but I was wondering if I could take advantage of the arrow operator here: wouldn't it be better to have the path as the second parameter in file:write()?).
Ciao, Giuseppe
basex-talk@mailman.uni-konstanz.de