Re: Guile, C++, and Mac OS X 10.4 (powerpc)

2010-08-18 Thread Ludovic Courtès
Hi,

Hans Aberg  writes:

> On 28 Jul 2010, at 21:49, Mike Solomon wrote:
>
>> Hey guile users,
>>Trying to compile the simple example bessel.c from
>> Writing-Guile-Extensions.html (renamed bessel.cc because I'm using
>> g+
>> +), I
>> encountered the following error:
>>
>> bessel.cc: In function 'void init_bessel()':
>> bessel.cc:13: error: invalid conversion from 'scm_unused_struct*
>> (*)(scm_unused_struct*)' to 'scm_unused_struct* (*)(...)'
>> bessel.cc:13: error:   initializing argument 5 of 'scm_unused_struct*
>> scm_c_define_gsubr(const char*, int, int, int, scm_unused_struct*
>> (*)
>> (...))'
>
> The SCM type is a pointer to an undefined C type - C hack, which
> clashes with C++. Clever in C, but bad for C++ users.

I don’t think that this is the cause of the problem.

The problem instead stems from use of function declarators with empty
parenthesis, which is also an obsolescent C feature, as discussed here:

  http://savannah.gnu.org/bugs/?23681

I fixed a few of these in Guile 1.9, but not all of them, and not
‘scm_c_define_gsubr’ in particular.

I would appreciate patches in this area.  :-)

Thanks,
Ludo’.




Re: make-module question.

2010-08-18 Thread Ludovic Courtès
Hi!

Ian Hulin  writes:

> (make-module) doesn't seem to appear in the documentation,  Is it
> supported, discouraged or deprecated?

It is undocumented but safe to use.

> Is there a supported scm_make_module  we can use in the Guile API, and
> if not, is it safe to use
>
> SCM scm_make_module_x = SCM_EOL;
> scm_permanent_object (scm_c_lookup ("make-module"));
>  and then do
> scm_call_0( SCM_VARIABLE_REF (scm_make_module_x)):
> ?

Yes, you can do this.  You could also write Scheme code instead.  ;-)

> Also what are the args the REPL says you can supply to (make-module) ?.

‘make-module’ takes one optional argument, which is the expected number
of bindings in the module (it’s a hint so that the underlying hash table
has the right size from the start.)

Thanks,
Ludo’.




Re: Latest guile 1.9 segfault in GC

2010-08-18 Thread Ludovic Courtès
Hi!

Cedric Cellier  writes:

> I do not understand how this GC works, but find it strange that this global
> variable is changed like this, especially since the libgc gc.h reads :
> "GC_all_interior_pointers (...) May not be changed after GC initialization."

‘scm_storage_prehistory’ does that in the right order:

  void
  scm_storage_prehistory ()
  {
GC_all_interior_pointers = 0;
GC_set_free_space_divisor (scm_getenv_int ("GC_FREE_SPACE_DIVISOR", 3));

GC_INIT ();

> How come the libgc GC_init function was already called when
> scm_storage_prehistory is called ? Apparently, the libgc overload
> pthread_create with its GC_pthread_create().
>
> So, guile must be inited before starting any thread.
>
> Let's try...
>
> OK, it works.

Cool.  :-)

Thanks,
Ludo




Re: Latest guile 1.9 segfault in GC

2010-08-18 Thread Ludovic Courtès
Hi,

Cedric Cellier  writes:

> But finaly, thanks to libgc's debug message, I got it.
> Actually, libgc overwrite pthread_create (and pthread_sigmask,
> and a few more) to know when a new thread is started.
> But this overloading is done "softly", ie. by a define in a
> C header file.

[...]

> So, in conclusion : always include libguile.h in the compilation
> units calling pthread functions.

That’s not entirely true, see Section “Thread Support” at
:

  All  implementations must intercept  thread creation  and a  few other
  thread-specific calls to allow  enumeration of threads and location of
  thread stacks.  This is current  accomplished with # define's  in gc.h
  (really gc_pthread_redirects.h), or  optionally by using ld's function
  call wrapping mechanism under Linux.

Indeed, here’s what I have on GNU/Linux:

  $ objdump -T ~/soft/lib/libgc.so|grep pthread_create
  0001ef80 gDF .text  028e  Base
GC_pthread_create
    DF *UND*    GLIBC_2.2.5 pthread_create

What OS do you use?

Thanks,
Ludo’.




Re: problem building guile-reader

2010-08-18 Thread Ludovic Courtès
Hello,

(Please follow-up to ‘guile-reader-de...@nongnu.org’.  Sorry for the
late reply, I had been sunbathing over the last few weeks.  ;-))

What does ‘gcc --version’ say?

Can you please print the value of ‘items’ in ‘parse-snarfed-line’ in
modules/system/documentation/c-snarf.scm?

Thanks in advance,
Ludo’.



