Lambdas and Pops - Jan Hettich

Lambdas and Pops - Jan Hettich

B044a0f039af800f4df09bf3b2465f18?s=128

Las Vegas Ruby Group

June 18, 2014
Tweet

Transcript

  1. λ's and POP's Jan Hettich LVRUG 5/21/2014

  2. Two kinds of Proc “plain old proc” lambda closure? yes

    yes class Proc Proc .lambda? false true semantics yield invocation similar to block method
  3. Creation • “Plain old procs” • Kernel.proc {|args| code} •

    Proc.new {|args| code} • Lambdas • Kernel.lambda {|args| code} • literal: ->(args) {code} • Method.to_proc
  4. call syntax • direct call – foo.call(args) – foo[args] –

    foo.(args) • block-style call – iterator args, &foo
  5. call semantics • yield semantics (blocks, pops) • similar to

    parallel assignment • return => lexically enclosing method • invocation semantics (methods, lambdas) • number of arguments must match • “diminutive return”
  6. Let's look at some code • A Digression on Method

    • Argument Passing • return statement • Using next • New behavior in Ruby 2.1.0