Skip to content

Instantly share code, notes, and snippets.

@lazywithclass
Last active April 24, 2017 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazywithclass/025e83daf530f4aa8941b7a474445137 to your computer and use it in GitHub Desktop.
Save lazywithclass/025e83daf530f4aa8941b7a474445137 to your computer and use it in GitHub Desktop.
[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