[Noisebridge-discuss] ML Wednesday: code up a neuron!
Josh Myer
josh at joshisanerd.com
Tue Mar 10 22:05:23 UTC 2009
On Tue, Mar 10, 2009 at 02:56:41PM -0700, Mikolaj Habryn wrote:
> I think most languages will look similar if written in accessible
> style. Real Python would say:
>
That's why I wrote the ruby in the most naive form possible. It's
like pseudocode with a slightly different syntax.
> import operator
>
> def dot_product(a, b):
> return sum(map(operator.mul, a, b))
>
I hate to yield the elegance plaque to python, but, well, it looks
like I must. That's just nice, clean functional code.
The most functional version in ruby I could pull together:
def dot_product(a, b)
a.zip(b).inject(0.0) { |s, x| s+x[0]*x[1] }
end
> Which just goes to show that most high-level languages look the same
> when written in real style too ;)
>
Sadly, ruby looks less like real languages than python does here.
Drat. It does smell kind of like a handicapped lisp, at least?
--
Josh Myer 650.248.3796
josh at joshisanerd.com
More information about the Noisebridge-discuss
mailing list