Re: Guile, C++, and Mac OS X 10.4 (powerpc)

2010-08-18 Thread Hans Aberg

On 18 Aug 2010, at 15:49, Ludovic Courtès wrote:


Hey guile users,
  Trying to compile the simple example bessel.c from
Writing-Guile-Extensions.html (renamed bessel.cc because I'm using
g+
+), I
encountered the following error:

bessel.cc: In function 'void init_bessel()':
bessel.cc:13: error: invalid conversion from 'scm_unused_struct*
(*)(scm_unused_struct*)' to 'scm_unused_struct* (*)(...)'
bessel.cc:13: error:   initializing argument 5 of  
'scm_unused_struct*

scm_c_define_gsubr(const char*, int, int, int, scm_unused_struct*
(*)
(...))'


The SCM type is a pointer to an undefined C type - C hack, which
clashes with C++. Clever in C, but bad for C++ users.


I don’t think that this is the cause of the problem.

The problem instead stems from use of function declarators with empty
parenthesis, which is also an obsolescent C feature, as discussed  
here:


 http://savannah.gnu.org/bugs/?23681

I fixed a few of these in Guile 1.9, but not all of them, and not
‘scm_c_define_gsubr’ in particular.

I would appreciate patches in this area.  :-)


I got those when doing a templates in a C++ wrap, and just assumed it  
had something to do with that SCM was a pointer.





Re: Guile for Game Scripting

2010-08-18 Thread Andy Wingo
Hi Luiji,

No Itisnt has already mentioned that Guile will support Lua, but I don't
think there's a problem with using the canonical implementation of Lua,
no. Basically the thing is, use what you want, but GNU suggests Guile;
and in the near future Guile will have decent support for a couple other
languages, Lua included.

On Fri 23 Jul 2010 20:34, Luiji Maryo  writes:

> - If I use Lua as a scripting format, would it be bad to use Guile for
> a markup language?  Or would it be better to implement a short,
> 50-line SEXP parser.

But I'm responding to you over this paragraph. It's not about parsing,
it's about (eventually) turning your application inside-out. See

  
http://hydra.nixos.org/build/565540/download/2/guile.html/Programming-Overview.html#Programming-Overview

for a discussion.

Happy hacking,

Andy
-- 
http://wingolog.org/



Re: Guile and Atom or XMPP

2010-08-18 Thread Andy Wingo
On Tue 27 Jul 2010 16:26, Mike Gran  writes:

> Are there libraries about that would allow Guile to interact with the Atom 
> Syndication Format and with XMPP.  Google reveals nothing, as far as I
> can tell.

It's not a parser, but for emitting atom it's easy enough to do it in
straight-up sxml. Tekuti has an example at the end of tekuti/page.scm
and related helpers there; see http://gitorious.org/tekuti.

Cheers,

Andy
-- 
http://wingolog.org/



Re: Plotting in Guile

2010-08-18 Thread Andy Wingo
Hi Joel,

On Wed 28 Jul 2010 08:21, Joel James Adamson  writes:

> I am using Guile to iterate equations and produce trajectories from
> those iterations.  My current strategy is to redirect the stdout to a
> file and then use GNUPLOT to plot the trajectories as parametric
> plots.  However, I would like to contain everything within one program,
> to keep Makefiles simple and (ideally) only deal with one programming
> language for the project.
>
> Any suggestions on how to accomplish this?

Plotutils is going to be better, but there is also the possibility of
generating the plots directly, via cairo.

  http://wingolog.org/software/guile-charting/

Grab it from git, if you want it to work with the 1.9 series.

Andy
-- 
http://wingolog.org/



Re: thread safe functions

2010-08-18 Thread Andy Wingo
Hi Cedric,

On Thu 05 Aug 2010 04:27, Cedric Cellier  writes:

> Is there somewhere a list of guile functions that are (/are not) thread
> safe ?
>
> I ask since this morning I was after a strange bug because I was using
> the format module in two different thread, then learnt that these
> functions are not reentrant. I'm also interrested in the thread-safeness
> of gc-stats function.

>From "Multi-Threading" in the manual:

   All libguile functions are (intended to be) robust in the face of
multiple threads using them concurrently.  This means that there is no
risk of the internal data structures of libguile becoming corrupted in
such a way that the process crashes.

   A program might still produce nonsensical results, though.  Taking
hashtables as an example, Guile guarantees that you can use them from
multiple threads concurrently and a hashtable will always remain a valid
hashtable and Guile will not crash when you access it.  It does not
guarantee, however, that inserting into it concurrently from two threads
will give useful results: only one insertion might actually happen, none
might happen, or the table might in general be modified in a totally
arbitrary manner.  (It will still be a valid hashtable, but not the one
that you might have expected.)  Guile might also signal an error when it
detects a harmful race condition.

   Thus, you need to put in additional synchronizations when multiple
