Subject: variables: scoping

From: Kjetil Torgrim Homme <[email-masked]>
Date: 14 Apr 2003 04:31:20 +0200

the discussion is getting unwieldy, so I'm trying to break it into
more managable pieces.

Lawrence Greenfield may be right, keeping all variables in one global
scope may cause problems later.  but I don't want to make things very
complicated, either, ie. mandatory declaration of variables before use
seems unnecessary.

therefore, I suggest a modifier :local to SET as a middle ground.  it
will cause the named variable to have block local scope.  if used
outside any blocks, it will have file local scope.  a SET _without_
:local will either change the value of an existing variable if there
is one in scope, or initialise a global variable.

  require [ "variables", "include" ];
  set "foo" "anna"; # a global variable
  set "foo" :local "beatrice"; # this shadows the global variable
  if ... {
      set "foo" "charlize";
      set "foo" :local "deborah"; # shadows the variable with file scope
      # here, ${foo} is "deborah"
  }
  # here, ${foo} is "charlize"
  include "/personal/spamtests";
  # inside spamtests, ${foo} is the global variable with value "anna".
  # spamtests can set new global variables which are visible after
  # the script returns.

this does mean that SET may be used to "declare" variables as well as
"set" their values, but I don't think it is a problem to combine the
two functions into one action.

-- 
Kjetil T.

---

From: [email-masked]
Date: Sun, 13 Apr 2003 19:54:34 -0700 (PDT)

> two functions into one action.

I strongly object to this proposal. It adds considerable implementation
complexity yet achieves negligable benefits.

Variables give scripts capabilities they didn't have before and which cannot be
achieved with any existing mechanisms. The same cannot be said for local
variables. I fail to see the capability they provide for real world scripts
that cannot be achieved any other way.

				Ned

---

From: Kjetil Torgrim Homme <[email-masked]>
Date: 15 Apr 2003 14:22:15 +0200

[Ned Freed]:
>
>   I strongly object to this proposal. It adds considerable
>   implementation complexity yet achieves negligable benefits.

okay.  my proposal demonstrates that the ability can be added later if
need be, anyway.  (variables must have global scope (across includes)
now to enable that extension later.)

-- 
Kjetil T.

---

From: [email-masked]
Date: Tue, 15 Apr 2003 09:49:05 -0700 (PDT)

> now to enable that extension later.)

Good point, and sufficient IMO to table this whole thing for now.

				Ned