cond-expand feature testing for presence of a Java class
Per Bothner
per@bothner.com
Mon Apr 4 00:23:00 GMT 2011
On 04/03/2011 04:56 PM, Jamison Hope wrote:
> I recently found myself wanting to conditionalize some code on the
> presence of a Java class. At first, I tried to see if I could have a
> module call (provide 'some-feature) only when this class was found,
> but then I realized it would be much simpler to modify the feature
> testing in IfFeature.java to recognize class names as a last resort.
> This has proven quite handy for me, letting me do something like:
>
> (cond-expand
> (com.example.AClass ;; AClass is found in classpath, safe to use
> (define-simple-class MySubclass (com.example.AClass) ...))
> (else (error "AClass not found.")))
>
> It seems unlikely for some unrelated feature's name to exactly match a
> fully-qualified class name, so I think this patch is pretty safe.
Seems reasonable - but idea occurs to me: Perhaps we should
use the class: namespace prefix, as in:
http://www.gnu.org/software/kawa/Field-operations.html
Your example would be:
(cond-expand
(class:com.example.AClass ;; AClass is found in classpath, safe to use
(define-simple-class MySubclass (com.example.AClass) ...))
(else (error "AClass not found.")))
What do you think?
--
--Per Bothner
per@bothner.com http://per.bothner.com/
More information about the Kawa
mailing list