This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Implementing load-path for Kawa


Hi:

I am trying to implement load-path support in Kawa. I am a newbie to Scheme and Kawa. I have run into something that I do not understand, perhaps with Scheme macros or perhaps with a Kawa variation.

I have created some functions to define and manage the load-path:

<snip>
; Global file-path variable.
(define load-path (list))

; Add a path to the load path.
(define (add-load-path path)
	(set! load-path (append load-path (list path))))

; Function to find a specified file in the load-path.
(define (find-in-load-path path)
	(find (lambda (x) (file-exists? (string-append x "/" path))) load-path))
</snip>

I then created my own load function that overloads the default one:

<snip>
; Reference to the built-in load function.
(define default-load (eval load (null-environment)))

; Over-loaded load function.
(define (load path)
	(if (find-in-load-path path)
		(default-load (string-append (find-in-load-path path) "/" path))
		(default-load path)))
</snip>

So far so good. Kawa will now look for and load the file specified in path in any of the locations in load-path.

However, applying the same pattern to include and require gives me an error, which boils down to the following:

#|kawa:13|# ((eval include (null-environment)) "math.scm")
Argument  (#<macro include>) to 'apply-to-args' has wrong type (kawa.lang.Macro) (expected: procedure)
	at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:170)
...

and 

#|kawa:11|# ((eval require (null-environment)) "math.scm")
Argument  (kawa.standard.require@39b8d6f7) to 'apply-to-args' has wrong type (kawa.standard.require) (expected: procedure)
	at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:170)
...

However, (eval include (null-environment)) returns #<procedure include>, and (eval require (null-environment)) returns #<procedure require>. So it looks like it is getting a procedure.

I suspect that there is some nuance to Scheme macros that I am not understanding. From looking at the Kawa source code, include is defined as a schema 'define-syntax' macro and require is a Java class that subclasses Syntax. However, I am not sure how that pertains to the errors that I am seeing.

Any help appreciated. Any alternate approaches and suggestions also gratefully received.

Cheers,
Gerald


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]