I have a very short piece of lua code (example: os.date("%Z") ).
I want to know if it is possible (currently or planned) to invoke that code directly on the same page, rather than creating a module with only one function, which job is to call that code.
I know creating a module with other time functions would be approach, but no wiki user will need to use others functions in the future. So creating I don't think it worth creating a library(module) of that kind.
No, that's not possible, currently or planned. You must create a module with one function, and invoke it.
Note that this code snippet is an obviously reusable function, which one might call "getDefaultTimezone".
Related
I'm using reagent to build several alternate root components, only one of which will be mounted on any given page; definitely either/or. These have a degree of commonality in their makeup, hence it will be convenient to move what is common among them to a common namespace.
What would be ideal is if in the file for each of these components I had the option to switch namespace into common, and add defs particular to the component, then switch back, thus avoiding circular dependencies nor needing any kind of inheritance.
I recalled this being possible in common lisp, how wonderful it was, and it also seems possible in clojure.
From Clojurescript docs: ns must be the first form and can only be used once, and in-ns is only usable from the repl.
I'm wondering if there's a way to achieve this kind of thing in clojurescript which is still eluding me.
If not I may need to reconsider my assumptions behind multiple alternate root components; the "many builds within one build" kind of idea, if that makes sense.
Update after some futher experimentation and confusion:
another option might be to split a single namespace across multiple files (is this possible?). Not sure what direction to turn in here.
The fact that in reagent I am using atoms in the global namespace is what's creating the need for circular dependencies if I use a separate namespace for common. Hence, wonder about one global namespace, in which case multiple files might help. Or is the way forward one giant file and one namespace??
Update: I've realised there is a great tension between keeping all app state globally (in my current case, multiple atoms), and passing app state around. My pattern currently is everything global, don't pass any of it around. Passing the necessary state as parameters to fns in the common namespace would solve the problem here (duh!), but then there's the question of what principles are being followed here regarding app state. If I just added a param whenever I needed one, but started with the idea that everything was global, there'd be no real principle to it...
In ClojureScript, everything is pre-compiled into a single static JavaScript "executable", so there is nothing like the repl you are used to in Clojure. Indeed, in CLJS the "Var" concept doesn't really after the compiler, they are just static (constant) variables and cannot be rebound.
Having said that, CLJS does emulate the behavior of Clojure dynamic variables via the binding form, so that may help you to reach your goal. As in CLJ, it creates what amounts to a (thread-local) global variable. This is a degenerate case in CLJS since there is only one thread. However, the source code looks identical to the CLJ case.
Another way to accomplish this is to just use a plain atom as a global variable so you don't have to pass a parameter around.
As always, when using a global variable, it reduces the number of parameters in function call trees, but it creates invisible dependencies between different parts of the code. Somethimes convenient, but usually a bad tradeoff.
I have multiple tcl files getting sourced
source fg_lib.tcl
source stc_lib.tcl
In stc_lib.tcl, there is a function which is only defined in fg_lib.tcl. Can I assume that since fg_lib.tcl is getting sourced, automatically the function will be usable to stc_lib.tcl?
One more question: if a certain function is defined in both the tcl files, depending on the ordering of source as above, which version of the function will be executed? I think function defined in stc_lib.tcl will be, but still would like to clarify.
Thanks,
The source command acts, immediately, as if the content of the file was in the script at the point where the source appears (except for the difference of what info script returns). If both scripts define a procedure foobar, it will be the later script (stc_lib.tcl in your case) that produces the version that is used.
However, if the scripts just define procedures that don't have overlapping names and don't otherwise call the commands they create, the order in which the sources are placed is typically unimportant. The proc command just creates a command; the body of the procedure isn't evaluated until the procedure is called. (This sounds obvious, but it really is exactly like that. The code is exactly what it says it is, and Tcl is all about immediate operational semantics and code that is registered to be run in response to some event.)
Bear in mind that if you are having problems with sources smashing each other, it's probably best to look into putting the code into namespaces or to otherwise find a way to stop entangling things. Writing confusing code is not recommended.
I'm trying to accelerate a piece of code using cuda fortran. This code uses the common statement in the definition of the variables which is not valid in the device code with cuda.
What I did is define the variables in a module instead of using the common statement but this gives me a wrong answer. I'm doing all of these on normal code in order to find a substitute to the common statement.
Code(common)
Code(without common)
I think it should work this way, because these variables are only used by these functions, but it doesn't. Why is that? And what can I do to fix this problem?
After taking a look at your files, I see that you are using OpenACC for Fortran, which is not what I would call CUDA Fortran. I will assume that that is your intent, and that you are not actually intending to use CUDA fortran, but instead you are trying to make the OpenACC code work correctly.
I have 2 suggestions.
Be specific. Which variables, which functions are not working correctly, and what are the results you are getting and what are the results you are expecting? The best scenario would be to provide a short complete, compilable example, rather than just dumping entire files of code into a question. Narrow your problem down to a specific example of something that is not working.
Again, assuming your intent is to use OpenACC fortran, you have already demonstrated that you have at least some idea of how to use the !acc kernels directive. I took a quick look at your code, and the loops you were encasing did not look terribly complicated. My suggestion is that you identify all of the data that is required (input) to these loops and generated (output) from these loops, and include additional !acc data directives, to specify these as copyin for input data and copyout for output data. A specific example/tutorial is given here. Having said that, as long as the data is in scope when the compiler is attempting to use it in an !acc kernels region, I don't think you should be getting incorrect results. But to pursue this further, I think a specific example would be appropriate. In general, use of the !acc data directive will help you to focus your attention on the data needed and make sure the compiler understands how to transfer it to/from the device and when.
And as I mentioned already, please paste code examples that you want others to look at in the actual question, rather than including links.
I have defined list_t in my project that got list module API like list_pop(). But now I have to use MySQL lib to communicate with DB, but the MySQL lib still got its list implements, and also defined a list_pop() API. In my other modules, I have to link both of them, and comes the conflict.
One of my solution is, separately include header file for different list API calling, this works well, but while some function need to call both of MySQL::list_pop() and local::list_pop(), how to notify the compiler the correct link point? Is there some GCC trick that can do these without any changes to local::list_pop()?
For most practical purposes, you are going to have to rename one or the other set of functions. It is probably easier to rename your own than those of MySQL.
The simplest approach is to simply add a prefix that has a higher probability of being unique (enough), such as your initials, or the codename of your project, or something. Or you can rename everything to avoid collisions, being aware that MySQL might add a new function in the future.
This is exactly why namespaces were invented for C++, and why C projects usually have systematic prefixes on sets of functions.
There is a way to solve this. Refactor your list_pop() to, say, my_list_pop().
There is one other way to solve this,
Looking at the header of the MySQL my_list.h here, https://github.com/lgsonic/mysql-trigger/blob/master/mysql/my_list.h you can see that list_pop is just a macro, and its binded at compile time, not at runtime(hence not a real library function). Changing list_pop of MySQL to list_pop_my(just in the #define) can make it do what you want it to do.
I'm currently trying out a few of the new C++0x features, namely std::function and std::bind. These two functions seem rather suitable for a event-delegate-system for C++ that works like in C♯. I've tried myself to create something like delegates before, but the Hacks I would have needed for member-function-pointers were to much for me…
During my tests I noticed that std::bind copies every object you bind. While that surely enhances safety - can't delete a still registered eventhandler :) - it's also a problem with stateful objects. Is there a way to deactivate the copying - or at least a way to obtain the encapsulated object from the std::function again?
PS: Is there a reference for the features that are going to be included in C++0x (hopefully C++11!) In the end it's at major parts of TR1 and a few additions…
I tried cppreference.org, but they are still at an early stage at documentation, cplusplus.com on the other seems to not even have started on covering C++0x.
If you want to avoid copying use std::ref and/or std::cref. They wrap the object into a pseudoreference
It isn't quite right that:
I noticed that std::bind copies every
object you bind.
At least that isn't the intended specification. You should be able to move a non-copyable object into a bind:
std::bind(f, std::unique_ptr<int>(new int(3)))
However, now that the move-only object is stored in the binder, it is an lvalue. Therefore you can only call it if f accepts an lvalue move-only object (say by lvalue reference). If this is not acceptable, and if the source object outlives the binder, then use of std::ref is another good solution (as mentioned by Armen).
If you need to copy the bound object, then all of its bound arguments must be copyable. But if you only move construct the bound object, then it will only move construct its bound arguments.
The best reference is N3242. There isn't a good and comprehensive tutorial that I'm aware of yet. I might start with the boost documentation with the understanding that std::bind has been adapted to work with rvalue-refs as much as possible.
I have created a move compatable version of bind. there are still lots of problems with it like the binders constructor and a few buggylines here and there etc but it seems to work
check it out here
http://code-slim-jim.blogspot.jp/2012/11/perfect-forwarding-bind-compatable-with.html