computer-science

Is finding the equivalence of two functions undecidable?

岁酱吖の 提交于 2019-11-26 12:25:51
问题 Is it impossible to know if two functions are equivalent? For example, a compiler writer wants to determine if two functions that the developer has written perform the same operation, what methods can he use to figure that one out? Or can what can we do to find out that two TMs are identical? Is there a way to normalize the machines? Edit: If the general case is undecidable, how much information do you need to have before you can correctly say that two functions are equivalent? 回答1: Given an

Function pointers, Closures, and Lambda

十年热恋 提交于 2019-11-26 11:50:03
问题 I am just now learning about function pointers and, as I was reading the K&R chapter on the subject, the first thing that hit me was, \"Hey, this is kinda like a closure.\" I knew this assumption is fundamentally wrong somehow and after a search online I didn\'t find really any analysis of this comparison. So why are C-style function pointers fundamentally different from closures or lambdas? As far as I can tell it has to do with the fact that the function pointer still points to a defined

Does “untyped” also mean “dynamically typed” in the academic CS world?

耗尽温柔 提交于 2019-11-26 11:47:53
问题 I\'m reading a slide deck that states \"JavaScript is untyped.\" This contradicted what I thought to be true so I started digging to try and learn more. Every answer to Is JavaScript an untyped language? says that JavaScript is not untyped and offered examples of various forms of static, dynamic, strong, and weak typing that I\'m familiar and happy with.. so that wasn\'t the way to go. So I asked Brendan Eich, the creator of JavaScript, and he said: academic types use \"untyped\" to mean \"no

What is Type-safe?

余生长醉 提交于 2019-11-26 11:28:28
What does "type-safe" mean? FlySwat Type safety means that the compiler will validate types while compiling, and throw an error if you try to assign the wrong type to a variable. Some simple examples: // Fails, Trying to put an integer in a string String one = 1; // Also fails. int foo = "bar"; This also applies to method arguments, since you are passing explicit types to them: int AddTwoNumbers(int a, int b) { return a + b; } If I tried to call that using: int Sum = AddTwoNumbers(5, "5"); The compiler would throw an error, because I am passing a string ("5"), and it is expecting an integer.

What is a Y-combinator? [closed]

梦想与她 提交于 2019-11-26 11:27:16
A Y-combinator is a computer science concept from the “functional” side of things. Most programmers don't know much at all about combinators, if they've even heard about them. What is a Y-combinator? How do combinators work? What are they good for? Are they useful in procedural languages? Nicholas Mancuso If you're ready for a long read, Mike Vanier has a great explanation . Long story short, it allows you to implement recursion in a language that doesn't necessarily support it natively. Chris Ammerman A Y-combinator is a "functional" (a function that operates on other functions) that enables

Are duplicate keys allowed in the definition of binary search trees?

爷,独闯天下 提交于 2019-11-26 10:08:06
问题 I\'m trying to find the definition of a binary search tree and I keep finding different definitions everywhere. Some say that for any given subtree the left child key is less than or equal to the root. Some say that for any given subtree the right child key is greater than or equal to the root. And my old college data structures book says \"every element has a key and no two elements have the same key.\" Is there a universal definition of a bst? Particularly in regards to what to do with

What is a Lambda?

狂风中的少年 提交于 2019-11-26 09:17:17
问题 Could someone provide a good description of what a Lambda is? We have a tag for them and they\'re on the secrets of C# question, but I have yet to find a good definition and explanation of what they are in the first place. 回答1: Closures, lambdas, and anonymous functions are not necessarily the same thing. An anonymous function is any function that doesn't have (or, at least, need) its own name. A closure is a function that can access variables that were in its lexical scope when it was

How to deal with overflow and underflow?

旧巷老猫 提交于 2019-11-26 09:14:22
问题 I am new to Matlab and trying to figure out how can I deal with overflow and underflow arithmetic when the answer is actually within the range. For example: x = 2e+160 x = x*x (which returns inf, an overflow) x = sqrt(x) (which is in the range) any help is appreciated. 回答1: I am not a Matlab user so take that in mind. The main problem behind this is first to detect overflow/underflows That is sometimes hard because they appear also in other cases when the computation does not return zero or

What are the lesser known but useful data structures?

ぐ巨炮叔叔 提交于 2019-11-26 08:38:24
问题 Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. There are some data structures around that are really useful but are unknown to most programmers. Which ones are they? Everybody knows about linked lists, binary trees, and hashes, but what about Skip lists and Bloom filters for example. I would like to know more data structures that are not so common, but are worth

Regular Expressions with repeated characters

安稳与你 提交于 2019-11-26 07:46:50
问题 I need to write a regular expression that can detect a string that contains only the characters x,y, and z, but where the characters are different from their neighbors. Here is an example xyzxzyz = Pass xyxyxyx = Pass xxyzxz = Fail (repeated x) zzzxxzz = Fail (adjacent characters are repeated) I thought that this would work ((x|y|z)?)*, but it does not seem to work. Any suggestions? EDIT Please note, I am looking for an answer that does not allow for look ahead or look behind operations. The