Polyglot CheatSheet - Lambda

Updated: 2018-05-28

Ruby

proc

>> multiply = -> x, y { x * y }
=> #<Proc (lambda)>
>> multiply.call(6, 9)
=> 54
>> multiply.call(2, 3)
=> 6
>> multiply[3, 4]
=> 12

Python

  • no multiple statements in a lambda
  • lambda cannot contain assignment
>>> sorted([3, -2, -4, 5, 1], key=lambda x: abs(x))
[1, -2, 3, -4, 5]