threads want to use a single hashtable, or any other mutable Scheme
object.

If you see any problem in libguile regarding threads, you should
certainly report it to bug-gu...@gnu.org (no subscription required).

The same goes for Scheme code. If you have found something in `format'
that is not thread-safe, do let us know.

Thanks,

Andy
-- 
http://wingolog.org/



Re: Data Dictionary and Configuration Files with Guile Scheme

2010-08-18 Thread Andy Wingo
On Thu 05 Aug 2010 10:15, Romel Sandoval  writes:

> I'm trying to create a data dictionary [1] to generate code from it.
[...]
> This way I can write s-exp as in the example *projects-table* an after a
> load I will have the data structure ready to work with it.

I think you are quite confused :) Use procedures, not macros. If you
really want to use s-expressions, use alists and define accessor
procedures, and be sure not to mutate literal values. You could use hash
tables and records also. Or myriad other data structures. Read
http://mitpress.mit.edu/sicp/, especially the chapters on data
abstraction and state.

But above all, don't take your data structure advice from anyone who
mentions SQL :)

Andy
-- 
http://wingolog.org/



Re: My Project: Guile Hypertext Preprocessor

2010-08-18 Thread Andy Wingo
Hi,

On Wed 11 Aug 2010 17:12, Luiji Maryo  writes:

> When looking through http://www.gnu.org/software/guile/ideas.html, I
> came across this nifty little idea for a PHP-like hypertext
> preprocessor that works with Guile.

I was recently pointed to http://woozle.org/~neale/src/eguile/. What do
you think about it?

Andy
-- 
http://wingolog.org/



Re: Latest guile 1.9 segfault in GC

2010-08-18 Thread Andy Wingo
Hi Cedric,

On Tue 17 Aug 2010 07:08, Cedric Cellier  writes:

> As a side note, I find libguile 1.9 slower than libguile 1.8.7.
> I suppose, being an unstable version, it's compiled by default
> with many debug options on. Is there an easy way to configure it
> for fast execution, for benchmarking reason ?

Guile 1.9's interpreter is slower than 1.8's interpreter, but 1.9 has a
compiler, and compiled Scheme runs much faster than 1.8.

You're probably not hitting the compiler for some reason. I think that
scm_primitive_load doesn't support autocompilation, where it probably
should. Is that the function you're using to load your Scheme code?

To work around it for now, call `load' from scheme. I know it's ugly but
at least you get the speed that way. Use scm_primitive_eval (scm_list_2
(scm_from_locale_string ("load"), path)).

Andy
-- 
http://wingolog.org/



Re: Plotting in Guile

2010-08-18 Thread Joel James Adamson
Andy Wingo  writes:

> Hi Joel,
>
> On Wed 28 Jul 2010 08:21, Joel James Adamson  writes:
>
>> I am using Guile to iterate equations and produce trajectories from
>> those iterations.  My current strategy is to redirect the stdout to a
>> file and then use GNUPLOT to plot the trajectories as parametric
>> plots.  However, I would like to contain everything within one program,
>> to keep Makefiles simple and (ideally) only deal with one programming
>> language for the project.
>>
>> Any suggestions on how to accomplish this?
>
> Plotutils is going to be better, but there is also the possibility of
> generating the plots directly, via cairo.
>
>   http://wingolog.org/software/guile-charting/

This is what I was looking for.  I will check it out some more.

Joel

-- 
Joel J. Adamson
Servedio Lab
University of North Carolina at Chapel Hill

FSF Member #8164
http://www.unc.edu/~adamsonj


pgp3zZcjK3XZI.pgp
Description: PGP signature


Re: Data Dictionary and Configuration Files with Guile Scheme

2010-08-18 Thread Romel Sandoval
El mié, 18-08-2010 a las 09:05 -0700, Andy Wingo escribió:
> On Thu 05 Aug 2010 10:15, Romel Sandoval  writes:
> 
> > I'm trying to create a data dictionary [1] to generate code from it.
> [...]
> > This way I can write s-exp as in the example *projects-table* an after a
> > load I will have the data structure ready to work with it.
> 
> I think you are quite confused :) Use procedures, not macros. If you
> really want to use s-expressions, use alists and define accessor
> procedures, and be sure not to mutate literal values. You could use hash
> tables and records also. Or myriad other data structures. Read
> http://mitpress.mit.edu/sicp/, especially the chapters on data
> abstraction and state.

Now I see. Thanks.

> 
> But above all, don't take your data structure advice from anyone who
> mentions SQL :)

