unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* library vs define-module issue
@ 2020-08-01 12:01 Zelphir Kaltstahl
  2020-08-01 13:40 ` John Cowan
  0 siblings, 1 reply; 3+ messages in thread
From: Zelphir Kaltstahl @ 2020-08-01 12:01 UTC (permalink / raw)
  To: Guile User

Hello Guile Users!

I've hit an issue, when trying to make use of (library ...) [1] instead
of (define-module ...) [2].

The file structure is as follows:

~~~~
.
├── example.scm
├── geometry-define-module.scm
└── geometry.scm
~~~~

When I define my module as follows, in geometry-define-module.scm, it works:

~~~~
(define-module (geometry-define-module)
  #:export (point
            make-point
            get-point-label
            get-point-coords))


(use-modules
 (srfi srfi-9)
 (srfi srfi-9 gnu))


(define-immutable-record-type <point>
  ;; define constructor
  (point label coords)
  ;; define predicate
  point?
  ;; define accessors and functional setters
  (label get-point-label set-point-label)
  (coords get-point-coords set-point-coords))


(define make-point
  (lambda* (coords #:key (label #f))
    (cond
     [label
      (point label coords)]
     [else
      (point 'unlabeled coords)])))
~~~~

I can import it in example.scm as follows (no errors):

~~~~
(use-modules (geometry-define-module))
~~~~

But when I define my module using library as follows:

~~~~
(library (geometry (0 0 1))
  (export point
          make-point
          get-point-label
          get-point-coords
          )
  (import
    ;; structs
    (srfi srfi-9)
    (srfi srfi-9 gnu)
    ;; hash table
    #;(srfi srfi-69)))


(define-immutable-record-type <point>
  ;; define constructor
  (point label coords)
  ;; define predicate
  point?
  ;; define accessors and functional setters
  (label get-point-label set-point-label)
  (coords get-point-coords set-point-coords))


(define make-point
  (lambda* (coords #:key (label #f))
    (cond
     [label
      (point label coords)]
     [else
      (point 'unlabeled coords)])))
~~~~

I cannot import it, or rather there are errors:

~~~~
(import (geometry))
~~~~

Calling Guile as follows:

~~~~
guile -L . --fresh-auto-compile example.scm
~~~~

The error is:

~~~~
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/xiaolong/dev/Guile/algorithm-examples/basics/example.scm
;;; compiling ./geometry.scm
;;; geometry.scm:25:0: warning: possibly unbound variable `define'
;;; geometry.scm:26:2: warning: possibly unbound variable `lambda*'
;;; geometry.scm:26:11: warning: possibly unbound variable `coords'
;;; geometry.scm:26:25: warning: possibly unbound variable `label'
;;; geometry.scm:27:4: warning: possibly unbound variable `cond'
;;; geometry.scm:28:5: warning: possibly unbound variable `label'
;;; geometry.scm:29:6: warning: possibly unbound variable `label'
;;; geometry.scm:29:6: warning: possibly unbound variable `coords'
;;; geometry.scm:30:5: warning: possibly unbound variable `else'
;;; geometry.scm:31:13: warning: possibly unbound variable `quote'
;;; geometry.scm:31:13: warning: possibly unbound variable `unlabeled'
;;; geometry.scm:31:6: warning: possibly unbound variable `coords'
;;; compiled /home/xiaolong/.cache/guile/ccache/3.0-LE-8-4.3/home/xiaolong/dev/Guile/algorithm-examples/basics/geometry.scm.go
;;; WARNING: compilation of /home/xiaolong/dev/Guile/algorithm-examples/basics/example.scm failed:
;;; Unbound variable: define
~~~~

What am I doing wrong? Why is everything unbound, even core forms like
define or cond? Perhaps I need to import some base thing when using
(library …)?

Best regards,
Zelphir

[1]: https://www.gnu.org/software/guile/manual/html_node/R6RS-Libraries.html

[2]:
https://www.gnu.org/software/guile/manual/html_node/Creating-Guile-Modules.html

-- 
repositories: https://notabug.org/ZelphirKaltstahl



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

* Re: library vs define-module issue
  2020-08-01 12:01 library vs define-module issue Zelphir Kaltstahl
@ 2020-08-01 13:40 ` John Cowan
  2020-08-01 14:46   ` Zelphir Kaltstahl
  0 siblings, 1 reply; 3+ messages in thread
From: John Cowan @ 2020-08-01 13:40 UTC (permalink / raw)
  To: Zelphir Kaltstahl; +Cc: Guile User

On Sat, Aug 1, 2020 at 8:02 AM Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
wrote:


> ;;; geometry.scm:25:0: warning: possibly unbound variable `define'
> ;;; geometry.scm:26:2: warning: possibly unbound variable `lambda*'
>
> What am I doing wrong? Why is everything unbound, even core forms like
> define or cond? Perhaps I need to import some base thing when using
> (library …)?
>

Exactly.  You have to import (rnrs base) or else (guile), because the
global environment is empty at the start of an R[67]RS library definition.
This is deliberate so that you can choose an entirely different base
library if you wish.  Similarly, Chicken provides both (scheme base) and
(chicken base), and Chibi provides both (scheme base) and (chibi), although
(chibi) is smaller than (scheme base) rather than larger, in keeping with
Chibi's goals.

As a matter of style, I recommend importing the standard base library and
then bringing in anything Guile-specific with (import (only (guile) ...)).
This advice also applies to Chibi, but not so much to Chicken unless you
are specifically using the R7RS mode.



John Cowan          http://vrici.lojban.org/~cowan        cowan@ccil.org
Is not a patron, my Lord [Chesterfield], one who looks with unconcern
on a man struggling for life in the water, and when he has reached ground
encumbers him with help?        --Samuel Johnson


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

* Re: library vs define-module issue
  2020-08-01 13:40 ` John Cowan
