Nicodemus (nicodemusrat) wrote,
Nicodemus
nicodemusrat

  • Mood:

Programmer Language Discussions

When language wonks* compare their various languages, unlike other guys, it's all about being small. I found this exchange in a wiki discussion of higher-order functions:


To compute the inner product of two vectors:

a = [ ... ] # your vector here
b = [ ... ] # your other vector here
d = map( (lambda p, q: p * q), a, b ) # work out the products
e = reduce( (lambda x, y: x + y), d, 0 ) # sum them up

I love Python.




sum = a.zip(b).inject(0) { |s, (x,y)| s + x * y }

Yeah, and that's why I prefer Ruby.




innerProd = (sum .) . zipWith (*)

Or Haskell ;)




+/(a*b)

Or J. >:)




Now, I fully expect someone to come up with a three character solution for Matlab or something. But, if you compute lots of inner products (and hey, who doesn't!) you now know that J is a great language for you! ;)


*Language wonk is not a derisive term. No, really.
Subscribe

  • Zootopia

    I got a chance to see Zootopia with my family this past weekend. [No spoilers below, don’t worry.] This is a movie that I’ve been looking forward to…

  • FC 2016

    Kit and I flew down to FC. The flight was an inauspicious start to the trip... SF was stacked up due to weather. We actually took off at 11:15…

  • NaNoWriMo 2015 - Won!

    I started my next novel manuscript during this past month. I used the momentum of NaNoWriMo to get things jumpstarted. I did not expect to reach…

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 14 comments

  • Zootopia

    I got a chance to see Zootopia with my family this past weekend. [No spoilers below, don’t worry.] This is a movie that I’ve been looking forward to…

  • FC 2016

    Kit and I flew down to FC. The flight was an inauspicious start to the trip... SF was stacked up due to weather. We actually took off at 11:15…

  • NaNoWriMo 2015 - Won!

    I started my next novel manuscript during this past month. I used the momentum of NaNoWriMo to get things jumpstarted. I did not expect to reach…