syntactic-sugar

Haskell record syntax

半世苍凉 提交于 2019-12-18 10:05:04
问题 Haskell's record syntax is considered by many to be a wart on an otherwise elegant language, on account of its ugly syntax and namespace pollution. On the other hand it's often more useful than the position based alternative. Instead of a declaration like this: data Foo = Foo { fooID :: Int, fooName :: String } deriving (Show) It seems to me that something along these lines would be more attractive: data Foo = Foo id :: Int name :: String deriving (Show) I'm sure there must be a good reason I

Elegant ways to return multiple values from a function

≡放荡痞女 提交于 2019-12-18 01:34:12
问题 It seems like in most mainstream programming languages, returning multiple values from a function is an extremely awkward thing. The typical solutions are to make either a struct or a plain old data class and return that, or to pass at least some of the parameters by reference or pointer instead of returning them. Using references/pointers is pretty awkward because it relies on side effects and means you have yet another parameter to pass. The class/struct solution is also IMHO pretty awkward

Objective-C: message syntax vs. dot syntax; what's the difference?

回眸只為那壹抹淺笑 提交于 2019-12-17 19:59:10
问题 If I'm using @synthesize foo; , what's the difference between the following: // message syntax [myObj setFoo:5]; [myObj foo]; and // dot syntax myObj.foo = 5; myObj.foo; I like the consistency of the dot syntax but I don't know if it's doing something I should be I concerned about. Any additional information would be a great help. 回答1: There is no functional difference between using dot syntax and using message syntax. I find that using message syntax is more consistent with the language as a

Why would you use “AS” when aliasing a SQL table?

僤鯓⒐⒋嵵緔 提交于 2019-12-17 16:33:00
问题 I just came across a SQL statement that uses AS to alias tables, like this: SELECT all, my, stuff FROM someTableName AS a INNER JOIN someOtherTableName AS b ON a.id = b.id What I'm used to seeing is: SELECT all, my, stuff FROM someTableName a INNER JOIN someOtherTableName b ON a.id = b.id I'm assuming there's no difference and it's just syntactic sugar, but which of these is more prevalent/wide-spread? Is there any reason to prefer one over the other? Edited to clarify: I appreciate all the

Using a block's return value in JavaScript

空扰寡人 提交于 2019-12-17 09:49:15
问题 On a lot of browsers I've tested, JavaScript blocks actually return a value. You can test it out in any console: for(var i = 0; i < 10; i++) { var sqrt = Math.sqrt(i); if(Math.floor(sqrt) === sqrt) { i; } } The "return" value is the last square number, that is, 9! But since it isn't an expression I suppose, you can't do this: for(var i = 0; i < 10; i++) { ... } + 5 That doesn't work. It gives + 5 , or 5 , of course, because it's a separate statement. Putting the loop in parentheses obviously

Using a block's return value in JavaScript

我是研究僧i 提交于 2019-12-17 09:49:14
问题 On a lot of browsers I've tested, JavaScript blocks actually return a value. You can test it out in any console: for(var i = 0; i < 10; i++) { var sqrt = Math.sqrt(i); if(Math.floor(sqrt) === sqrt) { i; } } The "return" value is the last square number, that is, 9! But since it isn't an expression I suppose, you can't do this: for(var i = 0; i < 10; i++) { ... } + 5 That doesn't work. It gives + 5 , or 5 , of course, because it's a separate statement. Putting the loop in parentheses obviously

Is there a way to implement custom language features in C#?

你。 提交于 2019-12-17 03:55:46
问题 I've been puzzling about this for a while and I've looked around a bit, unable to find any discussion about the subject. Lets assume I wanted to implement a trivial example, like a new looping construct: do..until Written very similarly to do..while do { //Things happen here } until (i == 15) This could be transformed into valid csharp by doing so: do { //Things happen here } while (!(i == 15)) This is obviously a simple example, but is there any way to add something of this nature? Ideally

Is there a way to implement custom language features in C#?

时光怂恿深爱的人放手 提交于 2019-12-17 03:55:19
问题 I've been puzzling about this for a while and I've looked around a bit, unable to find any discussion about the subject. Lets assume I wanted to implement a trivial example, like a new looping construct: do..until Written very similarly to do..while do { //Things happen here } until (i == 15) This could be transformed into valid csharp by doing so: do { //Things happen here } while (!(i == 15)) This is obviously a simple example, but is there any way to add something of this nature? Ideally

Is there a way to implement custom language features in C#?

↘锁芯ラ 提交于 2019-12-17 03:55:08
问题 I've been puzzling about this for a while and I've looked around a bit, unable to find any discussion about the subject. Lets assume I wanted to implement a trivial example, like a new looping construct: do..until Written very similarly to do..while do { //Things happen here } until (i == 15) This could be transformed into valid csharp by doing so: do { //Things happen here } while (!(i == 15)) This is obviously a simple example, but is there any way to add something of this nature? Ideally

WITH statement in Java

风流意气都作罢 提交于 2019-12-17 02:49:21
问题 In VB.NET there is the WITH command that lets you omit an object name and only access the methods and properties needed. For example: With foo .bar() .reset(true) myVar = .getName() End With Is there any such syntax within Java? Thanks! 回答1: No. The best you can do, when the expression is overly long, is to assign it to a local variable with a short name, and use {...} to create a scope: { TypeOfFoo it = foo; // foo could be any lengthy expression it.bar(); it.reset(true); myvar = it.getName(