[Grace-core] Modules vs Objects

Andrew P. Black black at cs.pdx.edu
Wed Aug 15 17:56:07 PDT 2012


We've agreed that modules are really just objects,  but I see some differences that perhaps be implied by the use of the two different keywords.


We are working on the assumption that 

	object {											(1)
		def x = exp1
		var y := exp2  
		statement
		method foo { x + y}
	}

really means something like

	object { 											(2)
		def x
		var y
		initially { 
			x = exp1
			y := exp2
			statement
		}
		method foo { x + y }
	}


The syntax (2) is not too bad for objects, but has the disadvantage that the time when the initially method is executed is not precisely specified.  This matters if exp1 or exp2 refer to variables or to mutable objects.  So I think that it's better not to just
re-write (1) into (2), but to allow the programmer to choose her syntax and semantics as the situation demands.

An alternative is to make 

	module {											(3)
		def x = exp1
		var y := exp2  
		statement
		method foo { x + y}
	}

mean "execute exp1, exp2 and statement now", while

	object {											(4)
		def x = exp1
		var y := exp2  
		statement
		method foo { x + y}
	}

means "execute  exp1, exp2 and statement later", i.e., (4) is implicitly re-written in to the form with initially, but (3) is not.

A file without a top-level object or module is implicitly surrounded by

	def filename = module {  <file contents> }

This lets 

	print "hello, world"

remain a valid program, this time defining a module that prints "hello, world"

What about inheritance?

	object {											(5)
		inherits bar.new
		def x = exp1
		var y := exp2
		statement
		method foo { x + y}
	}

really means something like

 	bar.new extendedByMethodsOf object {		
		def x											(6)
		var y
		initially {
			super.initially
			x = exp1
			y := exp2
			statement
		}
		method foo { x + y }
	}

What about 

	module {											(7)
		inherits module.new
		def x = exp1
		var y := exp2
		statement
		method foo { x + y}
	}

Yes, I think that it does make sense to talk about inheriting from "module.new", and not from module, because this makes it clear that each use of a module creates a new set of fields.

inherits would still have the extendedByMethodsOf semantics.  Do you see a need for the deferred execution semantics when one module inherits from another?

	Andrew



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailhost.cecs.pdx.edu/mailman/private/grace-core/attachments/20120815/891b16e1/attachment.html>


More information about the Grace-core mailing list