Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
[RC Diary] Interpreter and interviews(-36)

[RC Diary] Interpreter and interviews(-36)

Interpreter

Thanks to Racket I am getting even more understanding of how the interpreter works under the covers, especially (require racket/trace) is helping a lot, I can verify my assumptions with a quick run. This is basically what I wanted to do when I tried to translate the interpreter into Clojure, but couldn't because of my limited understanding of how to implement a patter match for lambdas.

Interviews

I've got another interview today. I've been asked the following questions:

  • currying
  • closures
  • prototypal inheritance

I'm not particularly satisfied with the answer I gave for currying, even if apparently they were correct enoug, so I'm going to brush up a bit.

I would say the biggest benefit is to configure and reuse functions, for different needs. The difference with partial application would be that the latter usually applies one argument to the function and the next call will expect all remaining arguments, an example in JavaScript:

function sumAll(a, b, c, d) {
  return a + b + c + d
}

// partial application
var sum1To = sumAll.bind(null, 1);
sum1To(2, 3, 4) // 10

function sumAll(a) {
  return function(b) {
    return function(c) {
      return function(d) {
        return a + b + c + d
      }
    }
  }
}

sumAll(1)(2)(3)(4) // 10

The difference should now be clear. Partial application applies a certain amount of arguments to the function, I just think of currying and partial application as two different ways to prepare a function, based on the needs, YMMV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment