ideas-computer-jasper-jasperScopeNotes1

Difference between revision 1 and current revision

No diff available.

are semiglobals like these?: http://docs.racket-lang.org/srfi-std/srfi-39.html

---

in order to make semiglobals a little more controlled than just dynamic scope, mb require functions that read from them to specify as much in their function signature, and in order to write from them, you don't just assign to that variable, you write to a semiglobal object (should we use the word 'parameter object' so schemeheads will recognize it? probably not, it's too confusable).

so e.g.

def f1(x): semiglobal q;

  g(4) == 20
  q.z = 3
  g(4) == 12

def g(y, semiglobal q = 5):

  return y * z

note that we have lost referential transparency in g, unless we consider the invocations g(4) and g(4) to be shorthand for g(4) and g(4, q.z).

this suggests that in fact, we should require to explicitly pass the semiglobal the first time.

they are still useful, for the purpose of refactoring something that was in one function, which first set a local variable and then later used it, into something where the setting of the local var and the usage are separated by a tower of descending function calls. e.g. the new requirement is:

def f1(x):

  g(4) == 20
  z = 3
  g(4, semiglobal z) == 12

def g(y, semiglobal z = 5):

  return y * z

and the reason it's useful is when you start with:

def f(x): z = 5

  y = 4
  ... do some other stuff ...
  y * z == 20
  z = 3
  ... do some other stuff ...
  y * z == 12

and then refactor into:

def f1(x):

  f2(4) == 20
  z = 3
  f2(4, semiglobal z) == 12

def f2(y): ... do some other stuff ... return f3(y)

def f3(y): ... do some other stuff ... return f4(y)

def f4(y): ... do some other stuff ... return g(y)

def g(y, semiglobal z = 5):

  return y * z

because this allows you to add new parameters for g which are set at f and then 'passed thru' f1, f2, f3, f4 without having to make f1, f2, f3, f4 aware of them.

Note that we are requiring semiglobals to have default arguments and to be keyword arguments.

---