www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Suggestion: non-fatal failed imports

reply Bill Baxter <dnewsgroup billbaxter.com> writes:
I was thinking, in my Luigi lib, I was just thinking about adding 
support for Schooner's fonts.  But I don't want to require that in order 
to compile. Ok so I could add yet another version flag, but I was 
thinking that it would be nice if support for fonts could just be 
compiled in if found and not otherwise.

So what if there were something like try/catch for imports?

This works in Python, of course it's no problem there because imports 
are done at run time.  But it is a fairly commonly used idiom there, 
which says to me that if it exists it will get used.

Anyway, I seek some better way to control various optional dependencies 
than lots of --version flags.

--bb
Apr 27 2007
next sibling parent "Ameer Armaly" <ameer_armaly hotmail.com> writes:
"Bill Baxter" <dnewsgroup billbaxter.com> wrote in message 
news:f0u9pk$1cgd$1 digitalmars.com...
I was thinking, in my Luigi lib, I was just thinking about adding support 
for Schooner's fonts.  But I don't want to require that in order to 
compile. Ok so I could add yet another version flag, but I was thinking 
that it would be nice if support for fonts could just be compiled in if 
found and not otherwise.

 So what if there were something like try/catch for imports?

 This works in Python, of course it's no problem there because imports are 
 done at run time.  But it is a fairly commonly used idiom there, which 
 says to me that if it exists it will get used.

 Anyway, I seek some better way to control various optional dependencies 
 than lots of --version flags.
Probably not quite what you're looking for (and untested), but using a const uint and having each bit represent an option, and use static if? Might even work at runtime; I just randomly thought of it right now.
 --bb 
Apr 27 2007
prev sibling parent reply Gregor Richards <Richards codu.org> writes:
Bill Baxter wrote:
 I was thinking, in my Luigi lib, I was just thinking about adding 
 support for Schooner's fonts.  But I don't want to require that in order 
 to compile. Ok so I could add yet another version flag, but I was 
 thinking that it would be nice if support for fonts could just be 
 compiled in if found and not otherwise.
 
 So what if there were something like try/catch for imports?
 
 This works in Python, of course it's no problem there because imports 
 are done at run time.  But it is a fairly commonly used idiom there, 
 which says to me that if it exists it will get used.
 
 Anyway, I seek some better way to control various optional dependencies 
 than lots of --version flags.
 
 --bb
I actually considered adding something like this as a DSSS feature, but decided it would be too much of a hack. It would be nifty if this was a language feature. - Gregor Richards
Apr 28 2007
parent Bill Baxter <dnewsgroup billbaxter.com> writes:
Gregor Richards wrote:
 Bill Baxter wrote:
 I was thinking, in my Luigi lib, I was just thinking about adding 
 support for Schooner's fonts.  But I don't want to require that in 
 order to compile. Ok so I could add yet another version flag, but I 
 was thinking that it would be nice if support for fonts could just be 
 compiled in if found and not otherwise.

 So what if there were something like try/catch for imports?

 This works in Python, of course it's no problem there because imports 
 are done at run time.  But it is a fairly commonly used idiom there, 
 which says to me that if it exists it will get used.

 Anyway, I seek some better way to control various optional 
 dependencies than lots of --version flags.

 --bb
I actually considered adding something like this as a DSSS feature, but decided it would be too much of a hack. It would be nifty if this was a language feature. - Gregor Richards
All we need is static try catch ;-) static try { import missing.module; } catch(CompileTimeImportException e) { pragma(msg, "Compiling without support for missing.module") } else { version = usingMissingModule; } Or something like that.
Apr 28 2007