Skip to content

Our scoping is a little broken #22

@skx

Description

@skx

This was spun off from the comment in #21.

There is a problem with scoping which can be revealed by this snippet:

(set! fib (fn* (n)
               (if (<= n 1)
                   n
                 (+ (fib (- n 1)) (fib (- n 2))))))

(let* (n 0)
  (while (<= n 10)
    (do
        (print (fib n))
        (set! n (+ n 1) true))))

Specifically the "set! n" should update the value of the "n" variable inside the let-scope, but doesn't unless the "true" parameter is added.

There are three scopes here:

  • The global scope, shared by everything before we execute code.
  • A new scope introduced by the (let*binding.
  • A third scope entered when a function body is executed.

There's something not quite right about the effects when the function/let scope overlap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions