Firstly, I've prepared 4 files related to library. The contents are very simple. Like this;
;; foo.sld (define-library (foo) (import (scheme base)) (export bar) (include "impl/bar.scm")) ;; impl/bar.scm (include "buzz.scm") ;; impl/buzz.scm (define bar 'bar) ;; buzz.scm (define bar 'buzz)Now I put those files following directory structure;
./ + foo.sld + impl + bar.scm + buzz.scm + buzz.scmThen, wrote following script;
(import (scheme base) (scheme write) (foo)) (display bar) (newline)The question is, what would be the expected value to be printed 'bar or 'buzz? I first expected to be print 'bar with Sagittarius but it was 'buzz. Then checked with Chibi which also printed 'buzz. At this point I thought, oh R7RS de-facto would be 'buzz. Well it wasn't. I've also check with Gauche and Foment and these printed 'bar.
I know why this happens actually. When the first include was processed then the current loading path returned to the same directly as "foo.sld". Then second include "buzz.scm" is processed. I don't know how Gauche and Foment do this properly (well R7RS doesn't specify how to resolve the path so both are proper behaviour though).
Well, by now I've never seen this type of code in anywhere other than in my test. But I would like to go more intuitive behaviour.
13th August, 2014
I've modified compiler to be able to handle above case. What I've changed is that
- include and include-ci returns read expression and filename
- compiler sets current load path after include is done according to above filenam