* Re: Loading a module before and after adding a load path
[not found] ` <87ip6tx0yf.fsf@supernova.vialactea>
@ 2013-01-19 4:32 ` Noah Lavine
2013-01-20 18:34 ` Andy Wingo
0 siblings, 1 reply; 4+ messages in thread
From: Noah Lavine @ 2013-01-19 4:32 UTC (permalink / raw)
To: Diogo F. S. Ramos; +Cc: Guile Mailing List, guile-devel
[-- Attachment #1: Type: text/plain, Size: 3267 bytes --]
Hello,
I see what you are trying to do, and I agree that it should be possible. I
have set up the same situation as you: trying to load a module, failing,
adding it to my path, trying again, and failing again. Here's what I've
figured out:
- resolve-module fails on the module, when I think it should succeed.
that's because
- try-autoload-module fails on the module, when again I think it should
succeed. and that's because
- autoload-done-or-in-progress? returns #t for the module, when I think it
should return #f. specifically, the module is marked as done, and therefore
try-module-autoload won't look for it any more.
- the module was marked as autoloaded because that's what
try-module-autoload does: it *always* marks its module as autoloaded, even
if it wasn't found.
As a workaround, remove your module from the list "autoloads-done".
(actually, there will be a pair in that list, where the cdr of the pair is
the name of the module as a string. remove that.)
In the long term, Andy and Ludo, what is the right way to fix this? Should
try-module-autoload not mark unfound modules as autoloaded? Or maybe there
should be a special function that says "retry this module, starting from
the beginning". Maybe it could even be part of reload-module.
Best,
Noah
On Fri, Jan 18, 2013 at 11:15 PM, Diogo F. S. Ramos <diogofsr@gmail.com>wrote:
> Nala Ginrut <nalaginrut@gmail.com> writes:
>
> > Why you need to load the module without giving its path?
>
> Sorry, I should have added some more context.
>
> While I'm working with the REPL, sometimes I forget to add the path to a
> module before trying to use it. It's a mistake. So, after trying to load
> the module with `use-modules', and failing, I remember that I have to
> add the path to the module. So I add the path to the module with
> `add-to-load-path' and I try again to evaluate
> `use-modules'. Unfortunately it does not load it and I'm stuck. To fix
> it, I end up restarting the REPL and adding the path _before_ trying to
> load it, as it's the right way to do it.
>
> Here is an example with my typical mistake:
>
> $ cat /tmp/foo/bar.scm
> (define-module (foo bar))
>
> (define-public (hello)
> (display "hello, world")
> (newline))
> $ guile
> GNU Guile 2.0.5-deb+1-1
> Copyright (C) 1995-2012 Free Software Foundation, Inc.
>
> Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
> This program is free software, and you are welcome to redistribute it
> under certain conditions; type `,show c' for details.
>
> Enter `,help' for help.
> scheme@(guile-user)> (use-modules (foo bar))
> While compiling expression:
> ERROR: no code for module (foo bar)
> scheme@(guile-user)> (add-to-load-path "/tmp")
> scheme@(guile-user)> (use-modules (foo bar))
> While compiling expression:
> ERROR: no code for module (foo bar)
> scheme@(guile-user)> (hello)
> ;;; <stdin>:4:0: warning: possibly unbound variable `hello'
> <unnamed port>:4:0: In procedure #<procedure e3f580 at <current input>:4:0
> ()>:
> <unnamed port>:4:0: In procedure module-lookup: Unbound variable: hello
>
> Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
> scheme@(guile-user) [1]>
>
> The question is: Is there a way to recover from this mistake in my live
> REPL session?
>
>
[-- Attachment #2: Type: text/html, Size: 4261 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Loading a module before and after adding a load path
2013-01-19 4:32 ` Loading a module before and after adding a load path Noah Lavine
@ 2013-01-20 18:34 ` Andy Wingo
2013-01-21 17:20 ` Ludovic Courtès
0 siblings, 1 reply; 4+ messages in thread
From: Andy Wingo @ 2013-01-20 18:34 UTC (permalink / raw)
To: Noah Lavine; +Cc: Guile Mailing List, guile-devel, Diogo F. S. Ramos
[-- Attachment #1: Type: text/plain, Size: 711 bytes --]
On Sat 19 Jan 2013 05:32, Noah Lavine <noah.b.lavine@gmail.com> writes:
> In the long term, Andy and Ludo, what is the right way to fix this?
This bug was introduced here:
commit 0fb81f95b0222c5ba49efd3e36cf797df54c0863
Author: Andy Wingo <wingo@pobox.com>
Date: Wed Jun 3 09:48:16 2009 +0200
add exception_on_error optional arg to primitive-load-path
Before, "didit" would be #f after a failed primitive-load-path, and
afterwards control proceeded to set it to #t.
Somehow we need to fix try-module-autoload to detect failure, which
seems to indicate that we should not be passing exception_on_error=#f to
primitive-load-path.
The following patch seems to fix it for me. WDYT?
Andy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-fix-try-module-autoload-which-did-not-detect-failure.patch --]
[-- Type: text/x-diff, Size: 7984 bytes --]
From 611e4d12abe5305b14ae24e4f135d5fc57ce0e9a Mon Sep 17 00:00:00 2001
From: Andy Wingo <wingo@pobox.com>
Date: Sun, 20 Jan 2013 19:33:42 +0100
Subject: [PATCH] fix try-module-autoload, which did not detect failure to
find the file
* libguile/load.c (scm_primitive_load_path): If the second argument is a
procedure, call it like a thunk.
* doc/ref/api-evaluation.texi (Load Paths): Update docs.
* module/ice-9/boot-9.scm (resolve-interface): Use `unless'.
(try-module-autoload): Use the new primitive-load-path to detect
failure to find an appropriate file. Fixes a bug reported by Diogo
F. S. Ramos. Thanks to Noah Lavine for tracking it down.
---
doc/ref/api-evaluation.texi | 17 ++++++++++-------
libguile/load.c | 22 +++++++++++++---------
module/ice-9/boot-9.scm | 29 +++++++++++++++++++++--------
3 files changed, 44 insertions(+), 24 deletions(-)
diff --git a/doc/ref/api-evaluation.texi b/doc/ref/api-evaluation.texi
index 2e5a3d2..17f6ed5 100644
--- a/doc/ref/api-evaluation.texi
+++ b/doc/ref/api-evaluation.texi
@@ -1,6 +1,6 @@
@c -*-texinfo-*-
@c This is part of the GNU Guile Reference Manual.
-@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2010, 2011, 2012
+@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2010, 2011, 2012, 2013
@c Free Software Foundation, Inc.
@c See the file guile.texi for copying conditions.
@@ -881,12 +881,15 @@ relative pathname and is not found in the list of search paths,
an error is signalled. Preferentially loads a compiled version of the
file, if it is available and up-to-date.
-By default or if @var{exception-on-not-found} is true, an exception is
-raised if @var{filename} is not found. If @var{exception-on-not-found}
-is @code{#f} and @var{filename} is not found, no exception is raised and
-@code{#f} is returned. For compatibility with Guile 1.8 and earlier,
-the C function takes only one argument, which can be either a string
-(the file name) or an argument list.
+If @var{filename} is a relative pathname and is not found in the list of
+search paths, one of three things may happen, depending on the optional
+second argument, @var{exception-on-not-found}. If it is @code{#f},
+@code{#f} will be returned. If it is a procedure, it will be called
+with no arguments. Otherwise an error is signalled.
+
+For compatibility with Guile 1.8 and earlier, the C function takes only
+one argument, which can be either a string (the file name) or an
+argument list.
@end deffn
@deffn {Scheme Procedure} %search-load-path filename
diff --git a/libguile/load.c b/libguile/load.c
index 723f3fd..84b6705 100644
--- a/libguile/load.c
+++ b/libguile/load.c
@@ -1,5 +1,5 @@
/* Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2004, 2006, 2008,
- * 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+ * 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -846,11 +846,13 @@ canonical_suffix (SCM fname)
SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 0, 0, 1,
(SCM args),
"Search @var{%load-path} for the file named @var{filename} and\n"
- "load it into the top-level environment. If @var{filename} is a\n"
- "relative pathname and is not found in the list of search paths,\n"
- "an error is signalled, unless the optional argument\n"
- "@var{exception_on_not_found} is @code{#f}, in which case\n"
- "@code{#f} is returned instead.")
+ "load it into the top-level environment.\n\n"
+ "If @var{filename} is a relative pathname and is not found in\n"
+ "the list of search paths, one of three things may happen,\n"
+ "depending on the optional second argument,\n"
+ "@var{exception_on_not_found}. If it is @code{#f}, @code{#f}\n"
+ "will be returned. If it is a procedure, it will be called\n"
+ "with no arguments. Otherwise an error is signalled.")
#define FUNC_NAME s_scm_primitive_load_path
{
SCM filename, exception_on_not_found;
@@ -924,11 +926,13 @@ SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 0, 0, 1,
if (scm_is_false (full_filename) && scm_is_false (compiled_filename))
{
- if (scm_is_true (exception_on_not_found))
+ if (scm_is_true (scm_procedure_p (exception_on_not_found)))
+ return scm_call_0 (exception_on_not_found);
+ else if (scm_is_false (exception_on_not_found))
+ return SCM_BOOL_F;
+ else
SCM_MISC_ERROR ("Unable to find file ~S in load path",
scm_list_1 (filename));
- else
- return SCM_BOOL_F;
}
if (!scm_is_false (hook))
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index e426374..77bb84a 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -1,7 +1,7 @@
;;; -*- mode: scheme; coding: utf-8; -*-
;;;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-;;;; 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
+;;;; 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
;;;; Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
@@ -2593,8 +2593,8 @@ VALUE."
version)
(let* ((module (resolve-module name #t version #:ensure #f))
(public-i (and module (module-public-interface module))))
- (and (or (not module) (not public-i))
- (error "no code for module" name))
+ (unless public-i
+ (error "no code for module" name))
(if (and (not select) (null? hide) (eq? renamer identity))
public-i
(let ((selection (or select (module-map (lambda (sym var) sym)
@@ -2765,10 +2765,13 @@ module '(ice-9 q) '(make-q q-length))}."
(define autoloads-in-progress '())
-;; This function is called from "modules.c". If you change it, be
-;; sure to update "modules.c" as well.
-
+;; This function is called from scm_load_scheme_module in
+;; "deprecated.c". Please do not change its interface.
+;;
(define* (try-module-autoload module-name #:optional version)
+ "Try to load a module of the given name. If it is not found, return
+#f. Otherwise return #t. May raise an exception if a file is found,
+but it fails to load."
(let* ((reverse-name (reverse module-name))
(name (symbol->string (car reverse-name)))
(dir-hint-module-name (reverse (cdr reverse-name)))
@@ -2785,6 +2788,13 @@ module '(ice-9 q) '(make-q q-length))}."
(with-fluids ((current-reader #f))
(save-module-excursion
(lambda ()
+ (define (call/ec proc)
+ (let ((tag (make-prompt-tag)))
+ (call-with-prompt
+ tag
+ (lambda ()
+ (proc (lambda () (abort-to-prompt tag))))
+ (lambda (k) (values)))))
;; The initial environment when loading a module is a fresh
;; user module.
(set-current-module (make-fresh-user-module))
@@ -2794,8 +2804,11 @@ module '(ice-9 q) '(make-q q-length))}."
;; out how to locate the compiled file, do auto-compilation,
;; etc. Punt for now, and don't use versions when locating
;; the file.
- (primitive-load-path (in-vicinity dir-hint name) #f)
- (set! didit #t)))))
+ (call/ec
+ (lambda (abort)
+ (primitive-load-path (in-vicinity dir-hint name)
+ abort)
+ (set! didit #t)))))))
(lambda () (set-autoloaded! dir-hint name didit)))
didit))))
--
1.7.10.4
[-- Attachment #3: Type: text/plain, Size: 26 bytes --]
--
http://wingolog.org/
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: Loading a module before and after adding a load path
2013-01-20 18:34 ` Andy Wingo
@ 2013-01-21 17:20 ` Ludovic Courtès
2013-01-21 18:12 ` Andy Wingo
0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2013-01-21 17:20 UTC (permalink / raw)
To: guile-devel; +Cc: guile-user
Andy Wingo <wingo@pobox.com> skribis:
> On Sat 19 Jan 2013 05:32, Noah Lavine <noah.b.lavine@gmail.com> writes:
>
>> In the long term, Andy and Ludo, what is the right way to fix this?
>
> This bug was introduced here:
>
> commit 0fb81f95b0222c5ba49efd3e36cf797df54c0863
> Author: Andy Wingo <wingo@pobox.com>
> Date: Wed Jun 3 09:48:16 2009 +0200
>
> add exception_on_error optional arg to primitive-load-path
>
> Before, "didit" would be #f after a failed primitive-load-path, and
> afterwards control proceeded to set it to #t.
Good catch!
> From 611e4d12abe5305b14ae24e4f135d5fc57ce0e9a Mon Sep 17 00:00:00 2001
> From: Andy Wingo <wingo@pobox.com>
> Date: Sun, 20 Jan 2013 19:33:42 +0100
> Subject: [PATCH] fix try-module-autoload, which did not detect failure to
> find the file
>
> * libguile/load.c (scm_primitive_load_path): If the second argument is a
> procedure, call it like a thunk.
>
> * doc/ref/api-evaluation.texi (Load Paths): Update docs.
>
> * module/ice-9/boot-9.scm (resolve-interface): Use `unless'.
> (try-module-autoload): Use the new primitive-load-path to detect
> failure to find an appropriate file. Fixes a bug reported by Diogo
> F. S. Ramos. Thanks to Noah Lavine for tracking it down.
Looks good to me.
Thanks,
Luod’.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Loading a module before and after adding a load path
2013-01-21 17:20 ` Ludovic Courtès
@ 2013-01-21 18:12 ` Andy Wingo
0 siblings, 0 replies; 4+ messages in thread
From: Andy Wingo @ 2013-01-21 18:12 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-user, guile-devel
On Mon 21 Jan 2013 18:20, ludo@gnu.org (Ludovic Courtès) writes:
>> Subject: [PATCH] fix try-module-autoload, which did not detect failure to
>> find the file
>
> Looks good to me.
Pushed, thanks.
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-01-21 18:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <87bocmxzax.fsf@supernova.vialactea>
[not found] ` <1358565467.2720.35.camel@Renee-desktop.suse>
[not found] ` <87ip6tx0yf.fsf@supernova.vialactea>
2013-01-19 4:32 ` Loading a module before and after adding a load path Noah Lavine
2013-01-20 18:34 ` Andy Wingo
2013-01-21 17:20 ` Ludovic Courtès
2013-01-21 18:12 ` Andy Wingo
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).