Two standard libraries?

Chris Nicholson-Sauls ibisbasenji at gmail.com
Tue Jul 17 14:15:12 PDT 2007


Julio César Carrascal Urquijo wrote:
> Kirk McDonald wrote:
>> Robert Fraser wrote:
>>> Well, not even scripting languages keep names of local variables in
>>> memory at runtime...
>>
>> Hmm?
>>
>>  >>> a = 12
>>  >>> b = 'waffles'
>>  >>> locals()
>> {'__builtins__': <module '__builtin__' (built-in)>, '__name__': 
>> '__main__', 'b': 'waffles', '__doc__': None, 'a': 12}
>>  >>> "%(a)s %(b)s" % locals()
>> '12 waffles'
>>
> 
> And if I may add:
> 
> <?php
> 
> $a = 5;
> $b = 'a';
> $$b = 'Hello, world!';
> echo $a;
> 
> ?>

And also Ruby.

# names.rb
puts Symbol.all_symbols.inspect


This will print for you an array of a few thousand symbols from the 
runtime, among them the names of many variables.  Changing the source to:
myVar = 42
puts Symbol.all_symbols.index(:myVar)

Gave me '1117'.  At least in Ruby each such symbol is retained exactly 
once, no matter how many things have that name.  (Otherwise... could you 
imagine the memory consumption...)

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list