Using find_library() in cmake function - cmake

In my project I use function, which calles find_library(...). Function is defined in SomeScript.cmake.
It works fine if called one time. But now I want to use it several time in my project. The problem is
that find_library caches the first result, and simply doesn`t run again.
So, the part I don't understand - function should provide it's own scope. But it looks like that there is,
only one "copy" of the function with all variables cached. Is it really so? And is there a correct way to use
find_library(...) inside a user function?

Related

Dynamic project-wide variable in Emacs

I'd like to have a project-wide variable which I can change during looking at that project. In other words, I'd like to get it affected whenever opening a file. Yes, I know .dir-locals.el exist in Emacs world. But I think it would be reset to the value set in .dir-locals.el whenever opening a file under that project.
Could I get some hints from you, please?
For this kind of thing you might want to use a function instead of a variable (directly). Specifically, use a getter and setter function.
All of your project code can invoke the getter function to get the value (which can be cached in a variable). And all of your code can invoke the setter function to change the value (which, again, can be cached in a variable).
These functions can be visible globally to your project. The cache variable would be accessed only by the getter and setter functions.
But as for code everywhere in your project being informed when the value gets updated and do what's appropriate with the new value whenever that happens, see #Phil's comment about the use of a variable - the same considerations apply.
You can have a hook in the setter function (or advise it), so that it does something additional (e.g. informs interested/subscribed code) whenever it updates the value.
For a variable you can do something similar using, as #Phils said in a comment, using add-variable-watcher.
For a user-option variable you can do something similar using :set and :get functions in the defcustom. (But those take effect only if changes are made using appropriate Customize functions or the Customize UI.)
You can eval in the dir-locals.el So, if you have a variable my-var that you want to be able to change with setq you could do something like
((nil . ((eval . (or (boundp 'my-var) (setq my-var 'default))))))
There are warnings about using eval in a dir-local though, since any code could be run there.

Use data in plugin outside the SCIPsolve call

I would like to share data between a plugin and my main function (this is, use it outside the call to the SCIPsolve function). For example, a branching rule sets a certain int variable to 1 and then, after the optimization is done I can go and check wether the variable was changes or not.
I thought I could accomplish this by using the plugin data (e.g. SCIP_BranchruleData) but it can't be accessed from outside the plugin's source file.
How can I do it?
I will appreciate any help.
Rodolfo
An easy solution is to add a getter function to the branchrule which you implement in branch_xyc.c and prototype in branch_xyz.h. Then your code needs to include the header file and you can access the fields in the branchdata.
See also the documentation of branch_allfullstrong.cpp where an external function is defined and you can see how to get the branchdata and branchrule when passing just a SCIP pointer.

How to pass a variable from one require() to another?

I have a variable currently set globally, that I am using in two different require() functions. How can I have it passed from first require() to the other?
As far as I know: you don't. The only way to make them read the same data is by putting it somewhere so they both can read it. Because both require() functions are placed inside a normal JavaScript file, the only scope they share is the global scope.
The other possibility is by passing it to the callback function of the require(), but that means you have to write a "module" that returns your data (or use dojo/text plugin to read a file read-only).
It's not recommended to have two require() statements at all. If we're still talking about the same stopwatch (I've read your code a bit), you should put all event handlers in one require() block. Then you can put the data they both need inside that require() block and they will all be able to read it.
Some reasons why having multiple require() blocks is not beneficial:
Harder to read/maintain: If you have multiple require() blocks, it's confusing. Most people don't use it anyways (recommended or not).
More duplicates: If you're using common modules like dojo/query and dojo/dom, you will have to add them to your module list every time. I don't think it will download the file twice, but it's still more to write/maintain.
Scope issues: As you just noticed, you will have scoping issues like this when multiple require() blocks needs to access the same data. This means you have to put them in global scope (which is another bad practice), write a module with just plain data (not really useful) or you have to wrap both of them in a function, which you have to execute manually (confusing)
Seperation concerns: If you have a valid reason to seperate them, you should be seperating them into modules.

Is there a way in elisp to make variable access trigger a function call?

I am programming in elisp, and I would like to associate a symbol with a function such that an attempt to access the variable instead calls the function. In particular, I want to trigger a special error message when lisp code attempts to access a certain variable. Is there a way to do this?
Example: suppose I want the variable current-time to evaluate to whatever (current-time-string) evaluates to at the time the variable is accessed. Is this possible?
Note that I do not control the code that attempts to access the variable, so that code could be compiled, so walking the tree and manually replacing variable accesses with function calls is not really an option.
You are looking for the Common Lisp define-symbol-macro.
Emacs Lisp lacks this feature, you cannot accomplish what you are trying to do.
However, not all is lost if you just want an error on accessing a variable.
Just makunbound it and access will error out (unless, of course, someone else nds it first).
I don't think you can do that.
As Sam says, define-symbol-macro would be the closest thing in Lisp (tho you make it sound like the accesses might be compiled beforehand, in which case even define-symbol-macro would be powerless). The closest thing in Elisp would be cl-symbol-macrolet, but that is even more limiting than define-symbol-macro since it has to be placed lexically around the accesses.

Using module-wide variables in Powershell 2.0

I've written a module to work with IBMs ClearCase through Powershell. At first it just contained a couple of often used functions, but now I'm expanding it. Most of the commands have to use a ClearTool object ($ct = new-object ClearCase.ClearTool), but I'd rather not have to recreate that object in every function call as it's a bit of overhead.
I also create a ClearCase view in many of these functions, but I can simply check for existence of the view and decide not to recreate it.
My question is, what's the best pattern for this? I can have a "create ct object" function and put the onus on the calling code to maintain it, but I don't think I like that method. Is it possible to have a module-wide variable for the ClearTool object and have Powershell check to see if it's filled before trying to recreate it each time?
Thanks!
In the end I created a couple of module-wide variables. I could hide them if necessary, although I haven't explicitly done that yet. I have a single function to create a view which must be called before doing any actual work and included in that is code to create the ClearTool object. I also have code to set the module-wide variables with the correct ClearTool object for use in other functions and the name of the view.
In the code of each of the functions if the ClearTool object ($ct) has not yet been set, they return an error condition.