What does the `` mean in swift and why is it useful? [duplicate] - swift

This question already has answers here:
Swift variable name with ` (backtick)
(3 answers)
Closed 2 years ago.
What does the `` around default mean in the following code below?
In what cases would you want to use it?
static let `default` = User(id: UUID(), name: "Anonymous")
Thank you in advanced

The backticks allow you to use restricted keywords in places where they otherwise couldn't be used, such as variable names.
default is a restricted keyword in Swift, but by putting backticks around it, it becomes a valid variable name.
Without the backticks, your code would result in the error
Keyword 'default' cannot be used as an identifier here

Related

List available functions in perl module [duplicate]

This question already has answers here:
Can I dynamically get a list of functions or function names from any Perl module?
(3 answers)
How do I list available methods on a given object or package in Perl?
(5 answers)
List all the subroutine names in perl program
(3 answers)
Get list of methods/functions defined explicitly in a module
(1 answer)
Closed 6 months ago.
First of all, I am entirely new in perl so I apologize if this is a rather basic question.
We have a perl script that calls on a module — lets name it module_x
It’s called in the script using this line.
require module_x
Sadly, this does not have a documentation and we can’t access the server where this script is.
Is there a way to know what functions are available in the module? Similar to desc in python.

Multiline anonymous function in Matlab? [duplicate]

This question already has answers here:
How to execute multiple statements in a MATLAB anonymous function?
(5 answers)
Closed 7 years ago.
Is it possible to create multiline anonymous function in Matlab?
There are no appropriate examples in documentation, but also no direct denials. In web discussions I found some derisions of askers as if it silly wish. Nowadays, when most languages introducing lambda expressions with multiline capability this looks strange.
No, unfortunately this is not possible.

Name a variable as string in Matlab [duplicate]

This question already has answers here:
Create variables with names from strings
(6 answers)
Closed 7 years ago.
Assume the variable FileName contains a string such as Name1. How do I make a variable with the name Name1?
The example 4 at this page seems to be similar, but I cant get it to work. Is it the right way to do it?
http://se.mathworks.com/help/matlab/ref/genvarname.html
What you see in "Example 4" is accused as bad programming style. The documentation also contains a section why to avoid eval.
I would recommend a struct with dynamic field names to achieve similar.
filename='name1';
mydata=struct();
mydata.(genvarname(filename))=load(filename);
Besides better performance, you also get additional functionality when handling multiple files. For example structfun to apply a function to all your data or fieldnames to get all filenames.
For what you want to do, the eval function is there for you:
FileName = 'Name1';
eval([FileName ' = 18;']); % Executes "Name1 = 18;"
and now the variable Name1 is created and has a value of 18.
The function genvarname has a different purpose, which is to generate acceptable and non-conflicting variable names, and not the variables themselves.

How to I access argv and argc in swift? [duplicate]

This question already has answers here:
How do I access program arguments in Swift?
(6 answers)
Closed 8 years ago.
I'm writing a command line app using Swift but I'm not sure how to get access to the arguments passed in. In C/Obj-c it seems relatively painless but if I try:
argv[0]
I get an error: Use of unresolved identifier 'argv'
There are two ways to do this:
The constants C_ARGC and C_ARGV. They are analogous to the argc and argv you'd see in a main() function.
The CommandLine.arguments array will contain all of the arguments to the process. (In Swift 2, CommandLine was called Process)

Perl calling subroutine with leading '&' [duplicate]

This question already has answers here:
When should I use the & to call a Perl subroutine?
(4 answers)
Closed 9 years ago.
Every now and then I see Perl scripts where subroutines are called with a leading '&'.
Is this legacy, or does it give any benefit?
As calling the subroutine without the ampersand sign works as well.
sub mysub {
print "mysub\n";
}
mysub;
&mysub;
Thx/Hermann
Calling with & is generally a code smell that somebody doesn't know what they're doing and are in a Perl4 mindset. In your specific example, it works exactly the same. However, calling with & disables function prototypes, so advanced users may use it in certain circumstances. You should expect to see a comment why next to the call in that case.