Can an SPL function call submit()? - infosphere-spl

I'm trying to call submit() from an SPL function (that is called from a Custom operator), but it is not working. It complains about the name of my stream:
submit({prop1=value1, prop2=value2}, MyStream);
ERROR: An unknown identifier was referenced in the SPL program: MyStream
Is this supported?

No, this is not supported. submit() can only be called inside the Custom operator, within its onTuple, onPunct, or onProcess clauses. It cannot be called from an SPL function.

Related

how to write own defined function that includes an imported function?

I am learning Julia programming by reading the book Think Julia I am including the following:
enter image description here
forward is a function in the ThinkJulia module. It acts on the Turtle() object, to move it forward. Why, after the line using ThinkJulia , am I getting this error. Do I have to be more specific in Julia about importing functions? I thought using would give me access to all functions in that particular module?
You need to pass a value not to its type to forward, so define your function like this:
function forward_len(t::Turtle, d)
forward(t, d)
end
and things should work
The error message is clear, you do not have forward method matching your parameter types.
Try 'Forward' instead of 'forward';
function forward_len(t::Turtle, d)
Forward(t, d)
end
Source: https://juliagraphics.github.io/Luxor.jl/v0.11/turtle.html

Functional parameters in Go functions

Is there a way to pass a function(which can be generic) to another function?
I know that with known input types and return types we can pass a function but a generic approach is needed
When reading the Go2 proposal on generic: "Type Parameters - Draft Design", I am not sure you would be able to pass as parameter a generic function without explicitly specify the type used by said function
See "Instantiating a function"
Go normally permits you to refer to a function without passing any arguments, producing a value of function type.
You may not do this with a function that has type parameters; all type arguments must be known at compile time.
That said, you can instantiate the function, by passing type arguments, but you don't have to call the instantiation. This will produce a function value with no type parameters.
// PrintInts is type func([]int).
var PrintInts = Print[int]

Is C++ function belonging to "callable type"

The C++11 standard says:
20.8.1 Definitions [func.def]
1 The following definitions apply to this Clause:
2 A call signature is the name of a return type followed by a parenthesized comma-separated list of zero or
more argument types.
3 A callable type is a function object type (20.8) or a pointer to member.
4 A callable object is an object of a callable type.
So my understanding is, a function is an instance of function type, so function is not "callable type". But definitely we can call functions.
This definition is a bit weird to me. Where did I get wrong?

Call Functions in CakePHP 3

Using CakePHP3, I have a dynamic set of customer supplied math functions in the file Operations.php (no class since it's a generic customer supplied for many php aps) and have it saved at src/Utils/. At the heading of my controller under the line "use App/Controller/AppController;" I have the line "use App/Utils/Operations;". When I try to call a function it errors with undefined function. How do I call these functions from a controller?

How to use JSCallback in Firebreath?

I'd like to add an event handler in my C++ code.
I followed document in firebreath.org (Callback from Scripts):
FB::JSObjectPtr doc = m_host->getDOMDocument()->getJSObject();
doc->Invoke("addEventListener", FB::variant_list_of("load", FB::make_callback(this, &mine::foo)));
but seeing following error:
/home/dq/manager/mine.cpp: In member function ‘void mine::init()’:
/home/dq/manager/mine.cpp:284:119: error: no matching function for call to ‘variant_list_of(const char [5], FB::JSAPIPtr)’
/home/dq/manager/mine.cpp:284:119: note: candidates are:
/usr/include/firebreath/ScriptingCore/variant_list.h:122:5: note: FB::detail::VariantListInserter FB::variant_list_of(FB::variant)
/usr/include/firebreath/ScriptingCore/variant_list.h:122:5: note: candidate expects 1 argument, 2 provided
/usr/include/firebreath/ScriptingCore/variant_list.h:128:5: note: FB::VariantList FB::variant_list_of()
/usr/include/firebreath/ScriptingCore/variant_list.h:128:5: note: candidate expects 0 arguments, 2 provided
In file included from /home/deqing/manager/mine.h:51:0,
from /home/deqing/manager/mine.cpp:37:
/usr/include/firebreath/ScriptingCore/JSCallback.h: In function ‘FB::JSAPIPtr FB::make_callback(const T&, F, bool) [with T = mine*, F = void (mine::*)(), FB::JSAPIPtr = boost::shared_ptr<FB::JSAPI>]’:
/home/dq/manager/mine.cpp:284:118: instantiated from here
/usr/include/firebreath/ScriptingCore/JSCallback.h:47:107: error: request for member ‘get’ in ‘instance’, which is of non-class type ‘mine* const’
/usr/include/firebreath/ScriptingCore/JSCallback.h:49:97: error: request for member ‘get’ in ‘instance’, which is of non-class type ‘mine* const’
make[2]: *** [CMakeFiles/mine.dir/manager/mine.cpp.o] Error 1
make[1]: *** [CMakeFiles/mine.dir/all] Error 2
make: *** [all] Error 2
Looking into the implementation of make_callback(), I tried following instead:
FB::JSObjectPtr doc = m_host->getDOMDocument()->getJSObject();
doc->Invoke("addEventListener", FB::variant_list_of("load")(FB::JSAPIPtr(new FB::JSCallback(FB::make_method(this, &mine::foo)))));
Compile passed this time, but my function - mine::foo() is not called with document.load()
By using "Inspect Element" in chrome, in "Event Listeners" I can see a new listener is added for "load". However, the listenerBody is a <JSAPI-Auto Javascript Object>.
I'm afraid this is why mine::foo() is not called, Javascript don't know how to call it because it is not a function, only an object.
Any one know how to get this done?
Another way that I can think of is:
Register a custom event handler
Fire the custom event on init
I'd like to use something like:
registerEventMethod("myevent", &mine::foo);
so that when myevent is fired, mine::foo() can be called.
The question here is, mine::foo is not a JSObjectPtr, so this snippet of code wouldn't work.
What is the proper way to use registerEventMethod() in this case?
registerEventObject was really never intended to be called manually; it is used by the internal implementations of addEventListener and attachEvent. The purpose is to attach javascript handlers to events in the plugin.
I would recommend you use something like boost's signals and slots to implement your own c++-side event system; FireBreath's stuff was never intended to solve that problem. On the other hand, if you wanted to look at it it would probably be possible to extend FireBreath's functionality to support that and I have it on very good authority that the gatekeeper for FireBreath would probably entertain a pull request to that end. =]