[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Strange error from %search-load-path via include-from-path when para
From: |
Mark H Weaver |
Subject: |
Re: Strange error from %search-load-path via include-from-path when parameter is not a literal string |
Date: |
Mon, 17 Oct 2011 17:54:06 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) |
Ian Hulin <address@hidden> 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