Questions tagged [language-specifications]

126 questions
2
votes
1 answer

Surprising NullPointerException when using ?:

Here is a little oddity: Integer oddity(boolean b1, boolean b2) { return b1 ? 0 : b2 ? 1 : null; } This will fail with a NullPointerException if b1 and b2 are false. But this: Integer oddity(boolean b1) { return b1 ? 0 : null; } Does not throw…
Andy Turner
  • 137,514
  • 11
  • 162
  • 243
2
votes
1 answer

How to reliably detect exotic objects in JavaScript?

Is there any way to reliably whether a JavaScript object is an exotic object type, and if so what its type is? By "exotic", I mean (for the purposes of this question) anything which is could not be created using Object.create. This includes…
2
votes
0 answers

Rails i18n inflections for error messages

Does anyone know how to define a gender for the attributes in a model? So when error messages appear I can give them a specific gender such as: La dirección no puede estar en blanco ( Address can't be left blank) - Address has a female article in…
HFR1994
  • 536
  • 1
  • 5
  • 16
2
votes
1 answer

How to represent in Java a context-free grammar?

I have a simple grammar: R --> R and R | R or R | atom The only terminal we have is atom. This is a recursive grammar because each R can be composed by nested R. The problems I am facing are: How to deal with recursion? How to build a java class R…
user840718
  • 1,563
  • 6
  • 29
  • 54
2
votes
1 answer

Does constructor with optional-parameter overload it?

Here is an example of code: public List(int capacity = defaultCapacity) { items = new T[capacity]; } In C# 5 Language Specification Section 1.6.7 is written: Instance constructors can be overloaded. For example, the List class declares two…
bot_insane
  • 2,545
  • 18
  • 40
2
votes
1 answer

SVG path spec: moveTo and implicit lineTo

I am trying to write a little SVG path parser / normalizer and got one last issue with the spec: As far as I understood the most commands support additional implicit commands and when they do so and are in relative mode, the "current point" will be…
2
votes
2 answers

Using "this->" to differentiate variable names inside constructors

I recall I used to be able to do this and have it work as intended: class foobar { public: foobar(int x, int y) { x = x; //the variables x, y belonging to the class got correctly initialized y = y; } private: int x,…
2
votes
3 answers

Does the XML Specification say anything about order of elements?

I've heard a couple times that the XML specification indicates that XML is not ordered (e.g. if you expect order, then it's not really true XML). As far as I could find, the XML specification says nothing about the order of elements; neither that…
zastrowm
  • 8,017
  • 3
  • 43
  • 63
2
votes
2 answers

Why does C# also not allow empty conditions in while loops?

Edit: I changed most of my question, because it was too long and altough my question is a request of facts, it was considered opinion based. Having said that, please read the comments where I try to explain why closing this question was wrong IMHO.…
Jordy
  • 1,816
  • 16
  • 29
2
votes
1 answer

Semantics of bool fields in explicit layout types (ECMA-334)

I'm trying to find where in ECMA-334 (C# language specification) the following behavior is defined. The source program is as follows. static void Main(string[] args) { TestStruct a = new TestStruct(); a.byteValue = 1; TestStruct b = new…
Sam Harwell
  • 97,721
  • 20
  • 209
  • 280
1
vote
0 answers

Error struct assignment in if clause (language spec question)

I get an error which I can't explain. Can you help me? package main import "fmt" type mystruct struct { a string } func main() { // ok m := mystruct{"a"} if m.a == "x" { fmt.Println("is x") } // not ok, error…
topskip
  • 16,207
  • 15
  • 67
  • 99
1
vote
0 answers

Type Inference in Method Invocation Poly Expression within the Invocation Context with/without method chaining

I was going through this question - this triggered the following set of thoughts regarding the Type Inference: class Song { public Integer duration; public String artist; public String title; // ... getters... } List playlist1 = new…
1
vote
0 answers

How do deal with the "type context" rule (Java SE 16 spec §3.2) for `>` characters properly when performing lexical analysis?

I'm recently interested in writing a parser for Java language. My reference is newly released Java SE 16 spec. On 3.2. Lexical Translations, I come across this sentence but I'm not sure whether I get it: ... There is one exception: if lexical…
Javran
  • 3,394
  • 2
  • 23
  • 40
1
vote
1 answer

Coffee Can Problem in TLA+ : cannot express a task

I am trying to model the David Gries’ Coffee Can Problem in TLA+, and I am stuck at this part : "What can you say about the color of the final remaining bean as a function of the numbers of black and white beans originally in the can?" I don't know…
devio
  • 1,147
  • 5
  • 15
  • 41
1
vote
2 answers

Type Error in Alloy using Double In Statement

I am trying to write a predicate that will make all Bananas and Fresh Apples expensive. I am able to achieve one of the conditions but never both. I'm very new to using Alloy, any help would be very much appreciated. Below is my code, the error is…
1 2 3
8 9