keyword

How do I use a keyword as a variable name?

瘦欲@ 提交于 2019-11-26 14:39:43
问题 I have the following class with the variables from , to and rate . from is a keyword. If I want to use it in the init method below, what's the correct way to write it? More context: The class needs the from variable explicitly as it's part of a json required by a POST endpoint written up by another developer in a different language. So changing the variable name is out of the question. class ExchangeRates(JsonAware): def __init__(self, from, to, rate): self.from = from self.to = to self.rate

What does “default” mean after a class' function declaration?

半腔热情 提交于 2019-11-26 14:05:13
I've seen default used next to function declarations in a class. What does it do? class C { C(const C&) = default; C(C&&) = default; C& operator=(const C&) & = default; C& operator=(C&&) & = default; virtual ~C() { } }; It's a new C++11 feature . It means that you want to use the compiler-generated version of that function, so you don't need to specify a body. You can also use = delete to specify that you don't want the compiler to generate that function automatically. With the introduction of move constructors and move assignment operators, the rules for when automatic versions of

What does static mean in ANSI-C [duplicate]

筅森魡賤 提交于 2019-11-26 13:49:29
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: What does “static” mean in a C program? What does the static keyword mean in C ? I'm using ANSI-C. I've seen in several code examples, they use the static keyword in front of variables and in front of functions. What is the purpose in case of using with a variable? And what is the purpose in case of using with a function? 回答1: Just as a brief answer, there are two usages for the static keyword when defining

Using keywords as identifiers in F#

拜拜、爱过 提交于 2019-11-26 12:45:55
问题 In C#, I can do the following: int @private = 15; And in VB.NET, I can do the following: Dim [Private] As Integer = 15 I am wondering if there is a way in F# to use reserved keywords as identifiers, like there is in VB.NET and C#? 回答1: Given section 3.4 of the F# 2.0 spec: Identifiers follow the specification below. Any sequence of characters that is enclosed in double-backtick marks (`` ``), excluding newlines, tabs, and double-backtick pairs themselves, is treated as an identifier. I

Understanding implicit in Scala

我只是一个虾纸丫 提交于 2019-11-26 12:34:37
I was making my way through the Scala playframework tutorial and I came across this snippet of code which had me puzzled: def newTask = Action { implicit request => taskForm.bindFromRequest.fold( errors => BadRequest(views.html.index(Task.all(), errors)), label => { Task.create(label) Redirect(routes.Application.tasks()) } ) } So I decided to investigate and came across this post . I still don't get it. What is the difference between this: implicit def double2Int(d : Double) : Int = d.toInt and def double2IntNonImplicit(d : Double) : Int = d.toInt other than the obvious fact they have

How to use “raise” keyword in Python [duplicate]

痞子三分冷 提交于 2019-11-26 12:34:34
问题 This question already has an answer here: Manually raising (throwing) an exception in Python 7 answers I have read the official definition of \"raise\", but I still don\'t quite understand what it does. In simplest terms, what is \"raise\"? Example usage would help. 回答1: It has 2 purposes. yentup has given the first one. It's used for raising your own errors. if something: raise Exception('My error!') The second is to reraise the current exception in an exception handler, so that it can be

`static` keyword inside function?

喜你入骨 提交于 2019-11-26 12:24:08
问题 I was looking at the source for Drupal 7, and I found some things I hadn\'t seen before. I did some initial looking in the php manual, but it didn\'t explain these examples. What does the keyword static do to a variable inside a function? function module_load_all($bootstrap = FALSE) { static $has_run = FALSE 回答1: It makes the function remember the value of the given variable ( $has_run in your example) between multiple calls. You could use this for different purposes, for example: function

What is the equivalent of the C# 'var' keyword in Java?

我的未来我决定 提交于 2019-11-26 11:57:42
问题 One use of the var keyword in C# is implicit type declaration. What is the Java equivalent syntax for var ? 回答1: There is none. Alas, you have to type out the full type name. Edit: 7 years after being posted, type inference for local variables (with var ) was added in Java 10. Edit: 6 years after being posted, to collect some of the comments from below: The reason C# has the var keyword is because it's possible to have Types that have no name in .NET. Eg: var myData = new { a = 1, b = "2" };

Groovy: what's the purpose of “def” in “def x = 0”?

ぃ、小莉子 提交于 2019-11-26 11:48:47
问题 In the following piece of code (taken from the Groovy Semantics Manual page), why prefix the assignment with the keyword def ? def x = 0 def y = 5 while ( y-- > 0 ) { println \"\" + x + \" \" + y x++ } assert x == 5 The def keyword can be removed, and this snippet would produce the same results. So what\'s the effect of the keyword def ? 回答1: It's syntactic sugar for basic scripts. Omitting the "def" keyword puts the variable in the bindings for the current script and groovy treats it (mostly

Alternative to a goto statement in Java

我是研究僧i 提交于 2019-11-26 11:44:58
What is an alternative function for the goto keyword in Java? Since Java does not have a goto. Padmarag You could use a labeled BREAK statement: search: for (i = 0; i < arrayOfInts.length; i++) { for (j = 0; j < arrayOfInts[i].length; j++) { if (arrayOfInts[i][j] == searchfor) { foundIt = true; break search; } } } However, in properly designed code, you shouldn't need GOTO functionality. Stephen C There isn't any direct equivalent to the goto concept in Java. There are a few constructs that allow you to do some of the things you can do with a classic goto . The break and continue statements