@ 2020-08-01 14:46   ` Zelphir Kaltstahl
  0 siblings, 0 replies; 3+ messages in thread
From: Zelphir Kaltstahl @ 2020-08-01 14:46 UTC (permalink / raw)
  To: John Cowan; +Cc: Guile User

Thanks John! This solved the problem. I now have it like this:

~~~~START~~~~
(library (geometry (0 0 1))
  (export point
          make-point
          get-point-label
          get-point-coords
          vector->point)
  (import
    (rnrs base)
    (only (guile) lambda*)
    ;; structs
    (srfi srfi-9)
    (srfi srfi-9 gnu)
    ;; fold and list operations
    (srfi srfi-1)))

... (other code) ...
~~~~~END~~~~~

and I can import that just fine.

Are all forms, which are usually available when using (define-module
...) exported in the import set (guile)?

If not, where would I look for them?

Using (help identifier) inside geiser helps. It shows me for example:

~~~~START~~~~
scheme@(guile-user)> (help define)
No documentation found for:
(rnrs base): define
~~~~~END~~~~~

Which tells me what I would need to import when using (library ...).

Best regards,
Zelphir

On 01.08.20 15:40, John Cowan wrote:
>
>
> On Sat, Aug 1, 2020 at 8:02 AM Zelphir Kaltstahl
> <zelphirkaltstahl@posteo.de <mailto:zelphirkaltstahl@posteo.de>> wrote:
>  
>
>     ;;; geometry.scm:25:0: warning: possibly unbound variable `define'
>     ;;; geometry.scm:26:2: warning: possibly unbound variable `lambda*'
>
>     What am I doing wrong? Why is everything unbound, even core forms like
>     define or cond? Perhaps I need to import some base thing when using
>     (library …)?
>
>
> Exactly.  You have to import (rnrs base) or else (guile), because the
> global environment is empty at the start of an R[67]RS library
> definition.  This is deliberate so that you can choose an entirely
> different base library if you wish.  Similarly, Chicken provides both
> (scheme base) and (chicken base), and Chibi provides both (scheme
> base) and (chibi), although (chibi) is smaller than (scheme base)
> rather than larger, in keeping with Chibi's goals.
>
> As a matter of style, I recommend importing the standard base library
> and then bringing in anything Guile-specific with (import (only
> (guile) ...)).  This advice also applies to Chibi, but not so much to
> Chicken unless you are specifically using the R7RS mode.
>
>
>
> John Cowan          http://vrici.lojban.org/~cowan      
>  cowan@ccil.org <mailto:cowan@ccil.org>
> Is not a patron, my Lord [Chesterfield], one who looks with unconcern
> on a man struggling for life in the water, and when he has reached ground
> encumbers him with help?        --Samuel Johnson
>
-- 
repositories: https://notabug.org/ZelphirKaltstahl



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

end of thread, other threads:[~2020-08-01 14:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-01 12:01 library vs define-module issue Zelphir Kaltstahl
2020-08-01 13:40 ` John Cowan
2020-08-01 14:46   ` Zelphir Kaltstahl

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