[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: set-current-module broken in current Guile CVS version

From: Dirk Herrmann
Subject: Re: set-current-module broken in current Guile CVS version
Date: Fri, 29 Dec 2000 19:00:15 +0100 (MET)

On Thu, 28 Dec 2000, Dirk Herrmann wrote:

> There are two possibilities:  
> * We provide two different scm_eval functions, one that is 'safe' in the
>   sense that environment switches do not influence calling code and
>   another one, that allows switches to a different module remain effective
>   after the function returns.  The repl would then use the second one.
> * The repl is modified to somehow get the necessary information from the
>   code that is evaluated.
> Somehow I prefer the second solution, although I have no clear idea yet,
> how that should be accomplished best.

Below is a sketch for a possible implementation for the second solution.
It's just an idea, that you should be able to try out if you put it into a
script.  Comments are welcome, better solutions as well :-)

Best regards,
Dirk Herrmann

;;; Sketch of the idea, including some debugging outputs and, as an example
;;; for the code that is to be evalutated, a switch to a module 'foo'.

;;; PART 1:
;;; We add the following definitions to the module where the repl is defined:

(define-module (guile)) ;; or whereever the repl itself lies...

(define repl-push-module-stack #f)
(define repl-pop-module-stack #f)
(let* ((module-stack '()))
  (set! repl-push-module-stack
        (lambda ()
          (set! module-stack (cons (current-module) module-stack))))
  (set! repl-pop-module-stack
        (lambda ()
          (set-current-module (car module-stack))
          (set! module-stack (cdr module-stack)))))

;;; PART 2:
;;; The repl is modified to wrap the code to be executed in pairs of
;;; repl-pop-module-stack / repl-push-module-stack as shown below.

(define-module (guile-user))

(write (current-module)) (newline)

;;; START of the important stuff:

;;; Prepare the module stack before evaluating...
((module-ref (resolve-module '(guile)) 'repl-push-module-stack))

;;; This is what the wrapped code should look like.  The original user
;;; input in this example was '(define-module (foo))'
      (lambda ()
        ((module-ref (resolve-module '(guile)) 'repl-pop-module-stack)))
      (lambda ()                      ; ** This is an example for code that
        (define-module (foo)))        ; ** is to be evaluated.
      (lambda ()
        ((module-ref (resolve-module '(guile)) 'repl-push-module-stack))))

;;; After evaluating, take over the module that was active at the end:
((module-ref (resolve-module '(guile)) 'repl-pop-module-stack))

;;; END of the important stuff.

(write (current-module)) (newline)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]