syntactic-sugar

Syntactic sugar vs. feature

本秂侑毒 提交于 2019-12-05 00:17:42
In C# (and Java) a string is little more than a char array with a stored length and a few methods tacked on. Likewise, (reference vs. value stuff aside) objects are little more than glorified structs with inheritance and interfaces added. On one level, these additions feel like clear features and enhancements unto themselves. On another level, they feel like a marginal upgrade from the status of "syntactic sugar." To take this idea further, consider (I may have some details wrong, but the point remains): transistor elementary logic gate compound gate | | ALU flip-flop | | | | register RAM | |

java, is there a way we can import a class under another name

点点圈 提交于 2019-12-04 23:37:50
is there a way we can import a class under another name? Like if i have a class called javax.C and another class called java.C i can import javax.C under the name C1 and import java.C under the name C2. We can do something like this in C#: using Sys=System; or Vb: Imports Sys=System No, there is nothing like that in Java. You can only import classes under their original name, and have to use the fully qualified name for all that you don't import (except those in java.lang and the current class's package). To be short, no, this isn't possible in Java. No. I think Java deliberately ditched

AWK: shortened if-then-else with regex

不问归期 提交于 2019-12-04 22:56:44
The following AWK format: /REGEX/ {Action} Will execute Action if the current line matches REGEX . Is there a way to add an else clause, which will be executed if the current line does not matches the regex, without using if-then-else explicitly, something like: /REGEX/ {Action-if-matches} {Action-if-does-not-match} Not so short: /REGEX/ {Action-if-matches} ! /REGEX/ {Action-if-does-not-match} But (g)awk supports the ternary operator too: { /REGEX/ ? matching=1 : matching = 0 ; if ( matching ==1 ) { matching_action } else { notmatching_action } } UPDATE : According to the great Glenn Jackman

Is there such thing as a relative jQuery selector?

爷,独闯天下 提交于 2019-12-04 17:54:42
问题 I have a reference to a jquery object with the this variable. I am looking for a way of applying the child selector to the object. I'm using $(this).find('table > tbody > tr > td') , but what I'm aiming for is something more like $('[Value of $(this) goes here somehow] > table > tbody > tr > td') . I realise that I can do $(this).children('table').children('tbody').children('tr').children('td') , but I was wondering if there was some syntactic sugar I could use here. 回答1: You can start with a

What kind of syntactic sugar is available in Perl to reduce code for l/rvalue operators vs. if statements?

北城以北 提交于 2019-12-04 16:32:49
问题 There's a bunch out there, as Perl is a pretty sugary language, but the most used statements in any language is the combination of if statements and setting values. I think I've found many of them, but there's still a few gaps. Ultimately, the goal would be to not have to write a variable name more than once: Here's what I have so far: $r ||= $s; # $r = $s unless ($r); $r //= $s; # $r = $s unless (defined $r); $r &&= $s; # $r = $s if ($r); $r = $c ? $s : $t; # if ($c) { $r = $s } else { $r =

Rcpp sugar for rank function

大城市里の小女人 提交于 2019-12-04 10:12:27
I have been trying to get the rank of a vector in c++ using Rcpp. I have used other sugar functions like is_na(); Is there a similar sugar function for rank R function in c++. Also is there any list of available R sugar functions in Rcpp/ G. Grothendieck 1) There is an order function here and order(order(x)) is rank(x, ties = "first") . 2) A second way would be: match(x, sort(x)) ADDED Second approach. 来源: https://stackoverflow.com/questions/23606266/rcpp-sugar-for-rank-function

Is initializing with “var{args}” a new feature of C++0x, or merely syntactic sugar?

你离开我真会死。 提交于 2019-12-04 04:19:58
问题 I was reading the C++0x faq and came across the section detailing initializer lists. The examples were mostly variations of: vector<int> vi = { 1, 2, 3 }; vector<int> vj({1, 2, 3}); // etc. However, also listed was the form: vector<int> vk{2}; This form appears elsewhere in the faq, and I am curious as to whether it is semantically different from the initial two forms, or just syntactic sugar for vk({x, y, z}) . 回答1: One is uniform initialization , and the other is initializer lists . They

Java for each vs regular for — are they equivalent?

一笑奈何 提交于 2019-12-03 23:25:01
问题 Are these two constructs equivalent? char[] arr = new char[5]; for (char x : arr) { // code goes here } Compared to: char[] arr = new char[5]; for (int i = 0; i < arr.length; i++) { char x = arr[i]; // code goes here } That is, if I put exactly the same code in the body of both loops (and they compile), will they behave exactly the same??? Full disclaimer: this was inspired by another question (Java: are these 2 codes the same). My answer there turned out not to be the answer, but I feel that

Destructuring assignment - object properties to variables in C#

坚强是说给别人听的谎言 提交于 2019-12-03 22:30:59
JavaScript has a nifty feature where you can assign several variables from properties in an object using one concise line. It's called destructuring assignment syntax which was added in ES6. // New object var o = {p1:'foo', p2:'bar', p3: 'baz'}; // Destructure var {p1, p2} = o; // Use the variables... console.log(p1.toUpperCase()); // FOO console.log(p2.toUpperCase()); // BAR I want to do something similar with C#. // New anonymous object var o = new {p1="foo", p2="bar", p3="baz"}; // Destructure (wrong syntax as of C#6) var {p1, p2} = o; // Use the variables... Console.WriteLine(p1.ToUpper())

method with angle brackets (<>)

可紊 提交于 2019-12-03 11:42:54
问题 Is it possible to have angle brackets in method names , e.g. : class Foo(ind1:Int,ind2:Int){...} var v = new Foo(1,2) v(1) = 3 //updates ind1 v<1> = 4 //updates ind2 The real situation is obviously more complicated than this!!I am trying to provide a convenient user interface. 回答1: This response is not meant too serious and is just a proof that this can almost be achieved using some hacks. class Vector(values: Int*) { val data = values.toArray def < (i:Int) = new { def `>_=`(x: Int) { data(i)