language-design

Bitwise operator predence

梦想的初衷 提交于 2019-12-07 12:35:38
问题 A gotcha I've run into a few times in C-like languages is this: original | included & ~excluded // BAD Due to precedence, this parses as: original | (included & ~excluded) // '~excluded' has no effect Does anyone know what was behind the original design decision of three separate precedence levels for bitwise operators? More importantly, do you agree with the decision, and why? 回答1: The operators have had this precedence since at least C. I agree with the order because it is the same relative

Are the languages with a sound type system a sub set of strongly typed languages? [closed]

喜欢而已 提交于 2019-12-07 10:27:41
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago . Are the languages with a sound type system a sub set of strongly typed languages? 回答1: What is a sound type system? Do you consider static typing more "sound" than dynamic typing? Does weak typing imply the type

Would it make sense to have a 'constify' operation in C++?

拟墨画扇 提交于 2019-12-07 02:39:56
问题 Would it make sense to have a " constify " operation in C/C++ that makes a variable const ? Here is an example where it could be useful, where obviously we don't want to declare it const yet in the first line: std::vector<int> v; v.push_back(5); constify v; // now it's const Currently, without such a possibility, you'd have to introduce another variable to get the same effect: std::vector<int> v0; v0.push_back(5); const std::vector<int>& v = v0; That's more confusing since it adds a new name

C-like language without NULL?

一笑奈何 提交于 2019-12-07 02:26:43
问题 Hi I was recently watching an old video about how null pointers were a billion dollar mistake. He points out both C# and java as they have run-time checks but don't completely eliminate it enough and this is somewhat understandable. He also points out the C at one point which he feels so sure of is a great problem. I get that null terminated strings, arrays with no length and a few other things are bad (billions of dollars on buffer overflow exploits) but to completely remove null? Some

Scala variadic functions and Seq

℡╲_俬逩灬. 提交于 2019-12-06 18:33:26
问题 As far as I know, traits like List or Seq are implemented in the Scala standard library instead of being part of the language itself. There is one thing that I do not understand, though: one has a syntax for variadic functions that looks like def foo(args: String*) = ... Internally one has access to args and it will be a Seq . It is not clear to me whether: Seq is considered a special data structure enough to appear as part of the language, or the * notation here is a particular case of a

Why does math.ceil return a float? [duplicate]

不打扰是莪最后的温柔 提交于 2019-12-06 09:33:16
This question already has answers here : Closed 7 years ago . Possible Duplicate: Why do Python's math.ceil() and math.floor() operations return floats instead of integers? From the Python documentation of math.ceil ... math. ceil(x) Return the ceiling of x as a float, the smallest integer value greater than or equal to x . Why did they consider float to be better? After all, the ceil of a number is by definition an integer and operations requiring real numbers can easily convert from int to float , but not necessarily the other way around, like in the case of [0] * ceil(x) . There are

Good language to implement for senior project? [closed]

孤人 提交于 2019-12-06 09:29:34
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 years ago . Its my last semester of college and I have to do a big presentation in December. I plan on designing a small language that not only works, but also has some nifty features to go with it. Does anyone have any interesting syntax ideas or features that would impress my professors? Note: I do not want to just copy a language and reimplement it. Im looking to do a little research and try some new ideas out. Whilst I

String/Range comparison problem

纵然是瞬间 提交于 2019-12-06 08:27:43
This make sense for things like : irb(main):001:0> ["b", "aa", "d", "dd"].sort => ["aa", "b", "d", "dd"] But doesn't for : irb(main):002:0> ("B".."AA").each{ |x| print "#{x}," } => "B".."AA" should produce : B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,=> "B".."AA" but "B" > "AA" => true Unlike "B".."BA" ("B" > "BA" => false) : irb(main):003:0> ("B".."BA").each{ |x| print "#{x}," } B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK,AL,AM,AN,AO,AP,AQ,AR,AS,AT,AU,AV,AW,AX,AY,AZ,BA,=> "B".."BA" Any advice to make "b".."aa" work as expected in ruby ? I use

Why Ruby has so many redundancies?

ぐ巨炮叔叔 提交于 2019-12-06 08:23:31
I love Ruby, for past couple of years it is my language of choice. But even since I started learning it, I was repelled with the fact that so often there are several ways to do the same (or equivalent) thing. I'll give couple of examples: methods often have aliases, so you always have to bother to choose the most adequate, popular or commonly accepted alternative and and or , besides && and || - just look at how much confusion precedence difference among them causes for keyword, used almost exclusively by inexperienced non-native Ruby developers What was the rationale behind such design

Why does main() require braces?

孤街醉人 提交于 2019-12-06 04:19:39
I tried several variations on main() return; or main() if(); and obtained different errors, the most peculiar of which was /usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/crt1.o: In function `_start': (.text+0x18): undefined reference to `main' collect2: ld returned 1 exit status While it's uncommon for a program to require only one statement, why does main() make it a requirement to have braces? Could someone explain why the error was so peculiar when compiling just int main();? Because you are defining a function named main() and a function definition is basically a function declaration