Re: Using a string as a variable name

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Lasse Reichstein Nielsen (lrn_at_hotpop.com)
Date: 06/22/04

  • Next message: Lee: "Re: Using a string as a variable name"
    Date: Tue, 22 Jun 2004 18:00:47 +0200
    
    

    "=?Utf-8?B?YWtsag==?=" <aklj@discussions.microsoft.com> writes:

    > I've only just started to seriously use scripting with CSS and what
    > I'm trying to do is pretty complex and hard to explain clearly.

    Experience tells me that being "hard to explain clearly" usually means
    that you don't have a clear understanding of it yourself. That is very
    likely if you are a recent stater with DHTML, since it isn't as easy
    as it might look :)

    > var nTabNine = 9;
    > var strVar = "nTab"+"Nine";
    > var nNewVar = &strVar; // nNewVar = 9 if & used like FoxPro
    >
    > Trust me, this is useful.

    I'll still maintain that it is not the best way to achieve that
    effect, and something I would recommend against getting as a habit.

    Perhaps it is because I was raised on compiled languages, and this
    construction only works in an interpreted language ... or maybe that's
    the reason that I just don't like mixing compile time and run
    time. The value of strVar is a run time value, whereas variable
    resolution should (IMO) be compile time ... I just think it's asking
    for trouble to mix the two.

    But I'm sometimes too much of a language theoretician :)

    > I was sure modern core languages would allow you to do this through
    > a simple operator/command (like &) but haven't found a way yet or
    > even know if it can be done although I take your point about
    > window[] when using JScript and DOM.

    Only interpreted languages would be able to do this, since compiled
    languages don't remember the variable names for run time.

    ECMAScript has one operation that can turn a variable name into its
    value: eval. However, that is far too big a cannon to use for this,
    and it is prone to misfiring if not handled carefully. Using the
    global object (aka "window") only works for global variables, not
    local.

    /L

    -- 
    Lasse Reichstein Nielsen  -  lrn@hotpop.com
     DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
      'Faith without judgement merely degrades the spirit divine.'
    

  • Next message: Lee: "Re: Using a string as a variable name"

    Relevant Pages

    • Re: OOP and memory management
      ... if the ability to catch some errors at compile time ... > languages; they are very annoying and they don't exist in strongly typed ... > trade off or you can be blinded by typical language adherence fanatacism. ... between catching all type errors at compile time, ...
      (comp.programming)
    • Re: Multi Dimensional Array Reallocation ?
      ... I've never said that everything can be done at compile time. ... >> g) would make Delphi programs run slower, ... would require a symbol table lookup and then a type check. ... specific interest in formal languages and compiler construction. ...
      (alt.comp.lang.borland-delphi)
    • Re: evaluating a string as an expression
      ... to evaluate a string as an expression and I ... The problem here is the difference between compile time and runtime. ... interpreter (which most scripting languages such as ColdFusion, PHP, Perl ... give you access to fields on objects and not local variables. ...
      (microsoft.public.vsnet.general)
    • Re: How can my software know when a LX200 has finished slewing?
      ... But strongly typed languages are much better when lives are at stake or for mission critical systems. ... Far better to have programmers typos and common errors detected at compile time than turn it into code that is guaranteed to crash in obscure ways later. ... Ultra high reliability software now has to use a cunning subset of the Ada language. ...
      (sci.astro.amateur)
    • Re: Advice on programming language, Not Trolling.
      ... languages, even less to engage in a flame war. ... He should choose a language that is fun and easy to learn. ... He can always play ... around a little with an interpreted language and when he thinks he's ...
      (rec.games.roguelike.development)