[Grace-core] Re-defining stuff from the standard libraries

Andrew P Black black at cs.pdx.edu
Mon Feb 23 17:10:14 PST 2015


This email is an attempt to clarify my views on what Grace needs to allow wrt re-defining stuff from the standard libraries.

For the sake of concreteness, let's assume that my application needs an enhancement to String objects.  I might need, for example, a method
"asHtml" turns a String into an html object.

In Smalltalk,  one does this by changing the class of all of the String objects that exist in the image.  They get a new class with the extra method. This seems to be the only way to do it in Smalltalk because Smalltalk runs in a live image that is a direct descendent of some image that was running at PARC in 1980.

In Grace, every program starts in its own, fresh, image.  So enhancing string does not require changing any existing strings — it requires changing the library code to include the extra method before any user-program code is executed.   So the whole business of enhancing libraries can be much less dynamic.

In concept, the way that I see this working is that the standard prelude will include something like

	import "standardString" as string

In my enhanced prelude, I would write something like

	import "standardString" as standardString
	import "html" as html
	
	def string is public  = object {
		inherits string
		method asHtml {  html.fromString(self) }
	}

For this to work, all of the Strings created by the code compiled for String Literals would need to call a constructor that's in standardString, 
such as string.fromNativeString().   By redefining the meaning of string in my program, I've made this constructor build my strings, the ones with the extra method — because all of the code generated by the compiler is (conceptually, al least) in the scope defined by my enhanced prelude.

No runtime object mutation is necessary.  In fact, most of this works in the language and the Minigrace implementation as currently defined, except that 

	(1) The language spec says that we can't inherit from a module object, because it's not "fresh".  So inherits string has to be inherits string.methods, and we have to define string.methods in the standardString library.
	(2) in Minigrace, the interface used to create strings from literals isn't string.fromNative, but new GraceString.  And the string library isn't cleanly packaged as a module.  Neither of these seems to be important, or hard to change.

I'm probably missing some details of what would be required to make this work, but I don't think that the conceptual outline has changed since we discussed on 2-3 July 2012 in the conference room on the ground floor of Kim's building.  (The notes from this meeting are in the SVN repo at Notes/Grace meeting 2 July 2012.rtf).

	Andrew


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailhost.cecs.pdx.edu/pipermail/grace-core/attachments/20150223/919d3d78/attachment.html>


More information about the Grace-core mailing list