unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Modules: first steps.
@ 2002-09-15 23:42 Han-Wen Nienhuys
  2002-09-18 20:41 ` Marius Vollmer
  0 siblings, 1 reply; 11+ messages in thread
From: Han-Wen Nienhuys @ 2002-09-15 23:42 UTC (permalink / raw)
  Cc: jantien


As an ouverture to the Grand Hacking  Branch of LilyPond, I'm
converting some of the internal variable systems in Lily to Scheme
anonymous modules.

Some questions:

 * Why set-current-module ?   I'd expect set-current-module!

 * How can I get a list of all the variables in a module (ok, I can
   figure that out by myself, but why is there no API entry for this?)

 * It would be nice if the C smob example also touched on module use.

 * I have in my code:

	void
	ly_init_guile ()
	{
	  SCM last_mod = scm_current_module ();
	  scm_set_current_module (scm_c_resolve_module ("lily"));

	  scm_c_use_module ("guile");

	  for (int i=scm_init_funcs_->size () ; i--;)
	    (scm_init_funcs_->elem (i)) ();

	  if (verbose_global_b)
	    progress_indication ("\n");


	  scm_primitive_load_path (scm_makfrom0str ("lily.scm"));

	  scm_set_current_module (last_mod);
	}

   The lily.scm file has 

      (use-modules (ice-9 regex))

   at the top.

   I get

	blauw:~/usr/src/savannah/lily/lilypond$ lilypond
	lstat(/home/hanwen/bin/usr) failed ...
	/home/hanwen/bin/usr: Onbekend bestand of map
	GNU LilyPond 1.7.0ERROR: no code for module (guile)

    How do I make the module that defines use-module available to the
    .scm file?

  * extern void scm_c_use_module (const char *name);.

    Why is there no scm_use_module (SCM)? For anonymous modules, the
    storing the name just to use it with scm_c_use_module seems silly,
    in particular if that function  has to recover the SCM module
    object from the name again.



-- 

Han-Wen Nienhuys   |   hanwen@cs.uu.nl   |   http://www.cs.uu.nl/~hanwen 


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


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

* Re: Modules: first steps.
  2002-09-15 23:42 Modules: first steps Han-Wen Nienhuys
@ 2002-09-18 20:41 ` Marius Vollmer
  2002-09-18 21:11   ` Tom Lord
                     ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Marius Vollmer @ 2002-09-18 20:41 UTC (permalink / raw)
  Cc: guile-devel, jantien

Han-Wen Nienhuys <hanwen@cs.uu.nl> writes:

>  * Why set-current-module ?   I'd expect set-current-module!

I can't really say.  I myself have grown a bit tired of the
bang-suffix, I have to say.

>  * How can I get a list of all the variables in a module (ok, I can
>    figure that out by myself, but why is there no API entry for this?)

The module system hasn't completely arrived yet.  (And it is moving
very slowly.)  Most of the things that aren't there have simply not
yet been done.  A lot of stuff is there, but has not been documented
yet since we are not sure if we want to keep it that way it is
currently done.

That being said, we should definitely proceed in small steps.  The big
module system overhaul is not going to happen, as far as I can see.

That being said, there is 'module-for-each' and 'module-map'.  We
should probably just document them and make them official.


>  * It would be nice if the C smob example also touched on module use.

There is "examples/box-module".  Is that what you are looking for, or
something else?

>  * I have in my code:

Here is something similar that does work for me:

    #include <libguile.h>

    void
    ly_init_lily_module (void *unused)
    {
    #if 0
      for (int i=scm_init_funcs_->size () ; i--;)
        (scm_init_funcs_->elem (i)) ();

      if (verbose_global_b)
        progress_indication ("\n");
    #endif

      scm_primitive_load_path (scm_makfrom0str ("lily.scm"));
    }

    void
    ly_init_guile ()
    {
      scm_c_define_module ("lily", ly_init_lily_module, NULL);
    }

    int
    main (int argc, char **argv)
    {
      scm_init_guile ();
      ly_init_guile ();
    }

The reason that you version didn't work is that when
scm_c_resolve_module (and 'resolve-module') can't find the requested
module, it returns a fresh, empty one.  It is _totally_ empty, which
means that things like 'use-modules' aren't available.  Since you want
to define a new module, you should use scm_c_define_module.  It will
do all the right things.

>   * extern void scm_c_use_module (const char *name);.
> 
>     Why is there no scm_use_module (SCM)? For anonymous modules, the
>     storing the name just to use it with scm_c_use_module seems silly,
>     in particular if that function  has to recover the SCM module
>     object from the name again.

Agreed.  We should have that as well.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


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

* Re: Modules: first steps.
  2002-09-18 20:41 ` Marius Vollmer
