Mathematica 7 compares to other languages

w_a_x_man at yahoo.com w_a_x_man at yahoo.com
Thu Dec 25 16:12:31 EST 2008


On Dec 25, 5:24 am, Xah Lee <xah... at gmail.com> wrote:

> The JavaScript example:
>
> // Javascript. By William James
> function normalize( vec ) {
> var div=Math.sqrt(vec.map(function(x) x*x).reduce(function(a,b) a+b))
>   return vec.map(function(x) x/div)
>
> }
>
> is also not qualified. (it is syntax error in SpiderMonkey engine
> “JavaScript-C 1.7.0 2007-10-03”)

Since you are using the latest version of Mathematica, you should
also use the latest version of SpiderMonkey.

The function works outside of a web browser with jslibs, and it
works in Firefox 3.0.1.

<html>
<body>

<script type="application/javascript;version=1.8"/>

// Tested with Firefox 3.0.1.
// SpiderMonkey JavaScript 1.6 added map().
// 1.8 added reduce() and function shorthand:
// function(x) { return x * x }
//   can now be:
// function(x) x * x

// Javascript. By William James
function normalize( vec ) {
var div=Math.sqrt(vec.map(function(x) x*x).reduce(function(a,b) a+b))
  return vec.map(function(x) x/div)
}

window.alert( normalize( [2,3,4] ).toSource() )

</script>

</body>
</html>



More information about the Python-list mailing list