我刚刚安装了 guile-lib-0.2.7.tar.gz,并检查安装后,发现了它 在 /usr/share/guile/site — 我认为这是正确的:
scheme@(guile-user)> (list (%library-dir) (%site-dir) (%global-site-dir) (%package-data-dir))
$1 = ("/usr/share/guile/3.0" "/usr/share/guile/site/3.0" "/usr/share/guile/site" "/usr/share/guile")
也就是说,以下面包屑解决了我的问题:
scheme@(guile-user)> (use-modules (guile-lib))
While compiling expression:
no code for module (guile-lib)
scheme@(guile-user)> (use-modules (math))
While compiling expression:
no code for module (math)
scheme@(guile-user)> (add-to-load-path "/usr/share/guile/site")
scheme@(guile-user)> (use-modules (math))
While compiling expression:
no code for module (math)
scheme@(guile-user)> (use-modules (primes.scm))
While compiling expression:
no code for module (primes.scm)
我接下来尝试了暴力破解:
scheme@(guile-user)> (primitive-load-path "/usr/share/guile/site/math/primes.scm")
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;; or pass the --no-auto-compile argument to disable.
;;; compiling /usr/share/guile/site/math/primes.scm
;;; compiled /home/hsmyers/.cache/guile/ccache/3.0-LE-8-4.2/usr/share/guile/site/math/primes.scm.go
scheme@(math primes)> (prime? 3)
$2 = #t
虽然这种方法有效,但这似乎不是正确的做法。
显然,我在这里做错了什么,但我(像往常一样)完全无能为力 至于哪里出了问题。我的问题是——我需要什么来修复之间的连接 Guile 和图书馆位置?
$> pwd
/home/al/experimentu/guile/guile_3.0.9/scripts
$> ls
guile-lib.scm
$> cat guile-lib.scm
(define-module (guile-lib)
#:export (fn_2)
#:export (fn_3)
#:export (fn_4))
(define (fn_2 x) (* 2 x))
(define (fn_3 x) (* 3 x))
(define (fn_4 x) (* 4 x))
$> guild compile guile-lib.scm -o /home/al/experimentu/guile/guile_3.0.9/scripts/guile-lib.scm.go
wrote `/home/al/experimentu/guile/guile_3.0.9/scripts/guile-lib.scm.go'
$> ls
guile-lib.scm guile-lib.scm.go
$> env GUILE_LOAD_PATH="/home/al/experimentu/guile/guile_3.0.9/scripts:..." guile --no-auto-compile
scheme@(guile-user)> (fn_2 12)
;;; <stdin>:1:1: warning: possibly unbound variable `fn_2'
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Unbound variable: fn_2
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> ,q
scheme@(guile-user)> (use-modules (guile-lib))
scheme@(guile-user)> (fn_2 12)
$1 = 24
scheme@(guile-user)> (fn_3 12)
$2 = 36
scheme@(guile-user)> (fn_4 12)
$3 = 48
scheme@(guile-user)>