Extending arithmetic
Håkan Stenholm
hakan.stenholm@REDACTED
Sat Feb 8 05:45:43 CET 2003
On fredag, feb 7, 2003, at 17:59 Europe/Stockholm, James Hague wrote:
> In graphics work vector math comes up a lot, and it occurred to me
> that much
> of this can be done in Erlang without changing the syntax at all.
> Rather
> than simply allowing "number + number -> number," allow the following:
>
> tuple + number -> tuple
> ex: {1,2,3} + 4 -> {4,6,7}
>
> tuple + tuple -> tuple
> ex: {1,2,3} + {4,5,6} -> {5,7,9}
>
> -tuple -> tuple
> -{1,2,3} - {-1,-2,-3}
>
....
> I don't expect this to be taken seriously, but I think it's an
> interesting
> idea.
Why not also add support for matrixes (when we are already overloading
+, -, / and *), so that we can do things like this:
X = ... % current x coordinate
Y = ... % current x coordinate
Dy = ... % move along y axis
Dx = ... % move along x axis
% Translated_along_X_and_Y
{X2, Y2, 1} =
{{1,0,Dx},
{0,1,Dy},
{0,0,1}} * {X,Y,1}
I would assume that applications like Wings could benefit from this.
More information about the erlang-questions
mailing list