Live data from Hacker News

First-class environments. Discuss. ;)

lambda-the-ultimate.org

1–5 of 5 posts

Re: First-class environments. Discuss. ;)

#2
I always though it would be cool for a language have a special array-like object called 'scope'. To test if a variable was in scope you would say something like "if 'a' in scope:". It could also be useful in debugging. You could definitely abuse it, like global variables or Javascript's arguments.caller, but with great power comes great responsibility.

Re: First-class environments. Discuss. ;)

#3
post #2

I always though it would be cool for a language have a special array-like object called 'scope'. To test if a variable was in scope you would say something like "if 'a' in scope:". It could also be useful in debugging. You could definitely abuse it, like global variables or Javascript's arguments.caller, but with great power comes great responsibility.

Would Python 'locals' be something like that?

  def f():
    x = 1
    if 'x' in locals():
      print 'x in scope'
  
  f()
  x in scope

Re: First-class environments. Discuss. ;)

#4
post #2

I always though it would be cool for a language have a special array-like object called 'scope'. To test if a variable was in scope you would say something like "if 'a' in scope:". It could also be useful in debugging. You could definitely abuse it, like global variables or Javascript's arguments.caller, but with great power comes great responsibility.

What's the use case? Isn't this something the compiler can determine statically?

Re: First-class environments. Discuss. ;)

#5
post #4
post #2

I always though it would be cool for a language have a special array-like object called 'scope'. To test if a variable was in scope you would say something like "if 'a' in scope:". It could also be useful in debugging. You could definitely abuse it, like global variables or Javascript's arguments.caller, but with great power comes great responsibility.

What's the use case? Isn't this something the compiler can determine statically?

You could potentially manually/dynamicaly manipulate the environment to an advantage.