Ikarus does not initialize libraries on import

Asked by Pinku Surana

I read this explanation: https://bugs.launchpad.net/ikarus/+bug/174545/comments/1

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
For:
Ikarus Scheme Edit question
Assignee:
No assignee Edit question
Solved by:
Abdulaziz Ghuloum
Solved:
Last query:
Last reply:
Revision history for this message
Pinku Surana (suranap) said :
#1

WHOOPS! One comment in the code is wrong:

> (add 1 2) ;; FAILS! because define-generic hasn't been executed
should be ==>
> (add 1 2) ;; FAILS! because define-method in (math integer) hasn't been executed

Revision history for this message
Best Abdulaziz Ghuloum (aghuloum) said :
#2

> Is this design specific to Ikarus or expected behavior in R6RS?

AFAICT, R6RS does not specify when libraries get initialized.

> Could there be an extension to force initialization?

You already know how to force a library to be initialized, so, no extension is absolutely necessary. Yes, it looks like a kludge, but this seems to be the only portable way to do it (unless you reformulate your solution as to not use side effects).

BTW (out of curiosity) , how does define-method work as an internal define? Say:
(let loop ()
  (define-method foo ---)
  (if --- (loop) ---))
Does the table get extended for ever?

Revision history for this message
Pinku Surana (suranap) said :
#3

Thanks for the info.

> BTW (out of curiosity) , how does define-method work as an internal define?
> Say:
>

If the new method has the same signature as the old one, the old one gets
replaced by the new one. Your example will result in only one method in the
table.

On Sun, Jul 13, 2008 at 1:00 AM, Abdulaziz Ghuloum <
<email address hidden>> wrote:

> Your question #38789 on Ikarus Scheme changed:
> https://answers.launchpad.net/ikarus/+question/38789
>
> Status: Open => Answered
>
> Abdulaziz Ghuloum proposed the following answer:
> > Is this design specific to Ikarus or expected behavior in R6RS?
>
> AFAICT, R6RS does not specify when libraries get initialized.
>
> > Could there be an extension to force initialization?
>
> You already know how to force a library to be initialized, so, no
> extension is absolutely necessary. Yes, it looks like a kludge, but
> this seems to be the only portable way to do it (unless you reformulate
> your solution as to not use side effects).
>
> BTW (out of curiosity) , how does define-method work as an internal define?
> Say:
> (let loop ()
> (define-method foo ---)
> (if --- (loop) ---))
> Does the table get extended for ever?
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/ikarus/+question/38789/+confirm?answer_id=1
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/ikarus/+question/38789
>
> You received this question notification because you are a direct
> subscriber of the question.
>

Revision history for this message
Pinku Surana (suranap) said :
#4

Thanks Abdulaziz Ghuloum, that solved my question.