Zorba: functions implemented from os (xquery-operators)? - xquery

I would like to use functions from the xquery-operators namespace (http://www.w3.org/2002/08/xquery-operators) in Zorba, specifically, op:add-dayTimeDuration-to-dateTime.
However I get a static error: "op:add-dayTimeDuration-to-dateTime": function with arity 2 not declared". I had to declare the op namespace to get that far, so maybe Zorba uses a different prefix. Or, maybe these functions aren't implemented. I've had difficulty trying to search for answers to these questions.
Thanks!

From the spec: Functions defined with the op prefix are described here to underpin the definitions of the operators in [XML Path Language (XPath) 2.0], [XQuery 1.0: An XML Query Language] and [XSL Transformations (XSLT) Version 2.0]. These functions are not available directly to users, and there is no requirement that implementations should actually provide these functions. For this reason, no namespace is associated with the op prefix. For example, multiplication is generally associated with the * operator, but it is described as a function in this document.....
Can't you just use the + operator?

Related

Gremlin math step has issues if a reserved word "exp" is used in a label name

I have a query which has the math function like below,
math('number1-expected_value').next()
It throws error as
**GremlinServerError: 499: {"detailedMessage":"Unknown function or variable 'cted_value' at pos 20 in expression 'number1 - expected_value'","requestId":"01e3f9e6-3cf2-4af0-bf94-5a4979d488b4","code":"InvalidParameterException"}**
I know, the exp keyword is reserved for exponentiation operation. Is there anyone who knows how to use a keyword as a normal string inside the math function in gremlin?
Note:
when I change the variable as "eexpected_value", it works. If I choose expeected_value, it throws same error. Hence expe and expee make operation of exponen
This appears to be an issue in the Gremlin math step which is built using EXP4J. I have opened the following Jira issue to track within the Apache TinkerPop project: https://issues.apache.org/jira/browse/TINKERPOP-2856
For now, the best workaround as you discovered is just to avoid using variable names that contain any of the math built in function names (like exp).

glob()-like C function however supporting the "**"-recursive syntax?

I've just noticed that passing e.g.: **/main.c to POSIX function glob() doesn't yield correct results (they are empty). Is there a similar and also such a common (POSIX, etc.) function that would support the "**"-recursive syntax? Or maybe some single file, small library with such feature?

How and why is a GNAT.Strings.String_List use clause disallowed? How can you use System.Strings.String_List."&" with infix notation?

Posting for two reasons: (1) I was stuck on unhelpful compiler errors for far too long for such a simple issue and I want the next person to google those messages to come upon my (or other) answers, and (2) I still don't understand disallowing a use clause, so my own answer is really incomplete.
In order to call a program in two places with mostly the same arguments, I want to use the '&' to append to a default list inline:
declare
Exit_Code : constant Integer := GNAT.OS_Lib.Spawn (Program_Name => "gprbuild", Args => (Default_GPR_Arguments & new String'(File_Name_Parameter)));
begin
if Exit_Code /= 0 then
raise Program_Error with "Exit code:" & Exit_Code'Image;
end if;
end;
However, the compiler complains that System.Strings.String_List needs a use clause:
operator for type "System.Strings.String_List" is not directly visible
use clause would make operation legal
But inserting use System.Strings.String_List yields:
"System.Strings.String_List" is not allowed in a use clause
I also got this warning:
warning: "System.Strings" is an internal GNAT unit
warning: use "GNAT.Strings" instead
So I substituted GNAT for System in the with and the use clause and got an extra error in addition to the original 'you need a use clause for System.Strings.String_List' one:
"GNAT.Strings.String_List" is not allowed in a use clause
Why is GNAT.Strings.String_List not allowed in a use clause? Section 8.5 on use clauses doesn't seem to state anything on disallowed packages, so is this a compiler bug? Is it possible to define a new package that cannot have a use clause?
In a use clause of the form
use Name;
Name must be a package name. GNAT.Strings.String_List is a subtype name, not a package name.
There are a number of ways to invoke "&" for String_List. The simplest is to use the full name:
GNAT.Strings."&" (Left, Right)
but presumably you want to be able to use it as an operator in infix notation, Left & Right. Ways to achieve this, in decreasing specificity:
function "&" (Left : GNAT.Strings.String_List; Right : GNAT.Strings.String_List) return GNAT.Strings.String_List renames GNAT.Strings."&"; This makes this specific function directly visible.
use type GNAT.Strings.String_List; This makes all primitive operators of the type directly visible.
use all type GNAT.Strings.String_List; This makes all primitive operations of the type (including non-operator operations) directly visible.
use GNAT.Strings; This makes everything in the package directly visible.
Looks like it is a design decision. And many other packages in System follows this rule. From the s-string.ads (package specification for System.String):
-- Note: this package is in the System hierarchy so that it can be directly
-- be used by other predefined packages. User access to this package is via
-- a renaming of this package in GNAT.String (file g-string.ads).
My guess why this is done in that way: because it isn't in the Ada specification, but extension from GNAT.

Is it possible to #inheritParams from a function within another package?

I wrote an importer for an obscure TSV format, which I want to package and document: https://github.com/katrinleinweber/MWX-import/commits/package
The importer function passes a renamed skip_lines parameter to utils::read.table so I would like to "pass" the latter's documentation of skip into my .Rd. However, trying a few notations like #inheritParams utils::read.table skip always results in Warning: Failed to find topic […].
Whether it's actually possible to inherit a single, specific parameter from another package's function is not clear to me after reading http://r-pkgs.had.co.nz/man.html and https://blog.rstudio.org/2017/02/01/roxygen2-6-0-0/.
Is it possible? If yes, thanks for any hint!
If you use #inheritParams utils::read.table, then any parameters in your function which match those in utils::read.table will be inherited (provided they aren't already explicitly documented). So this would cover your use case if you used skip instead of skip_lines.
I don't think it's possible to inherit documentation for a parameter when your parameter name doesn't match though.

Function signature not found despite showing with methods(...)

I am new to Julia, so this might be trivial.
I have a function definition within a module that looks like (using URIParser):
function add!(graph::Graph,
subject::URI,
predicate::URI,
object::URI)
...
end
Outside of the module, I call:
add!(g, URIParser.URI("http://test.org/1"), URIParser.URI("http://test.org/2"), URIParser.URI("http://test.org/1"))
Which gives me this error:
ERROR: no method add!(Graph,URI,URI,URI)
in include at boot.jl:238
in include_from_node1 at loading.jl:114
at /Users/jbaran/src/RDF/src/RDF.jl:79
Weird. Because when I can see a matching signature:
julia> methods(RDF.add!)
# 4 methods for generic function "add!":
add!(graph::Graph,subject::URI,predicate::URI,object::Number) at /Users/jbaran/src/RDF/src/RDF.jl:29
add!(graph::Graph,subject::URI,predicate::URI,object::String) at /Users/jbaran/src/RDF/src/RDF.jl:36
add!(graph::Graph,subject::URI,predicate::URI,object::URI) at /Users/jbaran/src/RDF/src/RDF.jl:43
add!(graph::Graph,statement::Statement) at /Users/jbaran/src/RDF/src/RDF.jl:68
At first I thought it was my use of object::Union(...), but even when I define three functions with Number, String, and URI, I get this error.
Is there something obvious that I am missing? I am using Julia 0.2.1 x86_64-apple-darwin12.5.0, by the way.
Thanks,
Kim
This looks like you may be getting bit by the very slight difference between method extension and function shadowing.
Here's the short of it. When you write function add!(::Graph, ...); …; end;, Julia looks at just your local scope and sees if add! is defined. If it is, then it will extend that function with this new method signature. But if it's not already defined locally, then Julia creates a new local variable add! for that function.
As JMW's comment suggests, I bet that you have two independent add! functions. Base.add! and RDF.add!. In your RDF module, you're shadowing the definition of Base.add!. This is similar to how you can name a local variable pi = 3 without affecting the real Base.pi in other scopes. But in this case, you want to merge your methods with the Base.add! function and let multiple dispatch take care of the resolution.
There are two ways to get the method extension behavior:
Within your module RDF scope, say import Base: add!. This explicitly brings Base.add! into your local scope as add!, allowing method extension.
Explicitly define your methods as function Base.add!(graph::Graph, …). I like this form as it more explicitly documents your intentions to extend the Base function at the definition site.
This could definitely be better documented. There's a short reference to this in the Modules section, and there's currently a pull request that should be merged soon that will help.

Resources