The problem it's that I haven't found any alternative to SQL :-( So I'm
trying to manage the problem.

SQL alternative?... Anyone?

Romel






Re: Data Dictionary and Configuration Files with Guile Scheme

2010-08-18 Thread Thien-Thi Nguyen
() Romel Sandoval 
() Thu, 05 Aug 2010 12:15:44 -0500

   What do you think?

I use Guile-PG (several modules) and a homegrown metainfo table
accessible via ‘(ttn-do zzz various-db) personal-pgtable-defs’ et al:
http://www.gnuvola.org/software/ttn-do/ttn-do.html.gz#zzz-various_002ddb

Here is ~/.pgtable-defs, omitting some parts:

  ;;; ~/.pgtable-defs --- database descriptions -*- scheme -*-
  
  ;; Keyword Expansions
  ;; --
  
  ((#:pk "PRIMARY KEY")
   (#:u  "UNIQUE")
   (#:nn "NOT NULL")
   (#:mf "MATCH FULL")
   (#:dc "ON DELETE CASCADE")
   (#:uc "ON UPDATE CASCADE")
   (#:r  "REFERENCES")
   (#:tz "WITH TIME ZONE"))
  
  ;; Database Table Definitions
  ;; --
  ;;
  ;; ((DB-1 (TABLE DEF ...) (TABLE DEF ...) ...)
  ;;  (DB-2 (TABLE DEF ...) (TABLE DEF ...) ...) ...)
  ;;
  ;; Some day `infer-defs' will be able to round-trip these...
  
  (("ttn"
  
("sw_maint"
 (vbool #:nn)
 (url  text #:nn)
 (mon  text #:nn)
 (name text #:pk)
 (orig text)
 (mtim timestamp[]))) ; 0: mon
  
   ("gnuvola"
  
("updbad"
 (time timestamp #:pk)
 (causetext)
 (errmsg   text))
  
("updok"
 (time timestamp #:pk)
 (wroteint4)
 (read int4)
 (rate float4)
 (totalint4)
 (speedup  float4))
  
("updfiles"
 (file text)
 (move char)
 (time timestamp #:r "updok" #:dc #:uc
  
  ;;; ~/.pgtable-defs ends here

This file consists of two forms.  The first is (hopefully)
self-explanatory.  The second describes two databases:

  db   tables
  ---  ---
  ttn  sw_maint
  gnuvola  updbad, updok, updfiles

Each table's columns are further described in a way that really ought to
be queryable from the backend, so that is a Code Enhancement Opportunity
for the Guile-PG reflection module alluded to by the "Some day" comment.

Although i think SQL is ugly (and thus concur in jest, i believe,
with Andy Wingo's admonition :-), Guile-PG makes it livable.  E.g.:
http://www.gnuvola.org/software/guile-pg/qcons-notes.txt

So, to answer your question: yes, sexps work fine as a Data Dictionary.



Re: make-module question.

2010-08-18 Thread Ian Hulin
Hi Ludo,
On 18/08/10 15:03, Ludovic � wrote:
> Hi!
> 
> Ian Hulin  writes:
> 
>> (make-module) doesn't seem to appear in the documentation,  Is it
>> supported, discouraged or deprecated?
> 
> It is undocumented but safe to use.
> 
>> Is there a supported scm_make_module  we can use in the Guile API, and
>> if not, is it safe to use
>>
>> SCM scm_make_module_x = SCM_EOL;
>> scm_permanent_object (scm_c_lookup ("make-module"));
>>  and then do
>> scm_call_0( SCM_VARIABLE_REF (scm_make_module_x)):
>> ?
> 
> Yes, you can do this.  You could also write Scheme code instead.  ;-)
> 
It's already in C++.
>> Also what are the args the REPL says you can supply to (make-module) ?.
> 
> ‘make-module’ takes one optional argument, which is the expected number
> of bindings in the module (it’s a hint so that the underlying hash table
> has the right size from the start.)
> 
Since posting this I managed to track down the V1.8.7 ice-9/boot-9.scm,
where this is declared.

It looks like there are three optional parameters, and the code is
trying to do a home-grown version of (ice-9 optargs) to default the
first parameter of missing to be 31, and then process two others, an
optional list of modules to be added to the new module's uses list and
an optional initialization thunk to be called.

It's as it it's trying to do
(define*-public (make-module (#:optional (size=31)
  #:optional (uses-list='()) #:optional (init-thunk='()))
...)


As the lilypond C++ routine immediately adds stuff to the uses list it
could be useful to call make-module with this parameter.
However, how do you call the thing while getting it to accept that you
don't want to pass it the first parameter and want to let it default the
value, but the first positional one you are passing is actually the
second actual one, as you don't have any list separators in Scheme like
in C++, or Pascal or whatever. So Scheme cannot distinguish between
(make-module ( my-obarray-size)) and (make-module ( my-uses-list))
whereas a language with list-element separators could make this clear
make-module ( my_obbaray_size, , );
and make-module ( , my_uses_list ,  );

I suppose I could try a bit more noodling around in the REPL.

Cheers,

Ian