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

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