language-design

Is it possible to create C# language modifications as did LINQ?

Deadly 提交于 2019-12-05 00:43:23
I've been looking quite a bit at Mr. Skeet's blog on how to re-implement LINQ . In particular, he states that the code: var list = (from person in people where person.FirstName.StartsWith("J") orderby person.Age select person.LastName) .ToList(); is translated to methods that are extension methods that are provided by the LINQ library: people.Where(person => person.FirstName.StartsWith("J")) .OrderBy(person => person.Age) .Select(person => person.LastName) BY THE COMPILER. My question is, how does one impress the bigwigs enough with a library to cause them to allow the language to change to

First Steps with DSL on Java?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 23:37:11
问题 Guys... Girls, I'm working on a project which I think could be enhanced by implementing a Domain Specific Language for defining a set of rules and/or conditions for some type of work-flow. I want to get a firm grasp on the subject, fundamentals, best practices, etc. specially how to implement them somehow with Java. What do you suggest? 回答1: First I would recommend reading chapter 9 (Notation) of The Practice of Programming by Kernighan and Pike. When you have done that, come back here with

Python: Why does the int class not have rich comparison operators like `__lt__()`?

放肆的年华 提交于 2019-12-04 22:29:38
Mostly curious. I've noticed (at least in py 2.6 and 2.7) that a float has all the familiar rich comparison functions: __lt__() , __gt__ , __eq__ , etc. >>> (5.0).__gt__(4.5) True but an int does not >>> (5).__gt__(4) Traceback (most recent call last): File "<input>", line 1, in <module> AttributeError: 'int' object has no attribute '__gt__' Which is odd to me, because the operator itself works fine >>> 5 > 4 True Even strings support the comparison functions >>> "hat".__gt__("ace") True but all the int has is __cmp__() Seems strange to me, and so I was wondering why this came to be. Just

Is there a specific reason nested namespace declarations are not allowed in C++?

我的未来我决定 提交于 2019-12-04 16:24:17
问题 The standard does not allow code like this: namespace Hello::World { //Things that are in namespace Hello::World } and instead requires namespace Hello { namespace World { //Things that are in namespace Hello::World }} What is the rationale? Was this simply not thought of at the time, or is there a specific reason it is not included? It seems that the first syntax more directly expresses in which namespace one is supposed to be, as the declaration mimics the actual use of the namespace in

What compromises Scala made to run on JVM?

此生再无相见时 提交于 2019-12-04 15:39:14
问题 Scala is a wonderful language, but I wonder how could be improved if it had it's own runtime? I.e. what design choices were made because of JVM choice? 回答1: This article is a discussion with Martin Odersky (Scala's creator) and includes the compromises that were made in Scala for compatibility with Java. The article mentions: Static overloading of methods Having both traits and classes Inclusion of null pointers. 回答2: The two most important compromises I know about are: type erasure (

The advantages of having static function like len(), max(), and min() over inherited method calls

核能气质少年 提交于 2019-12-04 11:48:19
问题 i am a python newbie, and i am not sure why python implemented len(obj), max(obj), and min(obj) as a static like functions (i am from the java language) over obj.len(), obj.max(), and obj.min() what are the advantages and disadvantages (other than obvious inconsistency) of having len()... over the method calls? why guido chose this over the method calls? (this could have been solved in python3 if needed, but it wasn't changed in python3, so there gotta be good reasons...i hope) thanks!! 回答1:

Confused by Boxing. Casting -1 to Int64 throws InvalidCastException

[亡魂溺海] 提交于 2019-12-04 11:13:13
问题 Ok I must be overlooking something extremely simple but I am lost. Given this object val = -1; var foo = (Int32)(val); var bar = (Int64)(val); The cast to Int64 throws and InvalidCastException. I recognize this is related to some strangeness with boxing but I don't understand the reasoning. From what I understand val is boxed as Int32 on the first line. Then when I try to cast as something other than Int32 InvalidCastException is thrown. I suppose this means that I am trying to unbox val as

Dynamic name resolution

不问归期 提交于 2019-12-04 10:48:01
Howcome some languages like PHP and Python use dynamic name resolution ? The only time I've ever thought of using it is to do something like this Python code, to save me from having to explicitly parameters to format : "{a} {b} {c} {d}".format(**locals()) but it doesn't really take much work to just be explicit (and is a bit less error-prone): "{a} {b} {c} {d}".format(a=a, b=b, c=c, d=d) And for setting/getting locals in the same scope, I don't see why anyone would ever use that instead of a map. Without dynamic name resolution, typos are caught, and you can automatically rename variables

Why does the local variable of an enhanced for loop have to be local? [duplicate]

£可爱£侵袭症+ 提交于 2019-12-04 08:50:00
问题 This question already has answers here : Why is declaration of the variable required inside a for-each loop in java (4 answers) Closed 4 years ago . According to the Java Language Specification, § 14.14.2, the variable of an enhanced for loop must be local to the loop. In other words, this compiles: for (State state : State.values()) { // do something for each state } but this does not: State state; for (state: State.values()) { // do something for each state } The JLS gives no rationale for

Does any programming language support defining constraints on primitive data types?

感情迁移 提交于 2019-12-04 08:49:50
Last night I was thining that programming languages can have a feature in which we should be able to constraints the values assigned to primitive data types. For example I should be able to say my variable of type int can only have value between 0 and 100 int<0, 100> progress; This would then act as a normal integer in all scenarios except the fact that you won't be able to specify values out of the range defined in constraint. The compiler will not compile the code progress=200 . This constraint can be carried over with type information. Is this possible? Is it done in any programming