[Grace-core] Summer Plans

Kim Bruce kim at cs.pomona.edu
Tue Jun 19 14:19:49 PDT 2012


I was more worried about cluttering up the name space than about storage allocation space.  Your nested object implementation doesn't solve the name space problem:


	def aRectangle = object {
		method at (center: Location) width (w:Number) height (h:Number) -> ShapeType {
			def diagonal = w at h
			def semiDiagonal = diagonal / 2
			return object {		
				def topLeft = center - semiDiagonal
				def bottomRight = center + semiDiagonal
				method ...
				method ...
					...
			}
		}			
	}

as diagonal and semiDiagonal are visible throughout the object expression.

My preferred solution at the moment would be:

	class aRectangle.at (center: Location) width (w:Number) height (h:Number) -> ShapeType {
		def topLeft
	        def bottomRight
		method setUp {       // confidential  -- perhaps put at the end of the class def
   			def diagonal = w at h
			def semiDiagonal = diagonal / 2
			topLeft = center - semiDiagonal
			bottomRight = center + semiDiagonal
                }

		setUp  // execute the method
		method ...
		method ...
					...
	}

This has the advantage that there is a clear chunk of code to be executed initially, the temp defs have limited scope, and (less importantly), they won't be carried around in the environment of methods -- even if there is no attempt to be efficient.

	Kim


More information about the Grace-core mailing list