|
Subject: Re: Idea: elementwise operators: [+], [*], ... Newsgroups: gmane.comp.lang.boo.devel Date: 2005-06-27 19:52:35 GMT (4 years, 1 week, 1 hour and 36 minutes ago) Norbert Nemec wrote: > Hi there, > > thinking further about the clash of + as addition and concatenation, I > had an even better idea: > > How about generally introducing [+], [*] and so on as elementwise > operations? This avoids the clash with the double meaning of + and *, > adds to the readability, since you see whether an operation handles > objects or collections offers a number of cool possibilities: > > A = [1,2] > B = [3,4] > => > A + B == [1,2,3,4] # as before > A [+] B == [4,6] > A [*] B == [3,8] > > If one of the arguments is not a list, it is distributed: > > A [+] 1 == [2,3] yeah apparently this was proposed for Python at one time too: http://www.python.org/peps/pep-0225.html except the favored syntax was A ~+ B instead of A [+] B. Actually A .+ B was his first choice, but probably the parser wouldn't allow it because uglies like this are allowed: "1 . ToString()" There are also some interesting proposals for Perl: http://dev.perl.org/perl6/rfc/207.html like A[|i] + B[|i] For now I'd just recommend a .NET math lib like dnAnalytics: http://www.dnanalytics.net/ See its DoubleVector and DoubleMatrix classes. A+B is element-wise for its vectors, but you can still do things like slicing. Remember to turn rawArrayIndexing on too if needed. Some related info: You can define your own custom infix operators in languages like Nemerle or LiveLogix's Logix using macros. There doesn't appear to be a standard computer math syntax for things like dot products, cross products, etc.: java expression parser example: http://www.singsurf.org/djep/html/djep/VectorJep.html#VEC scilab example: http://www.engineering.usu.edu/cee/faculty/gurro/Software_Calculators/Scilab_Docs/Scilab_scripts/Vectors_Script.sce Related also is the JScience proposal for adding scientific unit classes and conversions: http://www.jscience.org/ They wished to extend java's syntax too to make it easier to use units, but that's not going to happen. |
|
|