Arc Forumnew | comments | leaders | submitlogin
No internal definitions?
2 points by tger 6425 days ago | 2 comments
I was a bit surprised to see this:

    arc> (def foo () nil)
    #<procedure: foo>
    arc> (def bar ()
           (def foo () nil)
           nil)
    #<procedure: bar>
    arc> (bar)
    *** redefining foo
    nil
    arc>
Apparently the internal foo declaration doesn't shadow the top-level one, it replaces it. I though Arc did standard static binding a la Scheme.. Anyone care to enlighten me on this?


6 points by parenthesis 6425 days ago | link

As I understand it

  (def foo () nil)
is (roughly) equivalent to

  (= foo (fn () nil))
So, regardless of the context of the (def foo ...), if there isn't a local foo, it's the global foo that is bound to the new function.

To have a local function foo:

  (def foo () nil)

  (def bar ()
    (let foo (fn () t)
      (foo)))
And then

  (bar) -> t
  (foo) -> nil

-----

1 point by tger 6425 days ago | link

Thanks for your reply! My confusion stemmed from the fact that I thought that def behaved like define in Scheme (i.e. establishing a new binding), which apparently was not the case.

-----