[chuck-users] Are array types really classes ?
signal.automatique at gmail.com
Fri Sep 4 11:07:40 EDT 2009
>> Not quite, because I can't add member functions that would
>> perform "horizontal" operations (e.g. norm() for vectors, or draw() for
>> probability arrays).
> Sometimes I create public classes just as namespaces to encapsulate
> functionality. You could have public class Probabilities that contains a
> bunch of static members and then create a Vector class that has-a float
> and whatever else it needs and wraps Probabilities.norm() in member function
> Would that be a compromise? Or am I missing something?
I agree, particularly as the normalisation operation would most likely be
applied to the vector (probably to yield a unity length) and it wouldn't be
the array itself that would be normalised. So; if it would apply to the
vector it could/should belong to the vector's properties/namespace I'd say.
A separate question might be whether we would need some syntactic sugar to
apply a single operation to all array entries in a given array (for example
to normalise a set of a thousand vectors or to compute the absolute value of
all floats in a given array). This might make sense but a simple "for" loop
and a single line of code will do the job as well. For multi-dimensional
arrays this quickly becomes so hard to generalise that I think for loops are
perfectly fine, especially as they are so clear.
In practice much of this would depend on the exact issue we are trying to
solve and how. We could look into some concrete examples if Cyrille has some
and see where the issues arise. I myself would certainly start here with
defining a class named "vector", that would hold a array (of the vector's
components) as well as member functions for normalising it, multiplying it
by floats and possibly others, depending on the situation.
It takes a bit of work and thought but once done you can re-use it forever.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the chuck-users