[Top][All Lists]

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

Re: loading a module via an absolute path

From: Rob Browning
Subject: Re: loading a module via an absolute path
Date: Sat, 05 Oct 2002 20:51:56 -0500
User-agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/21.2 (i386-pc-linux-gnu)

address@hidden (Paul Jarc) writes:

> which isn't always convenient.  I think I ought to be able to
> duplicate what I like about use-modules with something like this:
> (eval '(load "/path/to/foo.scm") new-environment)

  (eval-in-module '(primitive-load "/path/to/foo.scm") some-module)

might be what you want.

> - The manual says (load) will evaluate the file's contents in the
>   top-level environment.  Is that still true inside eval, or will it
>   load into the specified environment?
> - What's the difference between load and primitive-load?

I think that's roughly the difference.  If I recall right,
primitive-load doesn't alter the current-environment and doesn't
restore it after the load, but Marius can probably clarify if I'm

> - Is there a way to load from an already-open port rather than a
> filename?  Could I just loop with read and eval?  Would that handle,
> e.g., read-hash-extend properly?  I don't see any reason it
> wouldn't.

I think that should work.

> - How do I create a new environment?  The documented procedures don't
>   seem to exist:

How about this:

  $ guile
  guile> (use-modules (ice-9 safe))
  guile> (define msm (make-safe-module))
  guile> msm
  #<module 8089b50>
  guile> (module-ref msm 'car)
  #<primitive-procedure car>
  guile> (eval 'car msm)
  #<primitive-procedure car>

  guile> (use-modules (ice-9 safe-r5rs))                     
  guile> (define msm (null-environment 5))                                  
  guile> msm
  #<interface 807ed30>
  guile> (eval 'if msm)
  #<primitive-macro! if>
  guile> (module-ref msm 'if)
  #<primitive-macro! if>
  guile> (eval 'unlink msm)  

  In current input:
     6: 0* [eval unlink #<interface 807ed30>]
     ?: 1* unlink

  <unnamed port>: In expression unlink:
  <unnamed port>: Unbound variable: unlink
  ABORT: (unbound-variable)
  guile> (module-define! msm 'some-num 5)                          
  guile> (module-ref msm 'some-num)
  guile> (eval 'some-num msm)      
  guile> some-num

  In unknown file:
     ?: 0* some-num

  <unnamed port>: In expression some-num:
  <unnamed port>: Unbound variable: some-num
  ABORT: (unbound-variable)
  guile> (module-use! (current-module) msm)
  guile> some-num                          
  guile> (module-public-interface msm)
  guile> (define foo (resolve-module '(ice-9 safe)))
  guile> (module-use! (current-module) (module-public-interface foo))
  guile> (module-public-interface foo)
  #<interface (ice-9 safe) 808b200>


> guile> (null-environment 5)
> <unnamed port>:29:1: In expression (null-environment 5):
> <unnamed port>:29:1: Unbound variable: null-environment
> ABORT: (unbound-variable)
> guile> (scheme-report-environment 5)
> <unnamed port>:30:1: In expression (scheme-report-environment 5):
> <unnamed port>:30:1: Unbound variable: scheme-report-environment
> ABORT: (unbound-variable)
> guile> (assv-ref %guile-build-info 'guileversion)
> "1.6.0"

or perhaps just (version) :>

Hope this helps.

Rob Browning
rlb,, and
GPG=1C58 8B2C FB5E 3F64 EA5C  64AE 78FE E5FE F0CB A0AD

reply via email to

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