Hi Christian,
I would say that datatype of variable "label" is JLabel. If I was programming in Java I guess I want Java to return the string: "JLabel" probably combined with the URI of the source were JLabel is defined.
Cheers, Rob.
PS. I'm no Java-programmer ( yet :-)
-----Oorspronkelijk bericht----- Van: Christian GrĂ¼n [mailto:christian.gruen@gmail.com] Verzonden: donderdag 30 juli 2015 9:55 Aan: Rob Stapper CC: Eliot Kimber; Florent Georges; BaseX Onderwerp: Re: [basex-talk] question
Hi Rob,
In that regard, XQuery is pretty similar to many other programming languages. Think e.g. of the following Java code:
public JLabel label = new JLabel();
What do you think is the "data type" of the variable named "label", and how would you like to deal with it in Java?
Cheers, Christian
On Thu, Jul 30, 2015 at 9:41 AM, Rob Stapper r.stapper@lijbrandt.nl wrote:
Eliot, Florent,
Thank you both for your reaction.
I've been thinking about the typeswitch-command too but it feels weird: I have this variable, inside XQuery its type is known but for retrieving it I have to go through all types and ask XQuery if it is this one. I hoped for a more direct solution.
I've been thinking about the inspect-function too but that one is more mend for documentation-purposes and I guess performance is an issue there.
Thanx again,
Rob
-----Oorspronkelijk bericht----- Van: Eliot Kimber [mailto:ekimber@contrext.com] Verzonden: woensdag 29 juli 2015 19:56 Aan: Florent Georges CC: Rob Stapper; BaseX Onderwerp: Re: [basex-talk] question
I am happy to be corrected.
Cheers,
E.
Eliot Kimber, Owner Contrext, LLC http://contrext.com
On 7/29/15, 10:42 AM, "Florent Georges" <fgeorges@gmail.com on behalf of lists@fgeorges.org> wrote:
Hi,
That would base the type annotation on the lexical value. For instance, the string '0' would be labelled as "integer" (given you test for xs:integer before xs:string):
let $var := '0' return if ( $var castable as xs:integer ) then 'integer' else if ( $var castable as xs:string ) then 'string' else 'unknown type' (: -> 'integer' :)
The operator "instance of" would solve that problem. But then, for that purpose, there is the "typeswitch" instruction:
typeswitch ( '0' ) case xs:integer return 'integer' case xs:string return 'string' default return 'unknown type' (: -> 'string' :)
Regards,
-- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/
On 29 July 2015 at 17:34, Eliot Kimber ekimber@contrext.com wrote:
I believe you need to use the "castable as" or "instance of" operators to determine the type, e.g.:
let $typeName := if ($somevar castable as xs:integer) then 'integer' else if ($somevar castable as xs:string) then 'string' else 'unknown type'
Or something close to that. There is also "instance of", which might be
I also found this paper, which might be interesting:
http://www.balisage.net/Proceedings/vol8/html/Holstege01/BalisageVol8
Hol st ege01.html
Cheers,
E.
Eliot Kimber, Owner Contrext, LLC http://contrext.com
On 7/29/15, 9:54 AM, "Rob Stapper" <basex-talk-bounces@mailman.uni-konstanz.de on behalf of r.stapper@lijbrandt.nl> wrote:
Hello,
I must be overlooking something, so excuses in advance, but: How can I retrieve the datatype of a variable?
TIA, Rob Stapper
<https://www.avast.com/antivirus> Dit e-mailbericht is gecontroleerd op
virussen met Avast antivirussoftware.
www.avast.com https://www.avast.com/antivirus
Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. https://www.avast.com/antivirus
--- Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. https://www.avast.com/antivirus