What does "fcn" stand for when naming callback functions? - terminology

Frequently I find callback functions called something fcn, but I can't figure out what fcn stands for or what it is a contraction of. What does fcn stand for?
e.g. my_callback_fcn as defined here
https://www.mathworks.com/help/matlab/matlab_prog/timer-callback-functions.html

That's short for "Function" by pronunciation.
You can find the following in that page:
"StartFcn",
"StopFcn",
"TimerFcn",
"ErrorFcn",

Related

Julia - How to pass kwargs from a function to a macro

You can define a function to pass its keyword arguments to inner functions like this:
function example(data;xcol,ycol,kwargs...)
DoSomething(; spec=:EX, x=xcol, y=ycol, kwargs...)
end
Now, the function DoSomething accepts many arguments, such as color. This works for functions, but I'd like to do this with a macro from VegaLite.jl:
function example(data;xcol,ycol,kwargs...)
#vlplot(data=data,mark=:point, x=xcol, y=ycol,kwargs...)
end
example(df,xcol=:Miles_per_Gallon, ycol=:Horsepower, color=:Origin)
Note that the code above does not work.
So the answer here is... it's tricky. And in fact, in general, this isn't possible unless the macro itself supports it.
See, macros do their transformations at parse time — and often will exploit what you've actually written to mean something different and special. For example, #vlplot will specially handle and support JSON-like {} syntaxes. These aren't valid Julia code and can't be passed to a function you define (like example)!
Now, it's tempting to see this and think, ok, let's make that outer example thing into a macro, too! But it's not that easy. I'm not sure it's possible to have a general answer that will always pass the arguments appropriately and get the hygiene correct. I'm pretty sure you need to know something about how the macro you're calling handles its arguments.
you need to add ; before kwargs to signal they are kwargs not positional arguments e.g.:
DoSomething(;spec=:EX, x=xcol, y=ycol, kwargs...)
(this is the answer for DoSomething being a function as this was the original formulation of the question)

Why is a function call called a "function call"?

I know what a function call is. I know what it does. I've debugged it a lot. I do have some intuitive sense on why it makes sense to use the term "function call", but when it comes down to it, I can't explain this properly like I could with a return statement.
For example, with a return statement the answer is: it's called a "return" because you return to where you came from. You return to the line from where the function was called. So it makes sense why the end of a function (implicitly or explicitly) returns.
I've noticed that for people who speak English as their native language this easier to grasp (especially with more obscure words such as "cache"). However, for people like me (Dutch, learned English through videogames and subtitled television), it's harder to grasp.
I googled for this question, but I get all kinds of entries what a function call is and how it works. I associate the word "call" a lot with telephones, since that's what I use it mainly for in English.
I asked a similar question on what the "de-" means in the word "dereference" here: What does the de- prefix in dereference mean? Is there a linguistic explanation for it?
The term call has a wide meaning. When used in calling a function, you would probably best interpret that as short for calling a function for execution. See the following meaning given by the Free Dictionary:
To order or request to undertake a particular activity or work; summon:
She was called for jury duty. He was called to the priesthood.
This is very close in meaning to another expression used for invoking functions: call upon a function.
That should make sense in the context of functions. The function provides a service, and it is called upon to provide it now. In both cases the meaning is: request the code in a function to be executed.
NB: In Dutch you may translate with oproepen or (less common) aanroepen.
Thanks to #hvj I noticed that the comments of the really related -- though not the same! Since I want to know it linguistically not historically -- question referenced a paper that was behind a paywall ( see http://dl.acm.org/citation.cfm?id=609816&CFID=888670230&CFTOKEN=46456506 ). I read the paper and then I found this small piece:
In this type of routine it is arranged that a sequence of operations is performed each time the subroutine is called into action.
So apparently the Zeitgeist of that time was phrasing it as calling sub-routines into action. Side note: they also talked about returning control from a sub-routine to the main program.

Is there a term for a function that modifies its arguments?

I'm not really classically educated in CS or mathematics. I'm just thinking there should be a term for this in pass-by-reference laungauges such as php. IE. functions that return a result (like how you'd want most functions to work) versus functions that modify an in-parameter.
Is there such a term?
The only term that I have heard relating to what you are talking about is: parameter idempotence
Simply put this type of function guarantees that the arguments remain untouched.
As far as a function that changes parameters I haven't heard any particular terms but I just say: parameter mutating.
From my experience any function that takes a reference to an object, it's a fairly safe bet that it will be mutating that parameter in some way.

Fortran: how to pass function name in a common block

In Fortran, is it possible to put a function in a common block as in:
COMMON /myblock/ func
(where x is some variable and func is a function).
My problem is that I would like to create a function s(x) that calls an external function func(x) but without passing func in s(x). For my project, s(x) has to be a function of only one variable, i.e., I do not want to do:
function s(x,func)
s=func(x)
Instead, I am hoping I could do:
function s(x)
common /myblock/ func
s=func(x)
Or, if someone has some other suggestion using modules or something, this will be great.
Thanks in advance for any help.
o.
and then have the same common (myblock) in the subroutine that calls s(x).
I don't believe that this is possible in any portable way. Some implementations may allow you to use some tricks to do it.
The modern way to do this is with a pointer to a function. The pointer could be passed as an argument or, for the design of this question, placed into a module. See, for example, Function pointer arrays in Fortran
I think you are not supposed to use common blocks for this, but modules. Put your function func in a module called myfunctions and then when needed insert at use myfunctions statement and thats it.
Modern fortran standards prohibit this. From 5.5.2 of Fortran 2003:
A common-block-object shall not be ... a function name, an entry name...
And at any rate, using global variables to pass around non-constant data is just a terrible, terrible idea. As ja72 points out, you could do this with modules, but I refuse to demonstrate it with sample code.

Declaration vs. Prototype vs. Symbol vs. Definition vs. Implementation

I see the terms "declaration," "prototype" and "symbol" thrown around interchangeably a lot when it comes to code like the following:
void MyUndefinedFunction();
The same goes for "definition" and "implementation" for things like this:
void MyClass::MyMethod()
{
// Actual code here.
}
Are there any distinctions between the terms, as with "argument" and "parameter?" Or are they truly synonymous?
Note: I'm not sure if this belongs here or on Programmers, so I posted it on both sites. If anyone has any objections, let me know and I'll delete one.
Unless you run into a purist, they are generally interchangable, except for symbol and prototype (difficult to give absolutes on language-agnostic)
symbol generally refers to a hook point for linking 2 bits of code together, such as a library entry point, or a target for resolving static linking
prototype generally refers to a definition of what a function/method looks like (arguments, return type, name, various types of visibility), but doesn't include an implementation.
You missed function vs. method, but my definition is:
function a callable bit of code that isn't bound to an object
method a callable bit of code in an object's namespace. Generally implemented by the compiler as a function that takes the object instance as it's first argument.
Possibly parameter hints at limiting scope, and therefore read-only.
Note If you ask a purist, you're more likely to have an argument than a parameter.
The difference between declaration and prototype is mainly in C, where the following is a non-prototype declaration:
int foo();
Note that this is different from:
int foo(void);
The latter is a prototype for a function taking no arguments, while the former is a declaration for a function whose argument types are not specified in the declaration. This can actually be useful to avoid function-pointer-type casts with certain uses of function pointers, but it's very easy to mess up, and messing it up invokes undefined behavior. Many C programmers consider non-prototype declarations harmful, and gcc has a warning option to flag them.