array programing language: APL, Mathematica

APL and Mathematica can both be categorized into a so-called Array programming language. It basically means, when a operand is a array/list, the operation is automatically mapped into the list. (as opposed to using a explicit “map” in lisp, perl, python.).

Here's APL implementation of normalizing a n-dimentional math vector.

normalize←{⍵÷((+/⍵⋆2)⋆0.5)}        

Code by Tom Novelli. APL code can be run here: Source ngn.github.com.

Here's Mathematica:

normalize = Function[#/Sqrt@(Plus@@(#^2))]

For detail, see: Vector Normalize Function in Mathematica, Haskell, Ruby, Python, Perl, Scheme Lisp, Javascript, Java, C

Popular posts from this blog

11 Years of Writing About Emacs

does md5 creates more randomness?

Google Code shutting down, future of ErgoEmacs