[Grace-core] Importing resources

James Noble kjx at ecs.vuw.ac.nz
Fri Feb 7 00:55:36 PST 2014


> There is a three-sentence summary right at the end. Here's the
> teaser: what if
>  import "logo.png" as logo : Image
>  import "about.txt" as aboutText : String
> just did the right thing?

well I think that's pretty Graceful :-)

> Here is the system that I am semi-proposing. All existing working
> import statements continue to have their current meaning. We instate a
> syntactic restriction on the import paths of Grace modules: the given
> import path may not contain a "." character (U+002e FULL STOP) after
> the final occurrence of "/" (U+002f SOLIDUS).

alternatively, how about: if the important path does not contain a 
"." character  (U+002e FULL STOP) after the final occurrence of "/" (U+002f SOLIDUS).
then:  we interpret the string as if it had with a ".grace" postfix

similarly, if there's no name: prefix, we interpret it as a "load:" or "grace:" prefix.  

(I'm assuming the html file loader will require an http: prefix, or some distinguishing mark...

> How are these extensions mapped to handlers? Probably, a per-program
> registry is defined, and user code can add entries to it (but see
> below for potential issues).

yep..

> There are some lingering issues with this:
> 1) This global registry may be subject to conflict if two different
> third-party modules both want to hook onto the same extension. Some
> way of resolving an ambiguity may be required.

or at least detecting it...

> 4) The registry introduces an ordering dependency for imports. If I
> want to import a PNG resource as a GTK+ image, I need to have imported
> the GTK+ module first. This may lead to errors sometimes. Note that
> import order is already semantically important for ordinary modules.

I think the Object-Capability stuff comes to the rescue here.
Assume that modules that who want to define a rule have to say something like

registry.handle("png")  with(myLoader.new) 

or even just registry.register( myLoader ) 

the point is that only modules that can get to the registry can register handlers.
(well assuming none of those modules then hand of the registry to someone else -
and that's an easy check...) 

so can we load those modules first, before any others that use those handlers...?

>  At the language
> definition level this may be irrelevant, since there is no explicit
> compile-time/run-time distinction, and no concept of static linking.

right.  

so I think this is sounding doable  (so far)

J




More information about the Grace-core mailing list