unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* [TIP] Using (@@ module-name binding-name) sometimes might result in "unbound variable"
@ 2023-09-12  8:24 Rodrigo Morales
  2023-09-12  8:34 ` Rodrigo Morales
  2023-09-13  8:10 ` Simon Tournier
  0 siblings, 2 replies; 4+ messages in thread
From: Rodrigo Morales @ 2023-09-12  8:24 UTC (permalink / raw)
  To: help-guix

TL; DR: Today, I wanted to make some experiments with a function,
which is not exported, from a module. I used "@@", but I still got an
error. I spent a significant amount of time trying to solve
this. Someone helped me out. I now want to share this with other Guix
users.

I used @@ as stated in the Guile manual [1], but I kept getting the error
"unbound variable" (please see below).

#+BEGIN_SRC scheme
(@@ (gnu home services fontutils) config->sxml)
#+END_SRC

#+RESULTS:
#+begin_example
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
error: config->sxml: unbound variable

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
#+end_example

Someone at #guile helped me out.

#+BEGIN_SRC scheme
(reload-module (resolve-module '(gnu home services fontutils)))
#+END_SRC

#+BEGIN_EXAMPLE
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /run/current-system/profile/share/guile/site/3.0/gnu/home/services/fontutils.scm
;;; compiled /home/rdrg/.cache/guile/ccache/3.0-LE-8-4.6/gnu/store/4dc7z9a5is1lv0v2ib9lpc6nvxlqv9gc-guix-1.4.0-10.4dfdd82/share/guile/site/3.0/gnu/home/services/fontutils.scm.go
$5 = #<directory (gnu home services fontutils) 7f763a259e60>
#+END_EXAMPLE

#+BEGIN_SRC scheme
(@@ (gnu home services fontutils) config->sxml)
#+END_SRC

#+RESULTS:
#+BEGIN_EXAMPLE
$6 = #<procedure config->sxml (config)>
#+END_EXAMPLE

Problem fixed.

From what I can see in the messages shown by =reload-module=, this
problem was caused because Guile was using a cached version which
didn't define "config->sxml" (please correct me if I'm wrong).

Would it be possible to mention this possible scenario and the fact
that it can be solved by using =reload-module= in the documentation of
=@@= at the Info manual [1]?  I believe there might be other curious
Guix users, like me, who want to call some non-exported functions, and
might encounter the exact same problem.

Perhaps, adding the following

#+BEGIN_QUOTE
Sometimes it might be necessary to revisit the source file by using
(reload-module (resolve-module module-name)) to make sure that
all functions are available.
#+END_QUOTE

as it follows:

#+BEGIN_QUOTE
syntax: @@ module-name binding-name

    Refer to the binding named binding-name in module module-name. The
    binding must not have been exported by the module. This syntax is
    only intended for debugging purposes or as a last
    resort. Sometimes it might be necessary to revisit the source file
    by using (reload-module (resolve-module module-name)) to make sure
    that all functions are available. See Declarative Modules, for
    some limitations on the use of @@.
#+END_QUOTE

[1] https://www.gnu.org/software/guile/manual/html_node/Using-Guile-Modules.html#index-_0040_0040


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

end of thread, other threads:[~2023-09-14  1:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-12  8:24 [TIP] Using (@@ module-name binding-name) sometimes might result in "unbound variable" Rodrigo Morales
2023-09-12  8:34 ` Rodrigo Morales
2023-09-13  8:10 ` Simon Tournier
2023-09-14  0:54   ` Rodrigo Morales

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