Skip to content

Recursive calls in SICP exercise 1.41 cause stack overflow #10

@8dcc

Description

@8dcc

When defining the following two functions:

(defun double (f)
  (lambda (arg)
    (f (f arg))))

(defun inc (n)
  (+ n 1))

And calling double with itself as an argument:

(((double (double double)) inc) 5)

It should evaluate to:

(((double (double (double (double inc))))) 5)

Effectively, ((2*2*2*2*1)+5) = 16+5 = 21.

However, it causes a Stack Overflow when SL is compiled with -DSL_DEBUG_MAX_CALLSTACK=10000. This happens in the latest commit, 7c4f3ba, but it's known to have happened since c6415e2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions