Skip to content

tail call length still hits call stack #99

Description

@adamdawkins

Hi,

I was reading http://raganwald.com/2015/02/07/tail-calls-defult-arguments-recycling.html, and it's fascinating stuff, thank you.

However, I was doing some testing myself, and I found that the tail call version of length() still hits Maximum call stack size exceeded at ~ 8,400 item long arrays on my Macbook Pro

Is this because of the inefficiency of [first, ...rest]. My understanding of the article was that the recursion was now ok because JavaScript optimizes away the function call overhead and stack space.

I'm just finding both the tail call length and the inefficient one fall over at the same point:

const length = ([first, ...rest], numberToBeAdded = 0) =>
  first === undefined
    ? numberToBeAdded
    : length(rest, 1 + numberToBeAdded)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions