Ian Hulin <i...@hulin.org.uk> writes:
> I'm trying to write a V2/V1 compatible function like the following:
>
> (define (ly:include the-file)
>   (if (string>? (version) "1.9.10")
>       (include-from-path the-file)
>       (load-from-path the-file)))

The problem is that `include' and `include-from-path' are not
procedures, but syntactic constructs that actually replace themselves
with the contents of the included file at macro-expansion time.

Among other things, this allows you to include a file into a local
lexical environment, e.g. if "foo.scm" contains "(define test 5)" then
the following procedure will return 5, and `test' will become a local
variable within `foo':

  (define (foo)
    (include "foo.scm")
    test)

Since `include' and `include-from-path' is performed at macro-expansion
time, obviously its parameter must be a literal string at
macro-expansion time.  Therefore, you can't use it from a procedure as
you attempted, but you could make a macro instead:

(define-syntax ly:include
   (if (string>? (version) "1.9.10")
       (syntax-rules () ((_ fn) (include-from-path fn)))
       (syntax-rules () ((_ fn) (load-from-path fn)))))

    Best,
     Mark

Reply via email to