guile-user
[Top][All Lists]
Advanced

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

Re: the module system ?


From: Martin Grabmueller
Subject: Re: the module system ?
Date: Tue, 6 Mar 2001 13:13:55 +0100 (MET)

> From: David Pirotte <address@hidden>
> Date: Tue, 06 Mar 2001 11:43:54 +0100
> 
> I am quite lost with respect to how the module system works. Here
> is what I thought would be correct:
> 
> 1] my module def and relative code:
> -----------------------------------
> 
> (define-module (tactus db-stuff)
> 
>   ;; from distribution
>   :use-module (database postgres)
>   :use-module (ice-9 format)
>   
>   ;; from alto
> 
>   )
> 
> (export ;; pg-con
>       open-db
>       close-db
>       ;; get-db-con-str
>       )
> 
> (setenv "PGDATESTYLE" "German")
> 
> (define (open-db dbname user . options)
>   ;; (format #t "dbname=~A user=~A options=~S~%" dbname user options)
>   (if (null? options)
>       (pg-connectdb (format #f "dbname=~A user=~A" dbname user))
>       (pg-connectdb (format #f "dbname=~A user=~A ~A" dbname user options)))
>   )
> 
> (define (close-db . con?)
>   (set! pg-con '())
>   (if (not (null? con?))
>       (eval `(set! ,(car con?) '()))))

A question: What is it you are doing here?  The use of eval looks a
bit strange, you are passing a symbol to `close-db' which gets set to
'().  This will most probably result in an error if you are calling
the procedure from another module, because variables always belong to
the module where they are defined in.

> 
> 2] when I try to use it:
> ------------------------
> 
> address@hidden:~/alto/projects/guile 58 $ guile
> guile> (use-modules (tactus db-stuff))
> guile> (open-db "tactus" "david")
> /usr/alto/projects/guile/tactus/db-stuff.scm:26:7: In expression 
> (pg-connectdb (format #f "dbname=~A user=~A" ...)):
> /usr/alto/projects/guile/tactus/db-stuff.scm:26:7: Unbound variable: 
> pg-connectdb
> ABORT: (unbound-variable)
> 
> Type "(backtrace)" to get more information or "(debug)" to enter the debugger.
> guile> 

You have to make sure that the variable `pg-connectdb' is exported
from the module where it is define (I assume it is (database
postgres)).

> 3] so, I hope we do not have to always have to know and load the modules 
> required
> by the modules we want to use ...

No, but you have to know which variables are exported, if you want to
use them from another module.
 
> What is it that I don't understand?
> many thanks for some hints

I hope that helps, please ask more specific questions if I have
misunderstood your mail.

Regards,
  'martin



reply via email to

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