What is the new name for this-expression-file-name? - racket

I need the name of the function that returns the path of the expression. In the old mzscheme days the two functions were called this-expression-file-name and this-expression-source-directory but what are they named in Racket?

You can still find this-expression-file-name and this-expression-source-directory in mzlib/etc. But usually now you'd use define-runtime-path to handle this-expression-source-directory, and direct access to the syntax object for the file name.

Related

Apache AGE - Creating Functions With Multiple Parameters

I was looking inside the create_vlabel function and noted that to get the graph_name and label_name it is used graph_name = PG_GETARG_NAME(0) and label_name = PG_GETARG_NAME(1). Since these two variables are also passed as parameters, I was thinking that, if I wanted to add one more parameter to this function, then I would need to use PG_GETARG_NAME(2) to get this parameter and use it in the function's logic. Is my assumption correct or do I need to do more tweaks to do this?
You are correct, but you also need to change the function signature in the "age--1.2.0.sql" file, updating the arguments:
CREATE FUNCTION ag_catalog.create_vlabel(graph_name name, label_name name, type new_argument)
RETURNS void
LANGUAGE c
AS 'MODULE_PATHNAME';
Note that all arguments come as a "Datum" struct, and PG_GETARG_NAME automatically converts it to a "Name" struct. If you need an argument as int32, for example, you should use PG_GETARG_INT32(index_of_the_argument), for strings, PG_GETARG_CSTRING(n), and so on.
Yes, your assumption is correct. If you want to add an additional parameter to the create_vlabel function in PostgreSQL, you can retrieve the value of the third argument using PG_GETARG_NAME(2). Keep in mind that you may need to make additional modifications to the function's logic to handle the new parameter correctly.
The answers given by Fahad Zaheer and Marco Souza are correct, but you can also create a Variadic function, with which you could have n number of arguments but one drawback is that you would have to check the type yourself. You can find more information here. You can also check many Apache Age functions made this way e.g agtype_to_int2.

Get parameter name in Clion plugin

I am developing a plugin for Clion (C++) that needs to access caller parameter name, e.g. if a function is declared:
void fun(int a);
and called
fun(42);
when the intent is invoked on 42 PsiElement it should get the corresponding parameter name, "a" in this case.
In a similar plugin for Intellij (Java), I get the parameter name with PsiCallExpression.resolveMethod() which contains the list of parameters. However, I cannot figure out how to do this in a Clion plugin. I can get a reference of a corresponding OCCallExpression, but it does not seem to contain a reference to the declared function. I tried to play around with ReferencesSearch.search(), but it did not find the declaration of the function.
At the same time, the IDE itself displays all the parameter name hints:
so I suppose it must be possible.
How can I get the parameter name for a given caller argument expression?
Please, look at InlayParameterHintsExtension.forLanguage(OCLanguage.getInstance()) and InlayParameterHintsProvider.getParameterHints

Why a function in swift can have different argument label and name [duplicate]

func mapEachElement (inArray arr: [Int], withFunc aFunc: (Int))
Why would there be "inArray and then "arr"...what's the point?
Same for "withFunc and "aFunc", it makes it more code complicated and also messier to read, why are they even used?
inArray is external name which the caller of the function should use when passing parameters. arr is the internal name which the function implementer uses in the implementation to refer to the parameter. You don't have to supply external name.It makes it more readable. It is more like to make swift function names and parameters readable as Objective-C functions are.
I'm not sold on the issue of having different internal and external names either.
Having or not having external names makes sense to me.
object.BeepXTimes(6) doesn't need an external name for it's parameter because the function name implies the meaning of the parameter.
The rationale, I think, is that sometimes the naming of a function's external parameters is phrased to make sense to the caller in a sentence:
someView.animateInWithDuration(0.25, withTimingFunction: .easeIn)
The external name withTimingFunction makes the function call read like a sentence, but withTimingFunction makes a lousy internal parameter name. You would probably want your parameter name to be just timingFunction. Having separate internal and external parameter names lets you do that.
For me, though, the extra complexity this requires in the function definition doesn't seem worth it. The good news is that the default is to create parameters using the same name for both internal and external parameter names, so the standard syntax is simple and easy to read.
These are internal and external parameter names.
Just like in Obj-C, you might have
- (void)calculateFoo:(id)foo withBar:(id)bar ...
[object calculateFoo:var1 withBar:var2];
in Swift, we use
func calculateFoo(foo: AnyObject, withBar bar: AnyObject) ...
object.calculateFoo(var1, withBar: var2)
The internal names foo and bar are only accessible inside the function/method. The external names provide the argument labels which you use to call the function.
In your case, you need to use the internal name nibBundle. That's the one accessible inside the function body.

What is the point of having two different names for the same parameter?

func mapEachElement (inArray arr: [Int], withFunc aFunc: (Int))
Why would there be "inArray and then "arr"...what's the point?
Same for "withFunc and "aFunc", it makes it more code complicated and also messier to read, why are they even used?
inArray is external name which the caller of the function should use when passing parameters. arr is the internal name which the function implementer uses in the implementation to refer to the parameter. You don't have to supply external name.It makes it more readable. It is more like to make swift function names and parameters readable as Objective-C functions are.
I'm not sold on the issue of having different internal and external names either.
Having or not having external names makes sense to me.
object.BeepXTimes(6) doesn't need an external name for it's parameter because the function name implies the meaning of the parameter.
The rationale, I think, is that sometimes the naming of a function's external parameters is phrased to make sense to the caller in a sentence:
someView.animateInWithDuration(0.25, withTimingFunction: .easeIn)
The external name withTimingFunction makes the function call read like a sentence, but withTimingFunction makes a lousy internal parameter name. You would probably want your parameter name to be just timingFunction. Having separate internal and external parameter names lets you do that.
For me, though, the extra complexity this requires in the function definition doesn't seem worth it. The good news is that the default is to create parameters using the same name for both internal and external parameter names, so the standard syntax is simple and easy to read.
These are internal and external parameter names.
Just like in Obj-C, you might have
- (void)calculateFoo:(id)foo withBar:(id)bar ...
[object calculateFoo:var1 withBar:var2];
in Swift, we use
func calculateFoo(foo: AnyObject, withBar bar: AnyObject) ...
object.calculateFoo(var1, withBar: var2)
The internal names foo and bar are only accessible inside the function/method. The external names provide the argument labels which you use to call the function.
In your case, you need to use the internal name nibBundle. That's the one accessible inside the function body.

what's handle and isa

I need an explanation with a simple examples about the following concepts:
'handle' function
#
+
isa
These are part of API that mathworks has devised.
A folder whose name begins with an # sign contains the definition of Matlab objects.
The folders with the + sign are similar, but they are used to define a "package" or namespace. These are hard to give an example of, but I would recommend looking at the help like gnovice says and looking through your matlab install folders for examples.
The isa() command takes an object and a string and tells you if the object is of the class descibed by the string.
A function handle, is just like a function pointer. You can pass the function handle around if you assign the function to a variable like:
myFuncRef = #isempty
Now you have a reference to the isempty() function which can be use like so:
myFuncRef(somevar)