[Grace-core] transitive imports

Kim Bruce kim at cs.pomona.edu
Wed Jun 4 11:49:39 PDT 2014


Discussions at the PL Design meeting got me thinking about how uniform our semantics are for imports.

As I understand it (and it seems to be implemented), imports are not transitive.  Here is the example I wrote:

File "imp.grace"
------------------
print "Hello, world!"
def x = 12

File imp2.grace
----------------------
import "imp" as imp
def y = 7
print(imp.x)

File "imp3.grace"
----------------------
import "imp2" as imp2
print(imp2.y)
print(imp2.imp.x)

Running imp3 results in:
Hello, world!
12
7
Error around line 3 of imp3: RuntimeError: no method imp in module<imp2>.
  called from module<imp2>.imp (defined nowhere in imp2 module) at imp3:3
  called from execution environment
   2: print(imp2.y)
   3: print(imp2.imp.x)

Thus it appears that import treats the name introduced as confidential by default.  This makes sense as the import is treated as a "def" declaration.  Unfortunately the system does not allow me to declare it as public to make it available.  It would be nice to make that possible.

Another issue (which I believe is an implementation issue) is that I cannot provide a type for an import.  If I replace the import statement in "imp2" by 

import "imp" as imp: {x:Number}

then the compiler crashes with the following error:
Internal compiler error, around line 3098 of parser: RuntimeError: Uninitialised value used as argument to dtype:= at line 3098 of parser.
  called fromObject.dtype:= at line 3098 of parser
  called frommodule<parser>.doimport at line 3312 of parser
  called frommodule<parser>.statement at line 3510 of parser
  called fromblock<parser:3504>.apply at line 574 of parser
  called frommodule<StandardPrelude>.while()do at line 3504 of parser
  called frommodule<parser>.parse at line 55 of compiler
  called fromexecution environment

These issues are related to my previous e-mail about not being able to declare top level defs in a module to be confidential.  (Actually you can declare it, but it is ignored as everything is treated as public.)

Kim






More information about the Grace-core mailing list