guile-user
[Top][All Lists]
Advanced

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

library vs define-module issue


From: Zelphir Kaltstahl
Subject: library vs define-module issue
Date: Sat, 1 Aug 2020 14:01:41 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Icedove/68.8.0

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



reply via email to

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