@ 2002-09-18 21:11   ` Tom Lord
  2002-09-19  0:18   ` Han-Wen Nienhuys
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 11+ messages in thread
From: Tom Lord @ 2002-09-18 21:11 UTC (permalink / raw)




       >>  * Why set-current-module ?   I'd expect set-current-module!

       > I can't really say.  I myself have grown a bit tired of the
       > bang-suffix, I have to say.

The bang suffix ideally means: "modifies the first argument as the
primary and intended effect", so it doesn't really apply to
set-current-module.


-t


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


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

* Re: Modules: first steps.
  2002-09-18 20:41 ` Marius Vollmer
  2002-09-18 21:11   ` Tom Lord
@ 2002-09-19  0:18   ` Han-Wen Nienhuys
  2002-09-21 21:02     ` Marius Vollmer
  2002-09-19 20:31   ` Han-Wen Nienhuys
  2002-09-19 20:38   ` Han-Wen Nienhuys
  3 siblings, 1 reply; 11+ messages in thread
From: Han-Wen Nienhuys @ 2002-09-19  0:18 UTC (permalink / raw)
  Cc: guile-devel, jantien

mvo@zagadka.ping.de writes:
> >  * It would be nice if the C smob example also touched on module use.
> 
> There is "examples/box-module".  Is that what you are looking for, or
> something else?

It would be nice if this was referred to in the documentation. I
accidentally stumbled upon it yesterday.

> >  * I have in my code:

> The reason that you version didn't work is that when
> scm_c_resolve_module (and 'resolve-module') can't find the requested
> module, it returns a fresh, empty one.  It is _totally_ empty, which
> means that things like 'use-modules' aren't available.  Since you want
> to define a new module, you should use scm_c_define_module.  It will
> do all the right things.

OK. The difference wasn't clear to me at all, and I don't think the
distinction is there in the doco.

This means that if I do

	    SCM mod = scm_c_define_module (...)
	    scm_set_current_module (mod)
	    scm_c_define ("foo", ... );

then 'foo is defined in MOD? This is what I really need.
 



-- 

Han-Wen Nienhuys   |   hanwen@cs.uu.nl   |   http://www.cs.uu.nl/~hanwen 


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


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

