Ikarus does not initialize libraries on import
I read this explanation: https:/
Is this design specific to Ikarus or expected behavior in R6RS? Could there be an extension to force initialization?
I ported an implementation of generic methods from Scheme48 to R6RS. A "generic" establishes a global variable that contains a method dispatch table. The methods are added as a side-effect into that global variable. Right now, I have to manually force Ikarus to initialize the libraries with new methods. That's not practical, but I haven't thought of another way to do this without side-effects. Anyone, at anytime, could write a new library that adds more methods to a generic.
Here's a stripped down example:
Ikarus Scheme version 0.0.3+ (revision 1525, build 2008-06-28)
Copyright (c) 2006-2008 Abdulaziz Ghuloum
> (library (math)
(export add &add)
(import (ikarus) (method))
(define-generic add &add (x y)) ;; creates function called "add" and method table called "&add"
(printf "initialized (math) \n")
)
> (library (math integer)
(export init-math-integer)
(import (ikarus) (method) (math))
;; ** Here's the problem. define-method inserts a method into &add in the math library.
(define-method &add ((x :integer) (y :integer)) (+ x y)) ;; turns into: (add-method! &add ... body of method ...)
(define (init-math-integer) #t)
(printf "initialized (math integer) \n")
)
> (import (math))
> (import (math integer))
> (add 1 2) ;; FAILS! because define-generic hasn't been executed
initialized (math)
Unhandled exception
Condition components:
1. &assertion
2. &message: "invalid or unimplemented operation"
3. &irritants: (add (2))
> (init-math-integer) ;; Force that library to initialize
initialized (math integer)
#t
> (add 1 2) ;; WORKS, but it's unpleasant
3
>
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- Abdulaziz Ghuloum
- Solved:
- Last query:
- Last reply: