1

From all the languages that I know (Java, C++), the name and the lifetime of a variable is always known at compile time. Is there any language for which the name and lifetime will be bound at run time?

Furthermore, I'm playing with C++ smart pointers at the moment. When is the life time known as well as the scope?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Bobby
  • 496
  • 5
  • 18
  • JavaScript, python perhaps? (Not sure) – SamTebbs33 Dec 05 '15 at 22:24
  • 3
    Variables don't have lifetimes; *objects* do. – Nicol Bolas Dec 05 '15 at 22:31
  • @NicolBolas Good point. – Bobby Dec 05 '15 at 22:32
  • In Java you know the lifetime of an object at compile time? – Martin York Dec 05 '15 at 22:43
  • 1
    Scope is known at compile time. Lifetime in general is not. – Alan Stokes Dec 05 '15 at 22:49
  • 1
    The question is very vague.... What is "variable"? Objects can have dynamic properties, even in C++ if you inherit from base object which supports them, and then these may be indistinguishable from properties defined at compile time, when accessing the instnce from a more dynamic language like Javascript or Python. Example: http://doc.qt.io/qt-5/qobject.html#setProperty – hyde Dec 05 '15 at 22:51
  • 1
    I fail to understand, what is the use of a variable that you don't know the name of? Could you give an example? – Ashkan Dec 05 '15 at 22:55

2 Answers2

0

With C++ smart pointers, the scope of the smart pointer is the regular scope. The scope of the managed object is determined by the smart pointers behavior.

There are a lot of languages that employ dynamic/runtime scoping. Javascript, PERL, PHP is a few. https://en.wikipedia.org/wiki/Scope_%28computer_science%29#Dynamic_scoping

Captain Giraffe
  • 14,407
  • 6
  • 39
  • 67
0

with java, NO a priori , or very difficult

see this: Is it possible to create variables at runtime in Java?

What can you do with that at runtime ?

You can reference variables, as you want (in an array, integer, in a Map ...)

Community
  • 1
  • 1