syntax

ES6 Arrow Functions and Promise Chaining condensed syntax explanation

十年热恋 提交于 2020-06-17 15:53:31
问题 In the following code block, can someone please provide links or an explanation for the condensed alert statement syntax. I understand the preceding expanded equivalent code that is commented out and contains the message parameter. However, I cannot find a reference to the syntax for omitting the message parameter: let timeoutPromise = new Promise((resolve, reject) => { setTimeout(() => { resolve('Success!'); }, 2000); }); /* timeoutPromise.then(message => { alert(message); }) */

VB.NET, two ways of passing array as parameter are identical?

风流意气都作罢 提交于 2020-06-16 04:01:31
问题 A question that always confuses me: in VB.NET, when declare a Function (or Sub ) that accepts an array as parameter, one can write either: Sub func(par as integer()) or: Sub func(par() as integer) . So, is par as integer() absolutely identical to par() as integer , even if I add various decorations (e.g. Byval ) to them? I googled and found this page on MSDN, which seems to use the second one. I also tried to write some test functions, which also suggest that there is no difference. But it

What is the meaning of angle brackets in Python?

99封情书 提交于 2020-06-10 12:46:49
问题 I found the following lines in the scikit-learn package: if is_sparse: problem = csr_set_problem( (<np.ndarray[np.float64_t, ndim=1, mode='c']>X.data).data, (<np.ndarray[np.int32_t, ndim=1, mode='c']>X.indices).shape, (<np.ndarray[np.int32_t, ndim=1, mode='c']>X.indices).data, (<np.ndarray[np.int32_t, ndim=1, mode='c']>X.indptr).shape, (<np.ndarray[np.int32_t, ndim=1, mode='c']>X.indptr).data, Y.data, (<np.int32_t>X.shape[1]), bias, sample_weight.data) else: ... All my searches for "angle

Unicode subscripts and superscripts in identifiers, why does Python consider XU == Xᵘ == Xᵤ?

偶尔善良 提交于 2020-06-10 08:33:28
问题 Python allows unicode identifiers. I defined Xᵘ = 42 , expecting XU and Xᵤ to result in a NameError . But in reality, when I define Xᵘ , Python (silently?) turns Xᵘ into Xu , which strikes me as somewhat of an unpythonic thing to do. Why is this happening? >>> Xᵘ = 42 >>> print((Xu, Xᵘ, Xᵤ)) (42, 42, 42) 回答1: Python converts all identifiers to their NFKC normal form; from the Identifiers section of the reference documentation: All identifiers are converted into the normal form NFKC while

Meaning of double bracket “[[foo()]] type name;” syntax in c++?

无人久伴 提交于 2020-06-10 02:14:28
问题 In this article about avoiding False Sharing, the following code snipped for alignment is presented: // C++ (using C++0x alignment syntax) template<typename T> struct cache_line_storage { [[ align(CACHE_LINE_SIZE) ]] T data; char pad[ CACHE_LINE_SIZE > sizeof(T) ? CACHE_LINE_SIZE - sizeof(T) : 1 ]; }; What is the meaning of line 4? I've never seen this double bracket syntax before. 回答1: That is the attribute specifier syntax. It was introduced as a unified syntax to access what were formerly

What is the meaning of macro in front of class definition in c++

泪湿孤枕 提交于 2020-06-09 05:22:06
问题 What is the syntax in C++ that allows the following construction, where a word appears in between "class" and "class_name"? namespace octave { // Command line arguments. See also options-usage.h. class OCTINTERP_API cmdline_options { public: ... Note, I am not asking the meaning of the macro. I am not asking what it does. I am not asking if it is empty. I am asking about the syntax of class definition. Several sources explain the syntax, but without the word in the middle, for example: class

What is the use of “else” after “for” loop in Python? [duplicate]

被刻印的时光 ゝ 提交于 2020-06-09 05:13:48
问题 This question already has answers here : Why does python use 'else' after for and while loops? (21 answers) Closed 6 years ago . It seems both of the below codes are printing the same, then what is the need of "else" block after "for" loop in python. Code 1: for i in range(10): print i else: print "after for loop" Code 2: for i in range(10): print i print "after for loop" Thanks in advance. 回答1: From the documentation: Loop statements may have an else clause; it is executed when the loop

What is the use of “else” after “for” loop in Python? [duplicate]

邮差的信 提交于 2020-06-09 05:13:22
问题 This question already has answers here : Why does python use 'else' after for and while loops? (21 answers) Closed 6 years ago . It seems both of the below codes are printing the same, then what is the need of "else" block after "for" loop in python. Code 1: for i in range(10): print i else: print "after for loop" Code 2: for i in range(10): print i print "after for loop" Thanks in advance. 回答1: From the documentation: Loop statements may have an else clause; it is executed when the loop

Difference between single and double quotes in Bash

a 夏天 提交于 2020-06-01 07:40:29
问题 In Bash, what are the differences between single quotes ( '' ) and double quotes ( "" )? 回答1: Single quotes won't interpolate anything, but double quotes will. For example: variables, backticks, certain \ escapes, etc. Example: $ echo "$(echo "upg")" upg $ echo '$(echo "upg")' $(echo "upg") The Bash manual has this to say: 3.1.2.2 Single Quotes Enclosing characters in single quotes ( ' ) preserves the literal value of each character within the quotes. A single quote may not occur between

Is there a more ergonomic syntax for Either when using futures?

穿精又带淫゛_ 提交于 2020-06-01 02:28:53
问题 Here's an example of using Tokio to run a function that returns a future: use futures::sync::oneshot; use futures::Future; use std::thread; use std::time::Duration; use tokio; #[derive(Debug)] struct MyError { error_code: i32, } impl From<oneshot::Canceled> for MyError { fn from(_: oneshot::Canceled) -> MyError { MyError { error_code: 1 } } } fn deferred_task() -> impl Future<Item = i32, Error = MyError> { let (sx, rx) = oneshot::channel(); thread::spawn(move || { thread::sleep(Duration::from