Mathematica 7 compares to other languages

Jon Harrop jon at ffconsultancy.com
Thu Dec 11 17:57:45 EST 2008


Xah Lee wrote:
> On Dec 10, 2:47 pm, John W Kennedy <jwke... at attglobal.net> wrote:
>> Xah Lee wrote:
>> > In lisp, python, perl, etc, you'll have 10 or so lines. In C or Java,
>> > you'll have 50 or hundreds lines.
>>
>> C:
>>
>> #include <stdlib.h>
>> #include <math.h>
>>
>> void normal(int dim, float* x, float* a) {
>> float sum = 0.0f;
>> int i;
>> float divisor;
>> for (i = 0; i < dim; ++i) sum += x[i] * x[i];
>> divisor = sqrt(sum);
>> for (i = 0; i < dim; ++i) a[i] = x[i]/divisor;
>>
>> }
> 
> i don't have experience coding C. The code above doesn't seems to
> satisfy the spec. The input should be just a vector, array, list, or
> whatever the lang supports.
> The output is the same datatype of the same dimension.

The output is in the preallocated argument "a". It is the same type (float
*) and has the same dimension. That is idiomatic C.

You could define a struct type representing a vector that includes its
length and data (akin to std::vector<..> in C++) but it would still be
nowhere near 50 LOC as you claimed.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u



More information about the Python-list mailing list