I don't think Chez supports a Chez-specific file extension. I had come across the separate library with implementation-specific extension solution before, and that's what I was using (taking advantage of .ikarus.sls). It's a good solution. However, I was unhappy with it because I didn't like having more than one source file. The current solution is greatly appealing to me because everything lives in one top-level script and I don't have to keep sending multiple files around.
On Fri, May 1, 2009 at 4:48 PM, Abdulaziz Ghuloum <[email protected]> wrote: > > On May 1, 2009, at 4:42 AM, Ramana Kumar wrote: > >> I finally discovered a way to make definitions depending on whether a >> certain library is available: >> >> (define make-engine >> (call/cc >> (lambda (k) >> (with-exception-handler >> (lambda (x) (k #f)) >> (lambda () (eval 'make-engine (environment '(scheme)))))))) >> >> (define-syntax if-engines >> (lambda (o) >> (define make-engine >> (call/cc >> (lambda (k) >> (with-exception-handler >> (lambda (x) (k #f)) >> (lambda () (eval 'make-engine (environment '(scheme)))))))) >> (syntax-case o () >> ((_ c) #'(if-engines c (if #f #f))) >> ((_ c a) (if make-engine #'c #'a))))) >> >> I then go on to use if-engines like this: (if-engines (begin some >> definitions which require make-engine) (begin alternative >> definitions)). > > So far so good. > >> As you can see I had to define make-engine twice, once for syntax and >> once for runtime. I know there's a nonstandard way to define it only >> once: (meta define make-engine ...) (actually, I'm not sure whether >> you still have to define it for runtime if you do that...). Is there >> another portable solution than defining it twice which would still let >> me put all my code in one file? > > I presume you're talking about Chez's meta keyword, which afaik makes > the definition available at macro expansion time and not at run time. > If you want a definition that's available in both times, and you want > to do it portably, it has to be put in a separate library. Too bad. > > Anyways, does Chez support a Chez-specific library file extension > like foo.chez.sls? This is pretty much the de facto standard way of > solving problems like yours. So, you define a chez library like > > ;;; ramana/engines.chez.sls > (library (ramana engines) > (export make-engine if-engines) > (import (scheme)) > (define-syntax if-engines > (syntax-rules () > [(_ c a) c] > [(_ c) c]))) > > ;;; ramana/engines.sls > (library (ramana engines) > (export if-engines) ;;; not exporting make-engine to get a > (import (rnrs)) ;;; syntax error if used incorrectly > (define-syntax if-engines > (syntax-rules () > [(_ c a) a] > [(_ c) (begin)]))) > > That's less code than what you have and is simpler since it does > not involve eval, exceptions, and lengthy macros. > > If Chez does not support this extension, well, you know where > LH-401 is. :-) > > Aziz,,, >
