[Grace-core] Undefined Variables

Andrew P. Black black at cs.pdx.edu
Wed Feb 25 11:37:12 PST 2015


I woke up in the middle of the night on Monday realizing what a Bad Idea it was to make the error that occurs when one accesses an undefined variable “uncatchable”.

It’s bad because it means that one can’t write a debugger or a unit testing framework that reports such an error and then continues with its work (showing the debugging information, or the stack trace, or going on with the next unit test.)   At least, one can’t do these things in Grace; some of them may be possible using extra-linguistic features, like OS-provided processes.   But it would be a really bad idea to have to run every unit test in a separate process just because one can’t catch this one kind of programming error!

We can catch other kinds of programming error, such as requesting a method that does not exist, or indexing an array outside of its bounds.  Why should this one be different?

Unlike Smalltalk, where nil is an Object, or Java, where NULL is a basic value, being defined in Grace is a property of variables.  Accessing an undefined variable should raise a programmingError.  So, in

	var x
	…
	var y := x

the initializing assignment of y should be an error, since an attempt to evaluate x must fail.    What I recall agreeing on very early on in the Grace design is that we should not wait until someone tries to request a method on x to raise the error.

I’m quite happy for the unitinitalized variable error to be caught at compile time.  But if it’s not caught at compile time, it should raise some refinement of programmingError.

While I was thinking about this, I looked in the spec to see what we say about exceptions, and did some editing.  I took the description of the exception hierarchy from the Wiki page and put it in the spec.  (It’s been on the Wiki for 7 months now, so I figured that we should have finished discussing it.)

What would be really useful is is someone who is good with tools would set up a daemon that automatically translated the current version of the Spec from LaTex to HTML and pushed it out to gracelang.org every night.   (I guess that we could also do this with the PDF).

	Andrew



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


More information about the Grace-core mailing list