In statically typed scenarios (closure world etc) - we can do automatic refactoring like java - where the language knows the name resolution, outer classes are closed (not dynamic etc). Let's notice not all refactorings can be done automatically

Closure world...

// closure world
// in a script or a dynamic class (open)

def x= 1
title = foo
for (...) {
    def x = 1
    title = foo
}
collect.each {
    title = "foo"
}

Builder world

normal static resolution

possible precedence rules from within usage of a builder

Johns proposal...

James proposal...

normal static resolution

changed dynamic resolution...

Markup ideas

Stuff Guillaume is happy-enough with

// Guillaumes suggestion
// though this conflicts with using quoted names on any method call
swing."frame" {
    "panel" {
    }
}

swing.frame {
    swing.panel {
        swing.button() 
    }
}

Other ideas

builder(foo) {
    frame() {
    }
}

// other alternatives
// magic method name
builder.$build() {
    frame() {
    }
}

builder {{
    frame() {
    }
}}

builder <{
    frame() {
    }
}>

/** wacky **/

/** end wacky **/

swing = new SwingBuilder()
namespace(swing) {
    frame() {
        button()
    }
}

wacky (swing) {
}

@Markup(swing) {
}

dynamic(swing) {
    ...
}

Passing closures into markup

def makeMarkup(builder) { 
    namesapce(builder) {
        frame {
            cheese.each { println it }
            bar() {
                whatnot()
            }
            this.toString()
         }
    }
}

def c = namesapce(builder) {
        frame {
            cheese.each { println it }
            bar() {
                whatnot()
            }
            this.toString()
         }
    }
}

def c = { builder ->
        namesapce(builder) {
            frame {
                cheese.each { println it }
                bar() {
                 whatnot()
              }
             this.toString()
            }
        }
        
c(swing)


def c = { b ->
            b.frame {
                cheese.each { println it }
                b.bar() {
                 b.whatnot()
              }
             this.toString()
        }
        
c(swing)

}

//... time passes

swing = new SwingBuilder()
def c = makeMarkup(swing)

Guillaumes suggestion....

def panel() {}

swing.frame {
    "panel" {...}
}

(* regular method call

    swing."foo"...

Random bits of snippets

In scripts, what should be in the binding? or local variables?

binding.x
def a
a 

Jochen:

class Foo {
    def method() { println bar } // this will have to throw an error!
}

class Foo2 extends Foo {
    @Property bar
}
class Foo {
    def method() { println .bar } // is this a way to call unbound variables?
}

class Foo2 extends Foo {
    @Property bar
}
// todo - need better name, change naming
@NoValidationOnVanillaNames
class Foo {
    def method() { println bar } // is this a way to call unbound variables?
}

scope:

class Remote() {
  def foo() {println 2}
}

//tug
def foo() {println 1}
remote.startSesssion(1, 2) {cred ->
      foo(cred, 2, 4)
}

or

//jstrachan
with (remote) {
  startSession(1, 2) { cred ->
    foo(cred, 2, 4)
  }
}

or

remote.startSesssion(1, 2) {cred ->
      remote.foo(cred, 2, 4)
}
class Foo {

def exec() {
  for(i in 1..100) {
    foo()
  }
  c = with() {
    foo()
  }
  builder << c
}

def foo(){}
}

Choice:

Either...

or

or

both! - which is default, what is syntax for non-default
e.g.

foo() could be  this.foo() or with(x) {foo()}

jstrachan - "foo should be looked for in the metaclass of the outer class,
it should never look in the metaclass of the closure"