News for hackers. Stuff that matters.
Re:Can your programming language do this? by judofyr on Wednesday July 08, 2009 @05:05PM (#694696)
Works nicely in Ruby 1.9:

  #!/usr/bin/ruby -Ku
  # encoding: utf-8
  module Enumerable
    def sum
      inject { |acc, val| acc + val }
    end

    def Σ(&blk)
      map(&blk).sum
    end

    def entropy(&prob)
      - Σ { |i| prob[i] * Math.log(prob[i]) }
    end
  end
EDIT: And in 1.8 if you pass -Ku.
Re:Can your programming language do this? by jrockway on Wednesday July 08, 2009 @05:56PM (#694786)
This also works fine in Perl, Common Lisp, and Haskell... and probably every other programming language that was designed after 1970.