semantics

Javascript object initialization and evaluation order

浪子不回头ぞ 提交于 2019-11-28 07:19:37
问题 If I write var a = [1,2]; var b = { foo: a.pop(), bar: a.pop() }; What is the value of b , according to the specification? (By experiment, it's {foo: 2, bar: 1} , but I worry whether this is implementation-specific.) 回答1: See ECMAScript section 11.1.5 defining how the ObjectLiteral production is parsed. In particular: PropertyNameAndValueList , PropertyName : AssignmentExpression is evaluated as follows: Evaluate PropertyNameAndValueList. Evaluate PropertyName. Evaluate AssignmentExpression.

What happens to you if you break the monad laws?

こ雲淡風輕ζ 提交于 2019-11-28 06:13:09
Do the compiler or the more "native" parts of the libraries (IO or functions that have access to black magic and the implementation) make assumptions about these laws? Will breaking them cause the impossible to happen? Or do they just express a programming pattern -- ie, the only person you'll annoy by breaking them are people who use your code and didn't expect you to be so careless? The compiler doesn't make any assumptions about the laws, however, if your instance does not obey the laws, it will not behave like a monad -- it will do strange things and otherwise appear to your users to not

The concept of Bottom in Haskell

依然范特西╮ 提交于 2019-11-28 05:21:43
Bottom in Haskell described here is said to be any computation that have errors, is unterminated, or involves infinite loop, is of any type... is this specific to Haskell? We know in Lattice theory, there is also a notion of Bottom there.....and shouldn't Bottom be defined based on what's the order defined? Indeed there is an order of definedness , where bottom is the least defined value. Have a look at this page about denotational semantics in Haskell for a more thorough explanation. Here is a lattice for the values of Maybe Bool taken from the wiki page. It shows that Just True is more

What's the exact semantics of deleted member functions in C++11?

强颜欢笑 提交于 2019-11-28 04:38:53
struct A { A(); A(const A&); A& operator =(const A&); A(A&&) = delete; A& operator =(A&&) = delete; }; struct B { B(); B(const B&); B& operator =(const B&); }; int main() { A a; a = A(); // error C2280 B b; b = B(); // OK } My compiler is VC++ 2013 RC. error C2280: 'A &A::operator =(A &&)' : attempting to reference a deleted function I just wonder why the compiler doesn't try A& operator =(const A&); when A& operator =(A&&) is deleted? Is this behavior defined by the C++ standard? a = A(); // error C2280 The expression on the right is a temporary which means it will look for operator=(A&&) and

Javascript: difference between a statement and an expression?

本小妞迷上赌 提交于 2019-11-28 03:39:17
I asked this question earlier, and after thinking about the topic some more, I began to wonder where the seemingly fuzzy boundary between the meanings of the terms "statement" and "expression" lies. Are all statements also expressions? Where do the return values in a REPL console come from? They don't always seem to make any intuitive sense. Of course if you type 1+1 , you'll get 2 , but other times it isn't as obvious what the logic is. Given that anything typed into REPL produces some value, does it mean that it can be used in JS source code as both an expression and a standalone statement?

Finding related words (specifically physical objects) to a specific word

倖福魔咒の 提交于 2019-11-28 03:24:37
I am trying to find words (specifically physical objects) related to a single word. For example: Tennis : tennis racket, tennis ball, tennis shoe Snooker : snooker cue, snooker ball, chalk Chess : chessboard, chess piece Bookcase : book I have tried to use WordNet, specifically the meronym semantic relationship; however, this method is not consistent as the results below show: Tennis : serve, volley, foot-fault, set point, return, advantage Snooker : nothing Chess : chess move, checkerboard (whose own meronym relationships shows ‘square’ & 'diagonal') Bookcase : shelve Weighting of terms will

Checking for empty arrays: count vs empty

旧巷老猫 提交于 2019-11-28 03:22:02
This question on ' How to tell if a PHP array is empty ' had me thinking of this question Is there a reason that count should be used instead of empty when determining if an array is empty or not? My personal thought would be if the 2 are equivalent for the case of empty arrays you should use empty because it gives a boolean answer to a boolean question. From the question linked above, it seems that count($var) == 0 is the popular method. To me, while technically correct, makes no sense. E.g. Q: $var, are you empty? A: 7 . Hmmm... Is there a reason I should use count == 0 instead or just a

What is the difference between syntax and semantics in programming languages?

假装没事ソ 提交于 2019-11-28 02:36:25
What is the difference between syntax and semantics in programming languages (like C, C++)? Jeff N Syntax is about the structure or the grammar of the language. It answers the question: how do I construct a valid sentence? All languages, even English and other human (aka "natural") languages have grammars, that is, rules that define whether or not the sentence is properly constructed. Here are some C language syntax rules: separate statements with a semi-colon enclose the conditional expression of an IF statement inside parentheses group multiple statements into a single statement by enclosing

Is an HTML5 <header> tag unnecessary if there is only a single <hx> tag inside it? [closed]

佐手、 提交于 2019-11-28 02:13:14
I've searched and have not come up with any useful answers, so here goes: Is an HTML5 <header> tag unnecessary if there is only a single <hx> tag inside it? For instance, I have the following HTML5 markup: <article> <header> <h1>Heading Title</h1> </header> ... </article> From an HTML5 semantics point of view, when there is only one <hx> tag inside the <header> and nothing else, is the <header> tag unnecessary/redundant, and should I just do this instead: <article> <h1>Heading Title</h1> ... </article> simmer From the first Note section on the W3C's header spec which ajp15243 mentioned above,

DIVs vs. TABLEs a rebuttal please

醉酒当歌 提交于 2019-11-28 01:39:30
There are lots of people out there asking "why shouldn't we use tables for structuring our HTML" and while a lot of answers come in, I rarely see anyone being converted to the world of semantics. That said, I've yet to see any convincing rebuttals to support the rationale for why we should (or might) use tables. Anyone care to offer a rationale for when tables are valid structural markup? Nov 7, 2008 Considering that this question didn't go away like I thought it would, I suppose I'd better clarify my question and explain its existence. Through frustration having read the "tables are easier"