* Re: Modules: first steps.
  2002-09-18 20:41 ` Marius Vollmer
  2002-09-18 21:11   ` Tom Lord
  2002-09-19  0:18   ` Han-Wen Nienhuys
@ 2002-09-19 20:31   ` Han-Wen Nienhuys
  2002-09-19 20:33     ` Rob Browning
  2002-09-20 14:21     ` Martin Grabmueller
  2002-09-19 20:38   ` Han-Wen Nienhuys
  3 siblings, 2 replies; 11+ messages in thread
From: Han-Wen Nienhuys @ 2002-09-19 20:31 UTC (permalink / raw)
  Cc: guile-devel, jantien

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=unknown, Size: 1141 bytes --]

mvo@zagadka.ping.de writes:
> 
> >  * It would be nice if the C smob example also touched on module use.
> 
> There is "examples/box-module".  Is that what you are looking for, or
> something else?

That doesn't inspire much confidence.

blauw:~/usr/src/guile-1.6.0/examples/box-module$ rm box
blauw:~/usr/src/guile-1.6.0/examples/box-module$ rm box.o
blauw:~/usr/src/guile-1.6.0/examples/box-module$   make box
gcc `/home/hanwen/usr/pkg/guile-1.6//bin/guile-config compile` -c box.c 
gcc box.o `/home/hanwen/usr/pkg/guile-1.6//bin/guile-config link` -o box
blauw:~/usr/src/guile-1.6.0/examples/box-module$ ./box
guile> (use-modules (box))
<unnamed port>: In expression ELF```ab`P^[%/1€‹iso8859-15\x024h04:
<unnamed port>: Unbound variable: ELF```ab`P^[%/1€‹iso8859-15\x024h04
ABORT: (unbound-variable)

Type "(backtrace)" to get more information or "(debug)" to enter the debugger.
guile> 

-- 

Han-Wen Nienhuys   |   hanwen@cs.uu.nl   |   http://www.cs.uu.nl/~hanwen 


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


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

* Re: Modules: first steps.
  2002-09-19 20:31   ` Han-Wen Nienhuys
@ 2002-09-19 20:33     ` Rob Browning
  2002-09-20 14:21     ` Martin Grabmueller
  1 sibling, 0 replies; 11+ messages in thread
From: Rob Browning @ 2002-09-19 20:33 UTC (permalink / raw)
  Cc: Marius Vollmer, guile-devel, jantien

Han-Wen Nienhuys <hanwen@cs.uu.nl> writes:

> That doesn't inspire much confidence.
>
> blauw:~/usr/src/guile-1.6.0/examples/box-module$ rm box
> blauw:~/usr/src/guile-1.6.0/examples/box-module$ rm box.o
> blauw:~/usr/src/guile-1.6.0/examples/box-module$   make box
> gcc `/home/hanwen/usr/pkg/guile-1.6//bin/guile-config compile` -c box.c 
> gcc box.o `/home/hanwen/usr/pkg/guile-1.6//bin/guile-config link` -o box
> blauw:~/usr/src/guile-1.6.0/examples/box-module$ ./box
> guile> (use-modules (box))
> <unnamed port>: In expression ELF```ab`P^[%/1€‹iso8859-15\x024h04:
> <unnamed port>: Unbound variable: ELF```ab`P^[%/1€‹iso8859-15\x024h04
> ABORT: (unbound-variable)
>
> Type "(backtrace)" to get more information or "(debug)" to enter the debugger.
Hmm.  Where is guile installed and/or is your envt right (PATH,
LD_LIBRARY_PATH), etc.

-- 
Rob Browning
rlb @defaultvalue.org, @linuxdevel.com, and @debian.org
Previously @cs.utexas.edu
GPG=1C58 8B2C FB5E 3F64 EA5C  64AE 78FE E5FE F0CB A0AD


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


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

* Re: Modules: first steps.
  2002-09-18 20:41 ` Marius Vollmer
                     ` (2 preceding siblings ...)
  2002-09-19 20:31   ` Han-Wen Nienhuys
@ 2002-09-19 20:38   ` Han-Wen Nienhuys
  2002-09-21 21:07     ` Marius Vollmer
  3 siblings, 1 reply; 11+ messages in thread
From: Han-Wen Nienhuys @ 2002-09-19 20:38 UTC (permalink / raw)
  Cc: guile-devel, jantien

mvo@zagadka.ping.de writes:
> I can't really say.  I myself have grown a bit tired of the
> bang-suffix, I have to say.
> 
> >  * How can I get a list of all the variables in a module (ok, I can
> >    figure that out by myself, but why is there no API entry for this?)
> 
> The module system hasn't completely arrived yet.  (And it is moving
> very slowly.)  Most of the things that aren't there have simply not
> yet been done.  A lot of stuff is there, but has not been documented
> yet since we are not sure if we want to keep it that way it is
> currently done.
> 
> That being said, we should definitely proceed in small steps.  The big
> module system overhaul is not going to happen, as far as I can see.

ok. How about a scm_export() function?

SCM
scm_export (SCM module, SCM namelist)
{
  scm_call_2 (SCM_VARIABLE_REF (module_export_x_var),
	      module, names);
}

-- 

Han-Wen Nienhuys   |   hanwen@cs.uu.nl   |   http://www.cs.uu.nl/~hanwen 


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


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

* Re: Modules: first steps.
  2002-09-19 20:31   ` Han-Wen Nienhuys
  2002-09-19 20:33     ` Rob Browning
@ 2002-09-20 14:21     ` Martin Grabmueller
  2002-09-20 22:40       ` Han-Wen Nienhuys
  1 sibling, 1 reply; 11+ messages in thread
From: Martin Grabmueller @ 2002-09-20 14:21 UTC (permalink / raw)
  Cc: mvo, guile-devel, jantien

> From: Han-Wen Nienhuys <hanwen@cs.uu.nl>
> Date: Thu, 19 Sep 2002 22:31:15 +0200
> 
> That doesn't inspire much confidence.
> 
> blauw:~/usr/src/guile-1.6.0/examples/box-module$ rm box
> blauw:~/usr/src/guile-1.6.0/examples/box-module$ rm box.o
> blauw:~/usr/src/guile-1.6.0/examples/box-module$   make box
> gcc `/home/hanwen/usr/pkg/guile-1.6//bin/guile-config compile` -c box.c 
> gcc box.o `/home/hanwen/usr/pkg/guile-1.6//bin/guile-config link` -o box
> blauw:~/usr/src/guile-1.6.0/examples/box-module$ ./box
> guile> (use-modules (box))
> <unnamed port>: In expression ELF```ab`
> <unnamed port>: Unbound variable: ELF```ab`
> ABORT: (unbound-variable)
> 
> Type "(backtrace)" to get more information or "(debug)" to enter the debugger.
> guile> 

Let me quote the README file:

** Example Session

  $ ./box
  guile> (use-modules (box-module))
  guile> (define b (make-box))
  guile> b
  #<box #f>
  guile> (box-set! b '(list of values))
  guile> b
  #<box (list of values)>
  guile> (box-ref b)
  (list of values)
  guile> (quit)
  $

So the module is called (box-module), not (box).

Guile seems tries to load the file `box' if you try to load a module
with that name, and that file unfortunately is the executable just
started, and Guile of course does not know what to do with an ELF
header :)

'martin


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


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

* Re: Modules: first steps.
  2002-09-20 14:21     ` Martin Grabmueller
@ 2002-09-20 22:40       ` Han-Wen Nienhuys
  0 siblings, 0 replies; 11+ messages in thread
From: Han-Wen Nienhuys @ 2002-09-20 22:40 UTC (permalink / raw)
  Cc: mvo, guile-devel, jantien

mg@glug.org writes:
> > That doesn't inspire much confidence.

> So the module is called (box-module), not (box).
> 
> Guile seems tries to load the file `box' if you try to load a module
> with that name, and that file unfortunately is the executable just
> started, and Guile of course does not know what to do with an ELF
> header :)

Errmmm. Cough :-)

Anyway, it works....



	blauw:~/usr/src/lilypond$ cat e.ly
	foo= \notes { c4 }
	#(display foo)

	\score { 
	  \context Voice \notes\relative c { c4 }
	  \paper {
	      bla = #(begin (display "hallo\n") "hoi\n")
	      baz = #(display bla)
	  }  
	}



	blauw:~/usr/src/lilypond$ lilypond e
	GNU LilyPond 1.7.0
	Now processing: `e.ly'
	Parsing...#<Music Sequential_musicorigin = #<location e.ly:0:18>
	elements = (#<Music Request_chordorigin = #<location e.ly:0:15>
	elements = (#<Music Note_reqorigin = #<location e.ly:0:15>
	duration = #<Duration 4 >
	pitch = #<Pitch c >
	type = request
	>)
	iterator-ctor = #<primitive-procedure Request_chord_iterator::constructor>
	>)
	iterator-ctor = #<primitive-procedure Sequential_music_iterator::constructor>
	>hallo
	hoi

	Interpreting music...[1]
	Preprocessing elements... 
	Calculating column positions... [2]
	paper output to `e.tex'...




-- 

Han-Wen Nienhuys   |   hanwen@cs.uu.nl   |   http://www.cs.uu.nl/~hanwen 


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


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

* Re: Modules: first steps.
  2002-09-19  0:18   ` Han-Wen Nienhuys
@ 2002-09-21 21:02     ` Marius Vollmer
  0 siblings, 0 replies; 11+ messages in thread
From: Marius Vollmer @ 2002-09-21 21:02 UTC (permalink / raw)
  Cc: guile-devel, jantien

Han-Wen Nienhuys <hanwen@cs.uu.nl> writes:

> mvo@zagadka.ping.de writes:
> > >  * It would be nice if the C smob example also touched on module use.
> > 
> > There is "examples/box-module".  Is that what you are looking for, or
> > something else?
> 
> It would be nice if this was referred to in the documentation. I
> accidentally stumbled upon it yesterday.

I'll add it.

> > The reason that you version didn't work is that when
> > scm_c_resolve_module (and 'resolve-module') can't find the
> > requested module, it returns a fresh, empty one.  It is _totally_
> > empty, which means that things like 'use-modules' aren't
> > available.  Since you want to define a new module, you should use
> > scm_c_define_module.  It will do all the right things.
> 
> OK. The difference wasn't clear to me at all, and I don't think the
> distinction is there in the doco.

I'd say it's suboptimal behavior of scm_c_resolve_module to construct
an empty, mostly useless module when it can't find the real one.  It
should probably just signal an error.

> This means that if I do
> 
> 	    SCM mod = scm_c_define_module (...)
> 	    scm_set_current_module (mod)
> 	    scm_c_define ("foo", ... );
> 
> then 'foo is defined in MOD?

Yes.

Depending on how your code is structured, it might be cleaner to use
scm_c_module_define.  That avoids messing with the current module.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


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

* Re: Modules: first steps.
  2002-09-19 20:38   ` Han-Wen Nienhuys
@ 2002-09-21 21:07     ` Marius Vollmer
  0 siblings, 0 replies; 11+ messages in thread
From: Marius Vollmer @ 2002-09-21 21:07 UTC (permalink / raw)
  Cc: guile-devel, jantien

Han-Wen Nienhuys <hanwen@cs.uu.nl> writes:

> ok. How about a scm_export() function?

Very good.  Please make it so that scm_c_export calls scm_export with
the constructed name list.  Thanks!

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


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

end of thread, other threads:[~2002-09-21 21:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-15 23:42 Modules: first steps Han-Wen Nienhuys
2002-09-18 20:41 ` Marius Vollmer
2002-09-18 21:11   ` Tom Lord
2002-09-19  0:18   ` Han-Wen Nienhuys
2002-09-21 21:02     ` Marius Vollmer
2002-09-19 20:31   ` Han-Wen Nienhuys
2002-09-19 20:33     ` Rob Browning
2002-09-20 14:21     ` Martin Grabmueller
2002-09-20 22:40       ` Han-Wen Nienhuys
2002-09-19 20:38   ` Han-Wen Nienhuys
2002-09-21 21:07     ` Marius Vollmer

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).