file:write and arrow operator

Wednesday, 4 July 2018 · 4 messages
GC
Giuseppe Celano4 Jul 2018 18:21 #
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
CG
Christian Grün4 Jul 2018 18:28 #
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
Quoted text · Giuseppe Celano · 11 lines
On Wed, Jul 4, 2018 at 6:21 PM Giuseppe Celano <celano at 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 > >
KD
Kirsten, Dirk4 Jul 2018 18:51 #
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 at gmail.com<mailto:christian.gruen at 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
Quoted text · Giuseppe Celano · 2 lines
On Wed, Jul 4, 2018 at 6:21 PM Giuseppe Celano <celano at informatik.uni-leipzig.de<mailto:celano at 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
GC
Giuseppe Celanoin reply to Giuseppe Celano, 4 Jul 2018, 18:214 Jul 2018 18:57 #
Thanks to both of you! This is very helpful. I will experiment with both solutions. Ciao, Giuseppe
Quoted text · Giuseppe Celano · 10 lines
> On Jul 4, 2018, at 6:21 PM, Giuseppe Celano <celano at 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 > >

⚡Generated with XQuery