i'm confused about IS OF and TREAT(). what the difference between IS OF and TREAT() (when come to sub-type and super-type) in oracle?
IS OF is an operator that tests an object and returns either true or false.
TREAT is a function that converts an object and returns an object.
So use IS OF it you just want to test whether an object is of some more specific subtype. Use TREAT if you not only want to test but use the object.
Related
I come from a C# background and try to migrate some of my time series library to R.
One of the benefits of OOP is that I can tuck away variables in a class and pass this as reference.
I read up on R environments, lists, ... and I'm still not sure about the right approach. If I would use a list then I would need to check the function argument:
exists()
(btw: Is there also a function to test for the elements in a list)
I could create a list, pass it as an argument and then write the result back in a list. But is this the right approach?
Any comments ...
exists is seldom used. If you need it, maybe you do something wrong.
missing is sometimes used.
Functions sometimes, but not very often, receive lists as parameters, and often return lists.
To test whether a list foo has an element bar, use is.null(foo$bar). This is FALSE if the list has the element, TRUE otherwise.
To determine if a variable is a function, I use the following method
function isFunction(variable)
return type(variable) == "function"
end
To my knowledge, this is a string comparison. As I've understood it, string comparisons are relatively slow and I fear this function might be a bottleneck in my code. Is there a less costly way to determine if a variable is a function?
I'm hoping there's a function which returns an integer that indicates the type of the variable instead. Or I can ask my question another way: How does type(var) determine the type of a variable? Surely, each variable can't hold a string representing its type so I'm guessing there is some backend-stuff in lua that looks up the string "function" when invoking type(var).
String comparisons in Lua are really fast because most strings are interned.
Internally, every Lua value contains a tag identifying its type. It is this tag that type uses.
I'm quite new to R, and I am currently trying to write a code with some foolproofing.
For example, I have a function where let's say it takes (n,c,l)
where the variables are supposed to be numerical, character, and logical types.
Is there a way so that I can check these things?
for example, I've tried is.integer(3) ... this returns FALSE.
Ideally, what I'm looking for is for example, suppose abc() is some function that will test if l==T or l==F (checking if the proper logical is input.
then: abc(T) gives TRUE, and abc(2) gives FALSE.
Also is there a way to check if n is specifically an integer? I mean I could check if (n%%1==0), but is there a specific function for this?
Thank you kindly in advance for what may seem to be a very basic question.
As suggested in the comments, you can use
is.numeric(3)#check whether numeric
is.integer(3L)#check whether integer
is.logical(TRUE)#Check whether logical
is.logical(2)#will return false
is.character("abc")#check whether character
is.character(4)#will return false
Similarly, you can check for other data types in R. Hope this is of help.
Suppose I am given an unknown R object given obj.
I want to do a quick check (i.e. non-definitive) to see, if an assignment obj<-value has a chance to success, i.e. to see if there is a function <- defined for such assignment.
Is it possible to do it without performing the actual assignment in R?
Given the following query
let $a := xs:dateTime("2012-01-01T00:00:00.000+00:00")
let $b := xs:dateTime($a)
let $c := xs:dateTime($a cast as xs:string)
(: cannot - don't know how to - execute the function without assignment :)
let $d := adjust-dateTime-to-timezone($a, xs:dayTimeDuration("PT1H"))
return (<a>{$a}</a>,<b>{$b}</b>,<c>{$c}</c>)
the output is as follows
<a>2012-01-01T01:00:00+01:00</a>
<b>2012-01-01T01:00:00+01:00</b>
<c>2012-01-01T00:00:00Z</c>
Based on XQuery's documentation on constructor functions (the constructor function for a given type is used to convert instances of other atomic types into the given type) this is the expected behaviour. Calling xs:dateTime($a) simply returns $a as there is no need to cast, but xs:dateTime($a cast as xs:string) creates a new xs:string from $a first. However this requires an extra conversion.
Is there any other way to tackle this problem? Or conversions are cheap and I shouldn't care?
(If it makes any difference my XQuery processor is BaseX 7.2.)
It seems it does a make a difference that I'm using BaseX. I've really thought that this is the way the xs:dateTime constructor function and the adjust-dateTime-to-timezone function should be working, this is why I misinterpreted the XQuery documentation.
Given the input I've been given by Dimitre and Ranon it seems the problem described is gone.
By the why my use case is, or more like it was, that I wanted to make a date-time interval based query against my XML data set's date-time element. Because the input parameters and the source date-time values used different time-zones I had to make time-zone corrections with the above function, which modified its input parameter (the original source date-time in my case), however I wanted to preserve the original value. Given the function's name adjust-dateTime I thought that it's okay that it modifies its argument, so I automatically thought that I had to copy my original value using a constructor function to be able to keep the original date-time value.
Looks like you ran into some really weird bug.
Your line 5 shouldn't change $a-c at all as XQuery is a functional programming language with immutable variables (adjust-dateTime-to-timezone should not change your variables) and without side effects. Thats why you were forced to assign $d, otherwise your calculated results directly would have been thrown away.
I just submitted some bug request. Zorba is doing your query right, you can use it for understanding the problem.
BaseX as you preferred XQuery processor will do within few days, too. I or some other BaseX team member will trigger you here as soon as it's fixed.
I guess your problem arised from missunderstanding and wrong behaviour of BaseX and should be solved. Feel free to ask again if anything stayed unclear with your query.
The output that is reported is incorrect.
The correct output (produced running Saxon under oXygen) is:
<a>2012-01-01T00:00:00Z</a>
<b>2012-01-01T00:00:00Z</b>
<c>2012-01-01T00:00:00Z</c>
The adjust-dateTime-to-timezone() function, as any other function cannot modify its arguments -- its effect is only contained in the variable $d -- which you don't use in the return clause.