language-theory

Why in C# does order matter for static initialization?

爷,独闯天下 提交于 2020-01-02 02:51:51
问题 This code has the well defined behavior in C# of not working: class Foo { static List<int> to = new List<int>( from ); // from is still null static IEnumerable<int> from = Something(); } Note: I'm not asking how to fix that code as I already known how to do that What is the justification for this? C# already does run time checks to detect the first access to static members. Why not extend this to a per member thing and have them run on demand or even better have the compiler figure out the

Can all iterative algorithms be expressed recursively?

会有一股神秘感。 提交于 2019-12-27 11:39:31
问题 If not, is there a good counter example that shows an iterative algorithm for which there exists no recursive counterpart? If it is the case that all iterative algorithms can be expressed recursively, are there cases in which this is more difficult to do? Also, what role does the programming language play in all this? I can imagine that Scheme programmers have a different take on iteration (= tail-recursion) and stack usage than Java-only programmers. 回答1: There's a simple ad hoc proof for

What is the possible benefit (if any) of allowing recursive constructors?

拥有回忆 提交于 2019-12-24 01:24:22
问题 In Java, constructors cannot be recursive. Compile time error: "recursive constructor invocation". Let's assume that we did not have this restriction. Things to keep in mind: The return type of a constructor is void. Since it is a void method you can't harness the complete power of recursion. A constructor can invoke itself (or any other constructor) using this(). But a "call to this must be first statement in constructor" We could use non local data between consecutive calls to still have

What is the possible benefit (if any) of allowing recursive constructors?

放肆的年华 提交于 2019-12-24 01:21:40
问题 In Java, constructors cannot be recursive. Compile time error: "recursive constructor invocation". Let's assume that we did not have this restriction. Things to keep in mind: The return type of a constructor is void. Since it is a void method you can't harness the complete power of recursion. A constructor can invoke itself (or any other constructor) using this(). But a "call to this must be first statement in constructor" We could use non local data between consecutive calls to still have

What is the definition of a “true” multidimensional array and what languages support them?

浪子不回头ぞ 提交于 2019-12-23 08:54:05
问题 Most of the programming books I have ever read, have the following line: "X language does not support true multidimensional arrays, but you can simulate (approximate) them with arrays of arrays." Since most of my experience has been with C-based languages, i.e. C++, Java, JavaScript, php, etc., I'm not sure of what a "true" multidimensional array is. What is the definition of a true multidimensional array and what languages support it? Also, please show an example of a true multidimensional

What actually is the assignment symbol in python?

社会主义新天地 提交于 2019-12-23 07:04:48
问题 Most sources online call = (and +=, -=, etc...) an assignment operator (for python). This makes sense in most languages, however, not in python. An operator takes one or more operands, returns a value, and forms an expression. However, in python, assignment is not an expression, and assignment does not yield a value. Therefore, = cannot be an operator. So what exactly is it? In a statement like x = 0, x is an identifier, 0 is a numeric literal, but I don't know what to call "=". 回答1: I was

What is the advantage of having this/self pointer mandatory explicit?

不想你离开。 提交于 2019-12-17 18:23:35
问题 What is the advantage of having this/self/me pointer mandatory explicit? According to OOP theory a method is supposed to operate mainly (only?) on member variables and method's arguments. Following this, it should be easier to refer to member variables than to external (from the object's side of view) variables... Explicit this makes it more verbose thus harder to refer to member variables than to external ones. This seems counter intuitive to me. 回答1: In addition to member variables and

Learning Resources on Parsers, Interpreters, and Compilers [closed]

五迷三道 提交于 2019-12-17 03:23:12
问题 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 6 years ago . I've been wanting to play around with writing my own language for a while now (ostensibly for the learning experience) and as such need to be relatively grounded in the construction of Parsers, Interpreters, and Compilers. So: Does anyone know of any good resources on constructing Parsers, Interpreters, and

Are all infinite languages undecidable?

落花浮王杯 提交于 2019-12-11 22:40:27
问题 I am wondering are all infinite languages undecidable? They must be right, as the TM trying to decide an infinite language would just loop forever, which makes it a recgonizer, not a decider. Thanks guys. 回答1: No, there are many infinite languages that are decidable. One trivial example is the language {n € N | a^n} , i.e. the language of words that only contain the letter "a". This language can be matched by the regular expression a* . so it is a regular language and thus decidable. 回答2: As

Analyzing Text for Accents

萝らか妹 提交于 2019-12-10 11:47:45
问题 This is the first part of another question of mine that had a recommendation to make it two questions: Adding Accents to Speech Generation. Summary: The other question asks how to add an accent programatically to generated speech. Not an accent mark or inflection, but a full accent like a British or Scottish or Russian one. The first question (same as this one) asks how the original text could be analyzed to determine what accents need to be added and where. Basically, how could text be