language-design

Why do Perl control statements require braces?

人走茶凉 提交于 2019-12-03 04:33:49
This may look like the recent question that asked why Perl doesn't allow one-liners to be "unblocked," but I found the answers to that question unsatisfactory because they either referred to the syntax documentation that says that braces are required , which I think is just begging the question, or ignored the question and simply gave braceless alternatives. Why does Perl require braces for control statements like if and for ? Put another way, why does Perl require blocks rather than statements, like some other popular languages allow? One reason could be that some styles dictate that you

Generating LLVM code for 'lambda', 'define'

限于喜欢 提交于 2019-12-03 03:47:13
问题 So I now have a fairly complete LISP (scheme) interpreter written in haskell. Just for fun I want to try to have it compile down to LLVM. Most of the code generation seems pretty straight forward, but I'm at a loss as to how to generate code for a lambda expression (kind of important in lisp ;) ) and how to manage the heap when I encounter a define expression. How might I generated code for these expressions? Note: I can generate code for the body of the lambda expression, What is confusing

What is the difference between static and dynamic binding?

人盡茶涼 提交于 2019-12-03 03:43:02
问题 Binding times can be classified between two types: static and dynamic. What is the difference between static and dynamic binding? Could you give a quick example of each to further illustrate it? 回答1: In the most general terms, static binding means that references are resolved at compile time . Animal a = new Animal(); a.Roar(); // The compiler can resolve this method call statically. Dynamic binding means that references are resolved at run time . public void MakeSomeNoise(object a) { //

Immutable Collections Actionscript 3

做~自己de王妃 提交于 2019-12-03 02:50:51
I've been trying lately to implement some clean coding practices in AS3. One of these has been to not give away references to Arrays from a containing object. The point being that I control addition and removal from one Class and all other users of the Array receive read only version. At the moment that read only version is a ArrayIterator class I wrote, which implements a typical Iterator interface (hasNext, getNext). It also extends Proxy so it can be used in for each loops just as a Array can. So my question is should this not be a fundamental feature of many languages? The ability to pass

Why are most string manipulations in Java based on regexp?

白昼怎懂夜的黑 提交于 2019-12-03 02:12:42
问题 In Java there are a bunch of methods that all have to do with manipulating Strings. The simplest example is the String.split("something") method. Now the actual definition of many of those methods is that they all take a regular expression as their input parameter(s). Which makes then all very powerful building blocks. Now there are two effects you'll see in many of those methods: They recompile the expression each time the method is invoked. As such they impose a performance impact. I've

How to track newer C++ std documents of given topic?

若如初见. 提交于 2019-12-03 02:00:02
问题 Following is a C++ std document. The document number is N3721, which superseded the older N3634. Obviously, it's easy to track older documents of given topic. However, my question is: How to track newer documents of given topic? For example, if N3721 is superseded by a newer document, how to track the newer one? 回答1: For the newer proposals (ones that start with the letter P ) you can use wg21.link redirect service to obtain the latest document: wg21.link - WG21 redirect service. Usage: wg21

What are Haskell's strictness points?

会有一股神秘感。 提交于 2019-12-03 01:47:20
问题 We all know (or should know) that Haskell is lazy by default. Nothing is evaluated until it must be evaluated. So when must something be evaluated? There are points where Haskell must be strict. I call these "strictness points", although this particular term isn't as widespread as I had thought. According to me: Reduction (or evaluation) in Haskell only occurs at strictness points. So the question is: what, precisely , are Haskell's strictness points? My intuition says that main , seq / bang

Why was the statement (j++); forbidden?

人盡茶涼 提交于 2019-12-03 01:32:44
问题 The following code is wrong (see it on ideone): public class Test { public static void Main() { int j = 5; (j++); // if we remove the "(" and ")" then this compiles fine. } } error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement Why does the code compile when we remove the parentheses? Why does it not compile with the parentheses? Why was C# designed that way? 回答1: Deep insights appreciated. I shall do my best. As other answers

Do default constructors for private inner classes have a formal parameter?

☆樱花仙子☆ 提交于 2019-12-03 01:26:38
Caveat #1: This is actually a potential two-parter: First, does the constructor for a private inner class have a formal parameter? If yes, why does the JLS say it doesn't? And if no, how/why not? Caveat #2: This question is not for speculation. I'm looking for authoritative answers only. Default constructors are defined in JLS 8.8.9 , which states (in part): The default constructor has no formal parameters, except in a non-private inner member class, where the default constructor implicitly declares one formal parameter representing the immediately enclosing instance of the class (§8.8.1, §15

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

天涯浪子 提交于 2019-12-03 01:04:30
This question already has an answer here: Why is declaration of the variable required inside a for-each loop in java 4 answers 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 this language design choice. I can see why the type name must be present if the local variable is modified by final or by an