dynamic-typing

Does new 'dynamic' variable type in .NET 4.0 solve the single/multiple method dispatch issue in CLR?

久未见 提交于 2019-12-03 03:21:02
The problem of single dispatch is mostly familiar to people engaged in coding with statically typed languages like Java and C#. The basic idea is: While the runtime polymorphism allows us to dispatch to the right method call according to the type (runtime type) of receiver , for example: IAnimal mything = new Cat(); mything.chop(); The method call will be performed according to the runtime type of mything , namely Cat . This is the single dispatch capability (which is present in Java/C#). Now, if you need to dispatch not only on the runtime type of receiver, but on the types of (multiple)

Using Variables for Class Names in Python?

天涯浪子 提交于 2019-12-03 02:42:04
问题 I want to know how to use variables for objects and function names in Python. In PHP, you can do this: $className = "MyClass"; $newObject = new $className(); How do you do this sort of thing in Python? Or, am I totally not appreciating some fundamental difference with Python, and if so, what is it? 回答1: In Python, className = MyClass newObject = className() The first line makes the variable className refer to the same thing as MyClass . Then the next line calls the MyClass constructor through

Using Variables for Class Names in Python?

∥☆過路亽.° 提交于 2019-12-02 16:13:10
I want to know how to use variables for objects and function names in Python. In PHP, you can do this: $className = "MyClass"; $newObject = new $className(); How do you do this sort of thing in Python? Or, am I totally not appreciating some fundamental difference with Python, and if so, what is it? In Python, className = MyClass newObject = className() The first line makes the variable className refer to the same thing as MyClass . Then the next line calls the MyClass constructor through the className variable. As a concrete example: >>> className = list >>> newObject = className() >>>

sorted-map throws exception on failed key look-up

我们两清 提交于 2019-12-01 21:21:48
user=> (def m (sorted-map 1 2)) #'user/m user=> (map? m) true user=> (get m :type) ClassCastException java.lang.Long cannot be cast to clojure.lang.Keyword clojure.lang.Keyword.compareTo (Keyword.java:114) It appears that sorted-map has chosen a numerical comparison function, which won't compare with a keyword. It would be nice to reason, "This thing supports IPersistentMap. So, I can call get on it to find out if it's a kind of map that I know about without risk of throwing an exception." The docstring for get says "Returns the value mapped to key, not-found or nil if key not present." Is

How can I create a sequence of numbered variables at run time?

血红的双手。 提交于 2019-11-30 10:10:10
问题 Friends, I must create a series of ArrayList s, each containing objects of unknown origin , with each instance assigned to a separate local variable. So far, so good... But I also need each local variable's name to follow a very specific pattern: the name should begin with "oArr", followed by one or more digits reflecting that particular array's position within the sequence. Furthermore, I will not know at compile-time how many of these arrays - and hence, how many local variables - I will be

How to identify numpy types in python?

送分小仙女□ 提交于 2019-11-29 22:00:14
How can one reliably determine if an object has a numpy type? I realize that this question goes against the philosophy of duck typing, but idea is to make sure a function (which uses scipy and numpy) never returns a numpy type unless it is called with a numpy type. This comes up in the solution to another question, but I think the general problem of determining if an object has a numpy type is far enough away from that original question that they should be separated. Use the builtin type function to get the type, then you can use the __module__ property to find out where it was defined: >>>

How can I create a sequence of numbered variables at run time?

牧云@^-^@ 提交于 2019-11-29 18:28:14
Friends, I must create a series of ArrayList s, each containing objects of unknown origin , with each instance assigned to a separate local variable. So far, so good... But I also need each local variable's name to follow a very specific pattern: the name should begin with "oArr", followed by one or more digits reflecting that particular array's position within the sequence. Furthermore, I will not know at compile-time how many of these arrays - and hence, how many local variables - I will be needing! It strikes me that this is perhaps a problem that could be solved by the availability of

How to deal with Python ~ static typing? [closed]

家住魔仙堡 提交于 2019-11-29 06:15:05
I am from Java world and I wonder what is so great about dynamic typing in Python besides missing errors while compiling the code? Do you like Python's typing? Do you have an example where it helped in a big project? Isn't it a bit error prone? Static type checking is undecidable in the general case. This means that there are programs which are statically type-safe but for which the type-checker cannot prove that they are statically type-safe, and thus the type-checker must reject those programs. In other words: there are type-safe programs that the type-checker will not allow you to write. Or

Which languages are dynamically typed and compiled (and which are statically typed and interpreted)?

青春壹個敷衍的年華 提交于 2019-11-28 22:26:06
In my reading on dynamic and static typing, I keep coming up against the assumption that statically typed languages are compiled, while dynamically typed languages are interpreted. I know that in general this is true, but I'm interested in the exceptions. I'd really like someone to not only give some examples of these exceptions, but try to explain why it was decided that these languages should work in this way. Here's a list of a few interesting systems. It is not exhaustive! Dynamically typed and compiled The Gambit Scheme compiler, Chez Scheme , Will Clinger's Larceny Scheme compiler, the

How to identify numpy types in python?

柔情痞子 提交于 2019-11-28 17:17:31
问题 How can one reliably determine if an object has a numpy type? I realize that this question goes against the philosophy of duck typing, but idea is to make sure a function (which uses scipy and numpy) never returns a numpy type unless it is called with a numpy type. This comes up in the solution to another question, but I think the general problem of determining if an object has a numpy type is far enough away from that original question that they should be separated. 回答1: Use the builtin type