syntactic-sugar

Is there such thing as a relative jQuery selector?

随声附和 提交于 2019-12-03 10:37:17
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. You can start with a child selector ( > ) when using .find() as well, like this: $(this).find('> table > tbody > tr > td') It's

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

拥有回忆 提交于 2019-12-03 10:28: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 = $t } $c ? $r : $s = $t; # if ($c) { $r = $t } else { $s = $t } $r = $s || $t; # if ($s) { $r = $s }

Defining new infix operators

早过忘川 提交于 2019-12-03 06:47:48
问题 So thanks to C++11, it's now possible to combine macros, user-defined literals, lambdas, etc. to create the closest I can get to 'syntactic sugar'. An example would be if (A contains B) Of course this is easy. cout <<("hello"_s contains "ello"_s)<<endl; The expression converts to a bool, where contains is a custom struct that takes the left-hand side and right-hand side as arguments. The struct of course overloads operator+ to take the custom string literal first, returning itself, then the

How can I use collection initializer syntax with ExpandoObject?

徘徊边缘 提交于 2019-12-03 05:17:35
I've noticed that the new ExpandoObject implements IDictionary<string,object> which has the requisite IEnumerable<KeyValuePair<string, object>> and Add(string, object) methods and so it should be possible to use the collection initialiser syntax to add properties to the expando object in the same way as you add items to a dictionary. Dictionary<string,object> dict = new Dictionary<string,object>() { { "Hello", "World" } }; dynamic obj = new ExpandoObject() { { "foo", "hello" }, { "bar", 42 }, { "baz", new object() } }; int value = obj.bar; But there doesn't seem to be a way of doing that.

Is it possible to use a bracketing syntactic sugar for an applicative functor?

自作多情 提交于 2019-12-03 04:49:56
In McBride and Paterson's 'Applicative programming with effects' they introduce some lovely syntactic sugar for lifting a pure function: [| f x y z |] for f <$> x <*> y <*> z and I recall someone somewhere else using li f w x y z il or il f v w x y z li , and I thought/hoped that might be because it could be defined using some existing language feature and cunning definition of li and il . I can't find any reference to this beyond the paper, and assuming that [| and |] aren't likely to turn up in ghc any time soon, is it possible to implement li and il somehow? I can't think of a sensible type

method with angle brackets (<>)

不打扰是莪最后的温柔 提交于 2019-12-03 03:07:56
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. 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) = x } def > { println("value at "+ i +" is "+ data(i)) } } override def toString = data.mkString("<", ", ",

What does extended slice syntax actually do for negative steps? [duplicate]

廉价感情. 提交于 2019-12-02 20:40:01
This question already has answers here : Understanding slice notation (32 answers) The extended slice syntax in python has been explained to me as " a[n:m:k] returns every kth element from n to m ". This gives me a good idea what to expect when k is positive. But I'm lost on how to interpret a[n:m:k] for negative k. I know that a[::-1] reverses a, and that a[::-k] takes ever kth element of the reversed a. But how is this a generalization of the definition for k positive? I'd like to know how a[n:m:k] is actually defined, so that (for example) I can understand why: "abcd"[-1:0:-1] = "dcb" Is a

Defining new infix operators

感情迁移 提交于 2019-12-02 20:24:36
So thanks to C++11, it's now possible to combine macros, user-defined literals, lambdas, etc. to create the closest I can get to 'syntactic sugar'. An example would be if (A contains B) Of course this is easy. cout <<("hello"_s contains "ello"_s)<<endl; The expression converts to a bool, where contains is a custom struct that takes the left-hand side and right-hand side as arguments. The struct of course overloads operator+ to take the custom string literal first, returning itself, then the operator+ for the struct itself. struct contains_struct { string lhs; string rhs; void set_lhs(string

.NET Framework supported empty action syntax or singleton

眉间皱痕 提交于 2019-12-02 01:45:36
问题 When working with existing frameworks, sometimes you need to pass in an action delegate which performs no action usually an extension point added by the original developer. Example: var anObject = new Foo(() => { }); And presumably the Foo object will call this delegate at some time. My goal here is to eliminate the use of { }, because my style dictates that { } need to be on their own, and separate lines, and I'm a bit OCD and hate being verbose if I don't have to be. When dealing with an

.NET Framework supported empty action syntax or singleton

折月煮酒 提交于 2019-12-02 01:33:21
When working with existing frameworks, sometimes you need to pass in an action delegate which performs no action usually an extension point added by the original developer. Example: var anObject = new Foo(() => { }); And presumably the Foo object will call this delegate at some time. My goal here is to eliminate the use of { }, because my style dictates that { } need to be on their own, and separate lines, and I'm a bit OCD and hate being verbose if I don't have to be. When dealing with an action which returns a value, this is simple enough- you can provide an expression instead of a statement