Discussion:
[xquery-talk] Functional XPath commands
Ihe Onwuka
2014-01-24 13:14:59 UTC
Permalink
So I have just written

if (@firstpage eq 0) then floor($totalPagesDecimal) else
ceiling($totalPagesDecimal)

but how close would

(floor,ceiling)[@firstpage + 1]($totalPagesDecimal) have been

I'm guessing I would at least have to put some function invoking
paraphenalia around the calls to floor and ceiling (hopefully not).
Christian Grün
2014-01-24 13:26:24 UTC
Permalink
Post by Ihe Onwuka
but how close would
Try this:

(floor#1,ceiling#1)[@firstpage + 1]($totalPagesDecimal)
Ihe Onwuka
2014-01-24 13:43:19 UTC
Permalink
Then the right answer was very close........ no just joking.

Thanks - nice that you don't have to do any unnecessary function wrapping.

On Fri, Jan 24, 2014 at 1:26 PM, Christian Grün
Post by Ihe Onwuka
but how close would
Ihe Onwuka
2014-01-26 05:53:06 UTC
Permalink
and it came to pass that the innocuous looking conditional in the if
statement demands that @firstpage is cast to xs:integer before it will
work lest there be complaints of unTypedAtomic (or whatever it said)
comparisons with xs:integer.

What is the pourquoi of this. Why no type promotion (or is it
downcasting) in effect here. What could be simpler than comparing to
0.

Verily twas a tough spot, I went through every other conditional in
the program first because it looked to me like the least likely
suspect.
Post by Ihe Onwuka
So I have just written
ceiling($totalPagesDecimal)
but how close would
I'm guessing I would at least have to put some function invoking
paraphenalia around the calls to floor and ceiling (hopefully not).
Liam R E Quin
2014-01-26 07:24:02 UTC
Permalink
Post by Ihe Onwuka
Verily twas a tough spot, I went through every other conditional in
the program first because it looked to me like the least likely
suspect.
Post by Ihe Onwuka
ceiling($totalPagesDecimal)
The XPath engine does not know that @firstpage is an integer - unless
it's schema-aware and you supplied a schema, perhaps.

if (@firstpage treat as xs:integer eq 0)
might be one way round it.

Liam
--
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml
Michael Sokolov
2014-01-26 16:16:28 UTC
Permalink
If you're a big fan of implicit type casts, you might want to take a
look at JavaScript. This movie
https://www.destroyallsoftware.com/talks/wat has some pretty funny
examples (see, eg [] + [], [] + {}, {} + {}, etc. -- none of them ends
up being what you might expect).

-Mike
Post by Ihe Onwuka
and it came to pass that the innocuous looking conditional in the if
work lest there be complaints of unTypedAtomic (or whatever it said)
comparisons with xs:integer.
What is the pourquoi of this. Why no type promotion (or is it
downcasting) in effect here. What could be simpler than comparing to
0.
Verily twas a tough spot, I went through every other conditional in
the program first because it looked to me like the least likely
suspect.
Post by Ihe Onwuka
So I have just written
ceiling($totalPagesDecimal)
but how close would
I'm guessing I would at least have to put some function invoking
paraphenalia around the calls to floor and ceiling (hopefully not).
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Ihe Onwuka
2014-01-26 18:31:21 UTC
Permalink
No I'm a fan of type inference suffering from an XSLT hangover.

On Sun, Jan 26, 2014 at 4:16 PM, Michael Sokolov
If you're a big fan of implicit type casts, you might want to take a look at
JavaScript. This movie https://www.destroyallsoftware.com/talks/wat has
some pretty funny examples (see, eg [] + [], [] + {}, {} + {}, etc. -- none
of them ends up being what you might expect).
-Mike
Post by Ihe Onwuka
and it came to pass that the innocuous looking conditional in the if
work lest there be complaints of unTypedAtomic (or whatever it said)
comparisons with xs:integer.
What is the pourquoi of this. Why no type promotion (or is it
downcasting) in effect here. What could be simpler than comparing to
0.
Verily twas a tough spot, I went through every other conditional in
the program first because it looked to me like the least likely
suspect.
Post by Ihe Onwuka
So I have just written
ceiling($totalPagesDecimal)
but how close would
I'm guessing I would at least have to put some function invoking
paraphenalia around the calls to floor and ceiling (hopefully not).
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Loading...