Is there a more modern, OO version of “Let’s Build a Compiler”? [closed]

It sounds like you completely missed the point of Crenshaw’s tutorials. LBC isn’t about writing pretty, clean, or efficient code. It’s all about bringing something that’s steeped in formal theory down to a level where the casual coder can easily and rapidly hack out a rudimentary (but working!) compiler. When I read through LBC years … Read more

What is tail-recursion elimination?

Tail call elimination is an optimization that saves stack space. It replaces a function call with a goto. Tail recursion elimination is the same thing, but with the added constraint that the function is calling itself. Basically, if the very last thing a function A does is return A(params…) then you can eliminate the allocation … Read more

JavaScript recursive search in JSON object

When searching recursively, you have to pass the result back by returning it. You’re not returning the result of findNode(id, currentChild), though. function findNode(id, currentNode) { var i, currentChild, result; if (id == currentNode.id) { return currentNode; } else { // Use a for loop instead of forEach to avoid nested functions // Otherwise “return” … Read more

Recursion and anonymous functions in elixir

It is not possible to recur on anonymous functions in Elixir. Erlang 17 (currently a release candidate) adds this possibility to Erlang and we plan to leverage it soon. Right now, the best approach is to define a module function and pass it around: def neural_bias([i|input],[w|weights], acc) do neural(input,weights,i*w+acc) end def neural_bias([], [bias], acc) do … Read more

Recursive function causing a stack overflow

You’re being hit by filter‘s laziness. Change (filter …) to (doall (filter …)) in your recur form and the problem should go away. A more in-depth explanation: The call to filter returns a lazy seq, which materialises actual elements of the filtered seq as required. As written, your code stacks filter upon filter upon filter…, … Read more