unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* set-current-module in .guile ?
@ 2008-04-05 17:24 Scott N. Walck
  2008-04-05 21:00 ` Jon Wilson
  2008-04-09 20:16 ` Neil Jerram
  0 siblings, 2 replies; 14+ messages in thread
From: Scott N. Walck @ 2008-04-05 17:24 UTC (permalink / raw
  To: guile-user

Dear Guilers,

Dan Gildea has ported a large fraction of Gerry Sussman's scmutils
code from MIT-scheme to guile.  In doing so, he uses guile modules
instead of MIT-scheme environments.  Much of the code creates a module
called "generic-environment".  In an interactive guile session, you
type

(set-current-module generic-environment)

and this redefines "+", for example, to add functions and vectors.

I would like to know if there is a way to set the interactive
environment to "generic-environment" in a .guile file.  If I put

(set-current-module generic-environment)

in a .guile file, it does nothing.  (I suppose because the current
module when reading the .guile file is different from the current
module in an interactive guile session?)

I would like to use this guile-scmutils with physics students, and I
would like to hide from them the need to execute

(set-current-module generic-environment)

in an interactive session.  Of course, I could pre-load

(define start
  (lambda ()
    (set-current-module generic-environment)))

in a .guile file or with the -l option, and then students would only
need to type

(start)

but it's still awkward, and it's a detail that I don't want to have to
explain to them.

I would appreciate any suggestions that folks might have.

Scott

-- 
Scott N. Walck
Associate Professor of Physics
Lebanon Valley College
Annville, PA 17003
phone: 717-867-6153
fax:   717-867-6075
email: walck@lvc.edu





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set-current-module in .guile ?
  2008-04-05 17:24 set-current-module in .guile ? Scott N. Walck
@ 2008-04-05 21:00 ` Jon Wilson
  2008-04-06  0:01   ` Walck, Scott
  2008-04-09 20:16 ` Neil Jerram
  1 sibling, 1 reply; 14+ messages in thread
From: Jon Wilson @ 2008-04-05 21:00 UTC (permalink / raw
  To: guile-user

Hi Scott,
Can you for some reason not use use-modules?
Regards,
Jon

Scott N. Walck wrote:
> Dear Guilers,
> 
> Dan Gildea has ported a large fraction of Gerry Sussman's scmutils
> code from MIT-scheme to guile.  In doing so, he uses guile modules
> instead of MIT-scheme environments.  Much of the code creates a module
> called "generic-environment".  In an interactive guile session, you
> type
> 
> (set-current-module generic-environment)
> 
> and this redefines "+", for example, to add functions and vectors.
> 
> I would like to know if there is a way to set the interactive
> environment to "generic-environment" in a .guile file.  If I put
> 
> (set-current-module generic-environment)
> 
> in a .guile file, it does nothing.  (I suppose because the current
> module when reading the .guile file is different from the current
> module in an interactive guile session?)
> 
> I would like to use this guile-scmutils with physics students, and I
> would like to hide from them the need to execute
> 
> (set-current-module generic-environment)
> 
> in an interactive session.  Of course, I could pre-load
> 
> (define start
>   (lambda ()
>     (set-current-module generic-environment)))
> 
> in a .guile file or with the -l option, and then students would only
> need to type
> 
> (start)
> 
> but it's still awkward, and it's a detail that I don't want to have to
> explain to them.
> 
> I would appreciate any suggestions that folks might have.
> 
> Scott
> 





^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: set-current-module in .guile ?
  2008-04-05 21:00 ` Jon Wilson
@ 2008-04-06  0:01   ` Walck, Scott
  2008-04-06 14:58     ` Ludovic Courtès
  0 siblings, 1 reply; 14+ messages in thread
From: Walck, Scott @ 2008-04-06  0:01 UTC (permalink / raw
  To: guile-user@gnu.org

I don't know how to use use-modules in this situation.  I'm not trying to load a module that has been prepared as a file.  I tried

(load "/usr/local/src/guile-scmutils/src/load.scm")
(use-modules generic-environment)

and

(load "/usr/local/src/guile-scmutils/src/load.scm")
(use-modules 'generic-environment)

and

(load "/usr/local/src/guile-scmutils/src/load.scm")
(use-modules (generic-environment))

in my .guile file, but none of them work.

Is there a way to take a module object like generic-environment and write it to a file that could be loaded with use-modules?

Scott N. Walck
Associate Professor of Physics
Lebanon Valley College

________________________________________
From: guile-user-bounces+walck=lvc.edu@gnu.org [guile-user-bounces+walck=lvc.edu@gnu.org] On Behalf Of Jon Wilson [jsw@wilsonjc.us]
Sent: Saturday, April 05, 2008 5:00 PM
To: guile-user@gnu.org
Subject: Re: set-current-module in .guile ?

Hi Scott,
Can you for some reason not use use-modules?
Regards,
Jon

Scott N. Walck wrote:
> Dear Guilers,
>
> Dan Gildea has ported a large fraction of Gerry Sussman's scmutils
> code from MIT-scheme to guile.  In doing so, he uses guile modules
> instead of MIT-scheme environments.  Much of the code creates a module
> called "generic-environment".  In an interactive guile session, you
> type
>
> (set-current-module generic-environment)
>
> and this redefines "+", for example, to add functions and vectors.
>
> I would like to know if there is a way to set the interactive
> environment to "generic-environment" in a .guile file.  If I put
>
> (set-current-module generic-environment)
>
> in a .guile file, it does nothing.  (I suppose because the current
> module when reading the .guile file is different from the current
> module in an interactive guile session?)
>
> I would like to use this guile-scmutils with physics students, and I
> would like to hide from them the need to execute
>
> (set-current-module generic-environment)
>
> in an interactive session.  Of course, I could pre-load
>
> (define start
>   (lambda ()
>     (set-current-module generic-environment)))
>
> in a .guile file or with the -l option, and then students would only
> need to type
>
> (start)
>
> but it's still awkward, and it's a detail that I don't want to have to
> explain to them.
>
> I would appreciate any suggestions that folks might have.
>
> Scott
>








^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set-current-module in .guile ?
  2008-04-06  0:01   ` Walck, Scott
@ 2008-04-06 14:58     ` Ludovic Courtès
  2008-04-07  1:27       ` Walck, Scott
  0 siblings, 1 reply; 14+ messages in thread
From: Ludovic Courtès @ 2008-04-06 14:58 UTC (permalink / raw
  To: guile-user

Hi,

"Walck, Scott" <walck@lvc.edu> writes:

> I don't know how to use use-modules in this situation.

That should be something like:

  (module-use! (current-module) generic-environment)

`use-modules' is just syntactic sugar that does this.

Let us know if it solves you problem.

Thanks,
Ludo'.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: set-current-module in .guile ?
  2008-04-06 14:58     ` Ludovic Courtès
@ 2008-04-07  1:27       ` Walck, Scott
  2008-04-07  7:16         ` Ludovic Courtès
  0 siblings, 1 reply; 14+ messages in thread
From: Walck, Scott @ 2008-04-07  1:27 UTC (permalink / raw
  To: guile-user@gnu.org

Hi,

That seems to cause me a core dump.

scott@dell:~$ guile
guile> (load "/usr/local/src/guile-scmutils/src/load.scm")
guile> +
#<primitive-generic +>
guile> (module-use! (current-module) generic-environment)
#f
guile> +
#<procedure g:+ args>
guile> (+ 2 3)
5
guile> (+ (vector 5 6) (vector 7 8))
Segmentation fault (core dumped)
scott@dell:~$

Here is how it is designed to work:

scott@dell:~$ guile
guile> (load "/usr/local/src/guile-scmutils/src/load.scm")
guile> +
#<primitive-generic +>
guile> (+ (vector 2 3) (vector 5 6))

Backtrace:
In current input:
   3: 0* [+ {#(2 3)} #(5 6)]

<unnamed port>:3:1: In procedure + in expression (+ (vector 2 3) (vector 5 6)):
<unnamed port>:3:1: Wrong type argument in position 1: #(2 3)
ABORT: (wrong-type-arg)
guile> (set-current-module generic-environment)
#<directory (guile-user) b7bd75e0>
guile> +
#<procedure g:+ args>
guile> (+ (vector 2 3) (vector 5 6))
#(7 9)
guile>

and what I'd really like to do is find a way to effectively execute the

(set-current-module generic-environment)

command before the user gets the guile prompt.  I'll keep trying things, and let you know if something works.

What puzzles me is that if I just put code in my .guile file to define the things I want, like

(define + g:+)
(define * g:*)
etc.,

I begin to get strange stack overflows, and what appear to be infinite loops.  I conclude that the underlying primitive operations are needed somewhere by some procedure.  The whole thing is pretty treacherous, I guess.  Thanks for your ideas.

Scott


________________________________________
From: guile-user-bounces+walck=lvc.edu@gnu.org [guile-user-bounces+walck=lvc.edu@gnu.org] On Behalf Of Ludovic Courtès [ludo@gnu.org]
Sent: Sunday, April 06, 2008 10:58 AM
To: guile-user@gnu.org
Subject: Re: set-current-module in .guile ?

Hi,

"Walck, Scott" <walck@lvc.edu> writes:

> I don't know how to use use-modules in this situation.

That should be something like:

  (module-use! (current-module) generic-environment)

`use-modules' is just syntactic sugar that does this.

Let us know if it solves you problem.

Thanks,
Ludo'.








^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set-current-module in .guile ?
  2008-04-07  1:27       ` Walck, Scott
@ 2008-04-07  7:16         ` Ludovic Courtès
  2008-04-07 11:27           ` Walck, Scott
  0 siblings, 1 reply; 14+ messages in thread
From: Ludovic Courtès @ 2008-04-07  7:16 UTC (permalink / raw
  To: guile-user

Hi,

"Walck, Scott" <walck@lvc.edu> writes:

> guile> (+ (vector 5 6) (vector 7 8))
> Segmentation fault (core dumped)

It's possible that it's a bug in your implementation of `+', i.e., in
`guile-scmutils'.  Can you run gdb on the core (using "gdb `which guile`
core") and show us the backtrace (using "bt" within gdb)?

> guile> (set-current-module generic-environment)
> #<directory (guile-user) b7bd75e0>
> guile> +
> #<procedure g:+ args>
> guile> (+ (vector 2 3) (vector 5 6))
> #(7 9)

Strange that it works here.  So the above segfault may not be due to
`guile-scmutils'...

Thanks,
Ludovic.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: set-current-module in .guile ?
  2008-04-07  7:16         ` Ludovic Courtès
@ 2008-04-07 11:27           ` Walck, Scott
  2008-04-07 13:38             ` Ludovic Courtès
  0 siblings, 1 reply; 14+ messages in thread
From: Walck, Scott @ 2008-04-07 11:27 UTC (permalink / raw
  To: guile-user@gnu.org

Hi,

I don't think it's the + function.  I get a segfault just by typing (exit).  I don't get a core file, though, in either case.  Why is that?

scott@dell:~/computer/guile$ guile
guile> (load "/usr/local/src/guile-scmutils/src/load.scm")
guile> (module-use! (current-module) generic-environment)
#f
guile> (exit)
Segmentation fault (core dumped)

Thanks,

Scott


________________________________________
From: guile-user-bounces+walck=lvc.edu@gnu.org [guile-user-bounces+walck=lvc.edu@gnu.org] On Behalf Of Ludovic Courtès [ludo@gnu.org]
Sent: Monday, April 07, 2008 3:16 AM
To: guile-user@gnu.org
Subject: Re: set-current-module in .guile ?

Hi,

"Walck, Scott" <walck@lvc.edu> writes:

> guile> (+ (vector 5 6) (vector 7 8))
> Segmentation fault (core dumped)

It's possible that it's a bug in your implementation of `+', i.e., in
`guile-scmutils'.  Can you run gdb on the core (using "gdb `which guile`
core") and show us the backtrace (using "bt" within gdb)?

> guile> (set-current-module generic-environment)
> #<directory (guile-user) b7bd75e0>
> guile> +
> #<procedure g:+ args>
> guile> (+ (vector 2 3) (vector 5 6))
> #(7 9)

Strange that it works here.  So the above segfault may not be due to
`guile-scmutils'...

Thanks,
Ludovic.








^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set-current-module in .guile ?
  2008-04-07 11:27           ` Walck, Scott
@ 2008-04-07 13:38             ` Ludovic Courtès
  2008-04-07 15:07               ` Scott N. Walck
  0 siblings, 1 reply; 14+ messages in thread
From: Ludovic Courtès @ 2008-04-07 13:38 UTC (permalink / raw
  To: guile-user

Hi,

"Walck, Scott" <walck@lvc.edu> writes:

> I don't think it's the + function.  I get a segfault just by typing
> (exit).  I don't get a core file, though, in either case.  Why is
> that?

You do get a core file since it says "core dumped".  Maybe it's named
`core.123' or something like that instead of just `core'.  Otherwise,
type "ulimit -c unlimited" and try again.

Thanks,
Ludovic.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set-current-module in .guile ?
  2008-04-07 13:38             ` Ludovic Courtès
@ 2008-04-07 15:07               ` Scott N. Walck
  2008-04-08 13:40                 ` Ludovic Courtès
  2008-04-09 15:05                 ` Ludovic Courtès
  0 siblings, 2 replies; 14+ messages in thread
From: Scott N. Walck @ 2008-04-07 15:07 UTC (permalink / raw
  To: guile-user@gnu.org

Hi,

Thanks for the "ulimit -c unlimited" command.

Here is the backtrace from gdb.

[walck@entangle:~]$ ulimit -c unlimited
[walck@entangle:~]$ guile
guile> (load "/usr/local/src/guile-scmutils/src/load.scm")
guile> (module-use! (current-module) generic-environment)
#f
guile> +
#<procedure g:+ args>
guile> (+ (vector 5 6) (vector 7 8))
Segmentation fault (core dumped)
[walck@entangle:~]$ ls core*
core.18853
[walck@entangle:~]$ gdb `which guile` core.18853
GNU gdb Red Hat Linux (6.3.0.0-1.122rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".

Reading symbols from shared object read from target memory...done.
Loaded system supplied DSO at 0x915000
Core was generated by `guile'.
Program terminated with signal 11, Segmentation fault.

warning: svr4_current_sos: Can't read pathname for load map: Input/output error

Reading symbols from /usr/local/lib/libguile.so.17...done.
Loaded symbols for /usr/local/lib/libguile.so.17
Reading symbols from /usr/lib/sse2/libgmp.so.3...done.
Loaded symbols for /usr/lib/sse2/libgmp.so.3
Reading symbols from /lib/libcrypt.so.1...done.
Loaded symbols for /lib/libcrypt.so.1
Reading symbols from /lib/libm.so.6...done.
Loaded symbols for /lib/libm.so.6
Reading symbols from /usr/local/lib/libltdl.so.3...done.
Loaded symbols for /usr/local/lib/libltdl.so.3
Reading symbols from /lib/libpthread.so.0...done.
Loaded symbols for /lib/libpthread.so.0
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /lib/libdl.so.2...done.
Loaded symbols for /lib/libdl.so.2
Reading symbols from /usr/local/lib/libguilereadline-v-17.so.17...done.
Loaded symbols for /usr/local/lib/libguilereadline-v-17.so.17
Reading symbols from /usr/lib/libreadline.so.5...done.
Loaded symbols for /usr/lib/libreadline.so.5
Reading symbols from /usr/lib/libncurses.so.5...done.
Loaded symbols for /usr/lib/libncurses.so.5
Reading symbols from /usr/local/lib/libguile-srfi-srfi-1-v-3.so.3...done.
Loaded symbols for /usr/local/lib/libguile-srfi-srfi-1-v-3.so.3
#0  0x00168d0c in scm_hash_fn_get_handle (table=0xb7f01560, obj=0xb7ef7190, 
    hash_fn=0x167b40 <scm_ihashq>, assoc_fn=0x1393d0 <scm_sloppy_assq>, 
    closure=0x0) at hashtab.c:415
415	{
(gdb) bt
#0  0x00168d0c in scm_hash_fn_get_handle (table=0xb7f01560, obj=0xb7ef7190, 
    hash_fn=0x167b40 <scm_ihashq>, assoc_fn=0x1393d0 <scm_sloppy_assq>, 
    closure=0x0) at hashtab.c:415
#1  0x00169d59 in scm_hash_fn_ref (table=0xb7f01560, obj=0xb7ef7190, 
    dflt=0x4, hash_fn=0x167b40 <scm_ihashq>, 
    assoc_fn=0x1393d0 <scm_sloppy_assq>, closure=0x0) at hashtab.c:500
#2  0x00169eff in scm_hashq_ref (table=0xb7f01560, key=0xb7ef7190, dflt=0x204)
    at hashtab.c:613
#3  0x0016fa78 in module_variable (module=0xb7f01590, sym=0xb7ef7190)
    at modules.c:289
#4  0x0016fae5 in module_variable (module=Variable "module" is not available.
) at modules.c:307
#5  0x0016fae5 in module_variable (module=Variable "module" is not available.
) at modules.c:307
#6  0x0016fae5 in module_variable (module=Variable "module" is not available.
) at modules.c:307

Thanks,

Scott



Ludovic Courtès writes:
 > Hi,
 > 
 > "Walck, Scott" <walck@lvc.edu> writes:
 > 
 > > I don't think it's the + function.  I get a segfault just by typing
 > > (exit).  I don't get a core file, though, in either case.  Why is
 > > that?
 > 
 > You do get a core file since it says "core dumped".  Maybe it's named
 > `core.123' or something like that instead of just `core'.  Otherwise,
 > type "ulimit -c unlimited" and try again.
 > 
 > Thanks,
 > Ludovic.
 > 
 > 
 > 
 > 






^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set-current-module in .guile ?
  2008-04-07 15:07               ` Scott N. Walck
@ 2008-04-08 13:40                 ` Ludovic Courtès
  2008-04-08 15:41                   ` Scott N. Walck
  2008-04-09 15:05                 ` Ludovic Courtès
  1 sibling, 1 reply; 14+ messages in thread
From: Ludovic Courtès @ 2008-04-08 13:40 UTC (permalink / raw
  To: guile-user

Hi,

"Scott N. Walck" <walck@lvc.edu> writes:

> [walck@entangle:~]$ guile
> guile> (load "/usr/local/src/guile-scmutils/src/load.scm")
> guile> (module-use! (current-module) generic-environment)
> #f
> guile> +
> #<procedure g:+ args>
> guile> (+ (vector 5 6) (vector 7 8))
> Segmentation fault (core dumped)

It starts looking like something worrying from the Guile side.  ;-)

I tried installing guile-scmutils to reproduce the problem but failed.
What version of Guile and SLIB are you using?

With SLIB 3b1 and Guile HEAD, I get:

  $ guile -L ~/soft/lib/ -l load.scm 
  Backtrace:
  In unknown file:
     ?: 0* [primitive-load "/home/ludo/soft/lib/slib/factor.scm"]
  In /home/ludo/soft/lib/slib/factor.scm:
    90: 1* (define prime:sieve (bytes 0 0 1 1 0 1 0 1 ...))
    90: 2  (define-public prime:sieve (bytes 0 0 1 1 0 1 0 1 ...))
    90: 3  (begin (define-private prime:sieve (bytes 0 0 1 ...)) (eval-case (# #)))
  In unknown file:
     ?: 4* (define-private prime:sieve (bytes 0 0 1 1 0 1 0 1 ...))
  In /home/ludo/soft/lib/slib/factor.scm:
    90: 5* [bytes 0 0 1 1 0 1 0 1 ...]
  In /home/ludo/soft/lib/slib/byte.scm:
    61: 6  [list->array 1 #u32(32) (0 0 1 1 0 1 0 1 0 ...)]

  /home/ludo/soft/lib/slib/byte.scm:61:3: In procedure list->array in expression (list->array 1 (A:fixN8b) ...):
  /home/ludo/soft/lib/slib/byte.scm:61:3: Wrong number of arguments to #<primitive-procedure list->array>

(Where `~/soft/lib' is that path to SLIB and `load.scm' is
guile-scmutils' load file.)

Actually, SLIB's `array' module isn't accessible from Guile for some
reason:

  guile> (use-modules (ice-9 slib))
  guile> (require 'array)
  #t
  guile> array?
  #<primitive-procedure array?>  ;; <--- This is Guile's built-in proc
  guile> A:bool 
  #<procedure at1 opt> ;; <--- but this one's from SLIB

Any idea?

Thanks,
Ludovic.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set-current-module in .guile ?
  2008-04-08 13:40                 ` Ludovic Courtès
@ 2008-04-08 15:41                   ` Scott N. Walck
  0 siblings, 0 replies; 14+ messages in thread
From: Scott N. Walck @ 2008-04-08 15:41 UTC (permalink / raw
  To: guile-user@gnu.org

Hi,

I'm using SLIB 3a5 and Guile 1.8.3.  I've had trouble with SLIB 3b1
also.

Scott


Ludovic Courtès writes:
 > Hi,
 > 
 > "Scott N. Walck" <walck@lvc.edu> writes:
 > 
 > > [walck@entangle:~]$ guile
 > > guile> (load "/usr/local/src/guile-scmutils/src/load.scm")
 > > guile> (module-use! (current-module) generic-environment)
 > > #f
 > > guile> +
 > > #<procedure g:+ args>
 > > guile> (+ (vector 5 6) (vector 7 8))
 > > Segmentation fault (core dumped)
 > 
 > It starts looking like something worrying from the Guile side.  ;-)
 > 
 > I tried installing guile-scmutils to reproduce the problem but failed.
 > What version of Guile and SLIB are you using?
 > 
 > With SLIB 3b1 and Guile HEAD, I get:
 > 
 >   $ guile -L ~/soft/lib/ -l load.scm
 >   Backtrace:
 >   In unknown file:
 >      ?: 0* [primitive-load "/home/ludo/soft/lib/slib/factor.scm"]
 >   In /home/ludo/soft/lib/slib/factor.scm:
 >     90: 1* (define prime:sieve (bytes 0 0 1 1 0 1 0 1 ...))
 >     90: 2  (define-public prime:sieve (bytes 0 0 1 1 0 1 0 1 ...))
 >     90: 3  (begin (define-private prime:sieve (bytes 0 0 1 ...)) (eval-case (# #)))
 >   In unknown file:
 >      ?: 4* (define-private prime:sieve (bytes 0 0 1 1 0 1 0 1 ...))
 >   In /home/ludo/soft/lib/slib/factor.scm:
 >     90: 5* [bytes 0 0 1 1 0 1 0 1 ...]
 >   In /home/ludo/soft/lib/slib/byte.scm:
 >     61: 6  [list->array 1 #u32(32) (0 0 1 1 0 1 0 1 0 ...)]
 > 
 >   /home/ludo/soft/lib/slib/byte.scm:61:3: In procedure list->array in expression (list->array 1 (A:fixN8b) ...):
 >   /home/ludo/soft/lib/slib/byte.scm:61:3: Wrong number of arguments to #<primitive-procedure list->array>
 > 
 > (Where `~/soft/lib' is that path to SLIB and `load.scm' is
 > guile-scmutils' load file.)
 > 
 > Actually, SLIB's `array' module isn't accessible from Guile for some
 > reason:
 > 
 >   guile> (use-modules (ice-9 slib))
 >   guile> (require 'array)
 >   #t
 >   guile> array?
 >   #<primitive-procedure array?>  ;; <--- This is Guile's built-in proc
 >   guile> A:bool
 >   #<procedure at1 opt> ;; <--- but this one's from SLIB
 > 
 > Any idea?
 > 
 > Thanks,
 > Ludovic.
 > 
 > 
 > 
 > 

-- 
Scott N. Walck
Associate Professor of Physics
Lebanon Valley College
Annville, PA 17003
phone: 717-867-6153
fax:   717-867-6075
email: walck@lvc.edu





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set-current-module in .guile ?
  2008-04-07 15:07               ` Scott N. Walck
  2008-04-08 13:40                 ` Ludovic Courtès
@ 2008-04-09 15:05                 ` Ludovic Courtès
  2008-04-09 15:24                   ` Walck, Scott
  1 sibling, 1 reply; 14+ messages in thread
From: Ludovic Courtès @ 2008-04-09 15:05 UTC (permalink / raw
  To: guile-user

Hi,

I can reproduce the problem now, with Guile 1.8 and SLIB 3a5.

"Scott N. Walck" <walck@lvc.edu> writes:

> [walck@entangle:~]$ guile
> guile> (load "/usr/local/src/guile-scmutils/src/load.scm")
> guile> (module-use! (current-module) generic-environment)
> #f
> guile> +
> #<procedure g:+ args>
> guile> (+ (vector 5 6) (vector 7 8))
> Segmentation fault (core dumped)

That's because there's a circular reference in the modules:

  guile> (module-uses generic-environment)
  (#<directory (guile-user) b7c35620>)
  guile> (current-module)
  #<directory (guile-user) b7c35620>

IOW, `generic-environment' uses `(guile-user)' (the default module
that's used when one get to the REPL), and the `module-use!' line above
makes `(guile-user)' use `generic-environment'.

Thus, further variable lookups that are not satisfied by either module
are bound to fail: the `module_variable ()' function in `modules.c'
looks for the variable in `(guile-user)', then in `generic-environment',
then in `(guile-user)', and so on.

This should be reported as a `guile-scmutils' bug.  One possibility is
to fix the way `generic-environment' is created in `kernel/genenv.scm'.
Guile-scmutils should really use modules in a more orthodox way rather
than expect users to fiddle with `set-current-module', `module-use!',
etc.

Thanks,
Ludovic.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: set-current-module in .guile ?
  2008-04-09 15:05                 ` Ludovic Courtès
@ 2008-04-09 15:24                   ` Walck, Scott
  0 siblings, 0 replies; 14+ messages in thread
From: Walck, Scott @ 2008-04-09 15:24 UTC (permalink / raw
  To: guile-user@gnu.org

Thanks, Loduvic.

I appreciate your effort looking at this.

Scott



________________________________________
From: guile-user-bounces+walck=lvc.edu@gnu.org [guile-user-bounces+walck=lvc.edu@gnu.org] On Behalf Of Ludovic Courtès [ludo@gnu.org]
Sent: Wednesday, April 09, 2008 11:05 AM
To: guile-user@gnu.org
Subject: Re: set-current-module in .guile ?

Hi,

I can reproduce the problem now, with Guile 1.8 and SLIB 3a5.

"Scott N. Walck" <walck@lvc.edu> writes:

> [walck@entangle:~]$ guile
> guile> (load "/usr/local/src/guile-scmutils/src/load.scm")
> guile> (module-use! (current-module) generic-environment)
> #f
> guile> +
> #<procedure g:+ args>
> guile> (+ (vector 5 6) (vector 7 8))
> Segmentation fault (core dumped)

That's because there's a circular reference in the modules:

  guile> (module-uses generic-environment)
  (#<directory (guile-user) b7c35620>)
  guile> (current-module)
  #<directory (guile-user) b7c35620>

IOW, `generic-environment' uses `(guile-user)' (the default module
that's used when one get to the REPL), and the `module-use!' line above
makes `(guile-user)' use `generic-environment'.

Thus, further variable lookups that are not satisfied by either module
are bound to fail: the `module_variable ()' function in `modules.c'
looks for the variable in `(guile-user)', then in `generic-environment',
then in `(guile-user)', and so on.

This should be reported as a `guile-scmutils' bug.  One possibility is
to fix the way `generic-environment' is created in `kernel/genenv.scm'.
Guile-scmutils should really use modules in a more orthodox way rather
than expect users to fiddle with `set-current-module', `module-use!',
etc.

Thanks,
Ludovic.








^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set-current-module in .guile ?
  2008-04-05 17:24 set-current-module in .guile ? Scott N. Walck
  2008-04-05 21:00 ` Jon Wilson
@ 2008-04-09 20:16 ` Neil Jerram
  1 sibling, 0 replies; 14+ messages in thread
From: Neil Jerram @ 2008-04-09 20:16 UTC (permalink / raw
  To: walck; +Cc: guile-user

"Scott N. Walck" <walck@lvc.edu> writes:

> Dear Guilers,
>
> Dan Gildea has ported a large fraction of Gerry Sussman's scmutils
> code from MIT-scheme to guile.

That sounds interesting!

>  In doing so, he uses guile modules
> instead of MIT-scheme environments.  Much of the code creates a module
> called "generic-environment".  In an interactive guile session, you
> type
>
> (set-current-module generic-environment)
>
> and this redefines "+", for example, to add functions and vectors.
>
> I would like to know if there is a way to set the interactive
> environment to "generic-environment" in a .guile file.  If I put
>
> (set-current-module generic-environment)
>
> in a .guile file, it does nothing.  (I suppose because the current
> module when reading the .guile file is different from the current
> module in an interactive guile session?)

Some further thoughts on this...  When you invoke Guile interactively,
what it actually does is run a canned script, namely:

(begin
  (turn-on-debugging)
  (load-user-init)         ; This loads your .guile
  (top-repl))

All of those procedures are defined in ice-9/boot-9.scm, so you can
see what they do by looking at their code.

The cause of your specific problem is that (top-repl) does:

  (let ((guile-user-module (resolve-module '(guile-user))))
    ...
    (set-current-module guile-user-module)
    ...

So even though (set-current-module generic-environment) in .guile does
have an effect, that effect is overridden by the later
set-current-module call here.

One overall solution is to settle for (guile-user) being your current
module, and import everything you need from generic-environment by
making (guile-user) use generic-environment - as has been
suggested (and hopefully now debugged!) by others.

Another option is to take a copy of the (top-repl) code, and modify it
to do what you want - i.e. the set the current module to
generic-environment, instead of to (guile-user).  Then you can create
a file containing the definition of scmutils-top-repl, and top level
code:

(begin
  (turn-on-debugging)
  (load-user-init)
  (scmutils-top-repl))

and invoke as "guile -s <filename>".

Hope that helps; let us know if you have further questions!

Regards,
     Neil





^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2008-04-09 20:16 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-05 17:24 set-current-module in .guile ? Scott N. Walck
2008-04-05 21:00 ` Jon Wilson
2008-04-06  0:01   ` Walck, Scott
2008-04-06 14:58     ` Ludovic Courtès
2008-04-07  1:27       ` Walck, Scott
2008-04-07  7:16         ` Ludovic Courtès
2008-04-07 11:27           ` Walck, Scott
2008-04-07 13:38             ` Ludovic Courtès
2008-04-07 15:07               ` Scott N. Walck
2008-04-08 13:40                 ` Ludovic Courtès
2008-04-08 15:41                   ` Scott N. Walck
2008-04-09 15:05                 ` Ludovic Courtès
2008-04-09 15:24                   ` Walck, Scott
2008-04-09 20:16 ` Neil Jerram

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).