On Fri, Dec 28, 2007 at 04:20:11PM +0900, Charles Oliver Nutter wrote:
> I really don't know, and to be honest I haven't seen a particularly 
> compelling use case for either lexically scoped namespaces 
> or...what...temporally scoped?
...
> What is the use case? I'd love to see.

I would like other users to be able to import mathn without it breaking
my code.

Ideally this should work:

  class Foo
    def foo
      # [ruby-talk:69859]
      use namespace Mathn
      m = Matrix[[1,2], [3,4]]
      return m*m.inv #=> [[1,0], [0,1]]
    end
  end

  class Bar
    def bar
      return 5/2 #=> 2
    end
  end

but I guess this is dynamic scoping rather than lexical scoping.

("temporal" to me implies that the change applies outside the current
thread -- see also [ruby-talk:196082])

While potentially more powerful, dynamic scoping makes it harder to know
what side-effects importing the namespace might have.

But what if the namespace could be turned on/off at the object or method
level?  And what if that namespace change automatically be propogated to
objects or methods created within a scope where that namespace were
active?

In the above example, m would automatically get the Mathn namespace
since it was created in a scope where that namespace was active.  Then
the code would work as expected.

This could be implemented similar to the way mix-ins are implemented
today, avoiding the performance penalty for every object.

Paul