Function which one must not shadow in Matlab - matlab

I am writing some helper functions for unit testing in Matlab. For that I need to overload Matlab functions, built-ins etc. In the documentation is written, that one shall not overload the function builtin. I also found out that one must not overload the lt operator, since it seems to get called by the UI all the time.
Is there a list of functions which one shall not overload, or do you know of any particular problems from overloading some specific functions?
Further Information:
My use case: I want to do mutation-testing and faul-injection.
in ther words, sometimes the called functions shall return wrong results or throw an error. If I overload the Matlab functions, I do not have to change the source code to do that.

Related

How to synthesize programs with multiple types in Rosette?

I am looking to write a DSL in Rosette with the goal of synthesizing a function. The DSL is based off a very small subset of Haskell, and is strongly typed. I therefore want to make sure that anything that Rosette generates is well-typed.
One way I could consider going about this is writing a "is-well-typed-code" function (that's something I've already done in Julia, which I'm porting from), and then assert that it must hold true of the synthesized function. However, I do not see with define-synthax and synthesize how to view the code both as a syntactic object (i.e., an S-expr that can have any function applied to it) and as a semantic function when synthesizing.
I could also imagine using a cond inside the define-synthax module over all possible types of the arguments (this is a finite set for this small DSL), and defining the possible forms separately for each type. However, including conds inside define-synthax does not seem to be possible.
Any ideas?
Thanks!

What is a callback in programming?

I have heard this term tossed around, can anybody explain what it means and what problem it solves. Also where does this originate from.
Simplified it's when you pass a function to another function, and that other function call you back using the function you passed.
It's useful for asynchronous programming, when events can happen at any time. Or for generic handling of certain functionality to make some algorithms more generic (for example in C++ you can pass a comparison function to the std::sort function, and your comparison function will be used to compare two items when sorting).

Why Matlab Coder is slow?

I'm trying to build a Mex function in Matlab-r2015a using Matlab Coder. The entry point function I want to convert is alg.m which is called by main.m.
Following the procedure, I'm at the step in which I'm asked to "define the type of each input for every entry point function". I choose the automatic procedure and enter main.m
My problem is: in order to define the type of each input, the Matlab Coder takes a very long time; the same problem appears at the next step, when I have to check whether there are issues in the Matlab code. Is that because Matlab has to execute the whole main.m+alg.m?
I suspect this should be the case because when I impose values of parameters that make the computation faster, the input types and issue checks are done immediately. Anyway, I would like to have some more explanations and, if any, suggestions to solve the problem.
You are correct, both steps Define Input Types and Check for Run-Time Issues run main.m which will in turn run alg.m.
If the input data types for the entry-point function don’t change, two test-benches (namely two versions of your main.m) can be written – a shorter one that invokes the entry-point once for defining input types, and a more comprehensive one that thoroughly exercises alg.m. The former can be used to quickly define input types, and the latter should be used when checking for run-time issues.

Use Run-time Parameters in a Matlab-code S-Function

I have to write a Level-2 S-Function in Matlab code (C is not viable) which takes in some parameters and uses them alone and in combination.
First I tried tunable parameters, but unfortunately I haven't succeded in tuning them (the documentation doesn't tell how to set_param for this purpose).
Then I have bumped into documentation of Run-Time parameters that says
The value of a run-time parameter that corresponds to multiple dialog
parameters is typically a function of the values of the dialog
parameters.
So I deduced that a runtime parameter would suit well, but the same documentation doesn't say how to tune and access them from a Matlab S-function, only from a C one.
Also, in in this page is documented a RuntimePrm object that seems similar to DialogPrm, but trying to write the values result in an error.
Is there any way to "cache" parameter combinations without using DWorks, which would affect subsequent linearization with fake states?

Why to use empty parentheses in Scala if we can just use no parentheses to define a function which does not need any arguments?

As far as I understand, in Scala we can define a function with no parameters either by using empty parentheses after its name, or no parentheses at all, and these two definitions are not synonyms. What is the purpose of distinguishing these 2 syntaxes and when should I better use one instead of another?
It's mostly a question of convention. Methods with empty parameter lists are, by convention, evaluated for their side-effects. Methods without parameters are assumed to be side-effect free. That's the convention.
Scala Style Guide says to omit parentheses only when the method being called has no side-effects:
http://docs.scala-lang.org/style/method-invocation.html
Other answers are great, but I also think it's worth mentioning that no-param methods allow for nice access to a classes fields, like so:
person.name
Because of parameterless methods, you could easily write a method to intercept reads (or writes) to the 'name' field without breaking calling code, like so
def name = { log("Accessing name!"); _name }
This is called the Uniform Access Principal
I have another light to bring to the usefulness of the convention encouraging an empty parentheses block in the declaration of functions (and thus later in calls to them) with side effects.
It is with the debugger.
If one add a watch in a debugger, such as, say, process referring for the example to a boolean in the focused debug context, either as a variable view, or as a pure side-effect free function evaluation, it creates a nasty risk for your later troubleshooting.
Indeed, if the debugger keeps that watch as a try-to-evaluate thing whenever you change the context (change thread, move in the call stack, reach another breakpoint...), which I found to be at least the case with IntelliJ IDEA, or Visual Studio for other languages, then the side-effects of any other process function possibly found in any browsed scope would be triggered...
Just imagine the kind of puzzling troubleshooting this could lead to if you do not have that warning just in mind, because of some innocent regular naming. If the convention were enforced, with my example, the process boolean evaluation would never fall back to a process() function call in the debugger watches; it might just be allowed in your debugger to explicitly access the () function putting process() in the watches, but then it would be clear you are not directly accessing any attribute or local variables, and fallbacks to other process() functions in other browsed scopes, if maybe unlucky, would at the very least be very less surprising.