dynamic-typing

scipy function always returns a numpy array

梦想的初衷 提交于 2019-12-06 10:36:27
问题 I'm encountering a scipy function that seems to return a numpy array no matter what's passed to it. In my application I need to be able to pass scalars and lists only, so the only "problem" is that when I pass a scalar to the function an array with one element is returned (when I would expect a scalar). Should I ignore this behaviour, or hack up the function to ensure that when a scalar is passed a scalar is returned? Example code: #! /usr/bin/env python import scipy import scipy.optimize

Why do COM libraries used from C# 4.0 require such heavy use of dynamic types?

自作多情 提交于 2019-12-06 04:41:56
问题 In the C# 4.0 demos, I'm seeing lots of code that uses the dynamic type. For example, the following code sets the value of an Excel cell: excel.Cells[1, 1].Value = ... However, you can also access the cell in an early bound manner with a cast: ((Range)excel.Cells[1, 1]).Value = ...; Why don't the Excel COM library just describe the Cell type as a Range type in the first place? Similarly, all the arguments to the following method are dynamic: excel.ActiveWorkbook.Charts.Add(...) Why couldn't

How to describe function arguments in dynamic typed languages?

五迷三道 提交于 2019-12-05 13:15:14
My question is more oriented toward Python, but it may also be about JavaScript or other scripting languages. I usually develop with statically typed languages (Java, C++, ActionScript, ...). I like to use from time to time Python, and I also need to sometimes use JavaScript. These are dynamic typed languages. Nothing wrong with that, but I usually have lots of headaches to understand which parameters are needed in a function or in a method. It happens even if it is my own code with some docstrings! Maybe because the eye has to look somewhere else than in the definition of the function. Of

Create an instance of a class from a string name in Haxe

丶灬走出姿态 提交于 2019-12-05 03:09:22
Let's say i acquire the name of a class that i made as a String . How can i Instantiate the class with the name contained in that string? I I know it will be derived from a certain parent class, but the actual class will vary. Franco Ponticelli var instance : MyClass = Type.createInstance(Type.resolveClass("path.to.MyClass"), []); Few notes: resolveClass() takes the full path (packages included) of the classe you need createInstance() takes as the second argument an array of values that are applied to the constructor. Those values must be in the exact number and must be passed even if they are

scipy function always returns a numpy array

本秂侑毒 提交于 2019-12-04 17:12:57
I'm encountering a scipy function that seems to return a numpy array no matter what's passed to it. In my application I need to be able to pass scalars and lists only, so the only "problem" is that when I pass a scalar to the function an array with one element is returned (when I would expect a scalar). Should I ignore this behaviour, or hack up the function to ensure that when a scalar is passed a scalar is returned? Example code: #! /usr/bin/env python import scipy import scipy.optimize from numpy import cos # This a some function we want to compute the inverse of def f(x): y = x + 2*cos(x)

Why do COM libraries used from C# 4.0 require such heavy use of dynamic types?

强颜欢笑 提交于 2019-12-04 12:19:13
In the C# 4.0 demos, I'm seeing lots of code that uses the dynamic type. For example, the following code sets the value of an Excel cell: excel.Cells[1, 1].Value = ... However, you can also access the cell in an early bound manner with a cast: ((Range)excel.Cells[1, 1]).Value = ...; Why don't the Excel COM library just describe the Cell type as a Range type in the first place? Similarly, all the arguments to the following method are dynamic: excel.ActiveWorkbook.Charts.Add(...) Why couldn't the arguments have been static? Looking at the Excel object model, there are dynamic types everywhere.

Is there a compiled* programming language with dynamic, maybe even weak typing?

回眸只為那壹抹淺笑 提交于 2019-12-04 09:53:27
问题 I wondered if there is a programming language which compiles to machine code/binary (not bytecode then executed by a VM, that's something completely different when considering typing) that features dynamic and/or weak typing, e.g: Think of a compiled language where: Variables don't need to be declared Variables can be created during runtime Functions can return values of different types Questions: Is there such a programming language? (Why) not? I think that a dynamically yet strong typed,

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

百般思念 提交于 2019-12-04 09:49:58
问题 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

sorted-map throws exception on failed key look-up

醉酒当歌 提交于 2019-12-04 04:19:42
问题 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."

Is there a compiled* programming language with dynamic, maybe even weak typing?

青春壹個敷衍的年華 提交于 2019-12-03 04:15:19
I wondered if there is a programming language which compiles to machine code/binary (not bytecode then executed by a VM, that's something completely different when considering typing) that features dynamic and/or weak typing, e.g: Think of a compiled language where: Variables don't need to be declared Variables can be created during runtime Functions can return values of different types Questions: Is there such a programming language? (Why) not? I think that a dynamically yet strong typed, compiled language would really sense, but is it possible? I believe Lisp fits that description. http://en