From: Andy Wingo <wingo@pobox.com>
To: Neil Jerram <neil@ossau.uklinux.net>
Cc: guile-user@gnu.org
Subject: Re: Modules
Date: Sun, 30 Jan 2011 12:42:07 +0100 [thread overview]
Message-ID: <m3pqre39f4.fsf@unquote.localdomain> (raw)
In-Reply-To: <87tygrcnbf.fsf@ossau.uklinux.net> (Neil Jerram's message of "Sat, 29 Jan 2011 23:17:08 +0000")
Hi Neil,
On Sun 30 Jan 2011 00:17, Neil Jerram <neil@ossau.uklinux.net> writes:
> Andy Wingo <wingo@pobox.com> writes:
>
>> If you are using modules, they are already in one global namespace,
>> the various roots of which are in the %load-path and/or
>> %load-compiled-path. (resolve-module '(foo bar)) should work
>> regardless of what file calls it.
>
> If the modules are installed, that's true. What if they are not?
In that case you have to modify the load path, somehow. I have been
doing this with scripts that add to $GUILE_LOAD_PATH and
$GUILE_LOAD_COMPILED_PATH. (Which is another thing to note; if you have
an autotooled project, the .go files go in the $builddir.)
So if I'm hacking against an uninstalled tekuti, for example, I run my
code within ~/src/tekuti/env.
> For scripts that use uninstalled modules, then, some kind of solution is
> needed; ideally one that works for both 1.8 and 1.9/2.0, allows the code
> needed to live in a single common file, rather than duplicated at the
> top of each script; and continues to work if the script+module tree as a
> whole is moved to a different place in the filesystem. Also I think
> it's preferable if the solution is a Guile one, as opposed to based on
> the #! line, or needing a shell script wrapper.
How would it look?
I guess I am unclear on the actual problem being solved here :) Let's
consider that I am hacking on my "analysis" script, which lives at
~/src/foo/analysis. I guess it's helping me in my "foo" project. Now
the script gets too big; time to split into modules. How to do that?
We have basically one option of a path to automatically add to the load
path: ~/src/foo. It seems tractable, unless we start to consider
installing the script to /usr/bin, combined with the presence of "" in
the default load-extensions list, in which case the unexpected
interactions with other members of that path look daunting.
No, I think that the script itself will need to indicate some path to
add to the load path.
What you can do, perhaps, is add a macro:
(define-syntax add-relative-load-path
(lambda (x)
(syntax-case x ()
((_ path) (string? (syntax->datum #'path))
(let* ((src (syntax-source #'x))
(current-file (or (and src (assq-ref src 'filename))
(error "Could not determine current file name")))
(vicinity (dirname (canonicalize-path current-file)))
(path-elt (in-vicinity vicinity (syntax->datum #'path))))
#`(eval-when (compile load eval)
(set! %load-path (cons #,path-elt %load-path))))))))
Then in "analysis", you could `(add-relative-load-path ".")'.
But... If you compile a .go, then install both .scm and .go somewhere,
the installed .go file will reference the build path, which was inserted
into the source via the current-file business.
(You could argue that this is precisely the case that we are _not_
interested in, given that currently we only install .go files for files
that are in the load path. But I guess we should figure out a better
autocompilation story for files in $bindir.)
It _is_ true that we need to figure out what's going on with
(current-load-port) in 1.9, but it's not clear what to do, exactly, when
you have compiled files; you could not have the corresponding .scm at
all, or in any case when you've loaded the .go you don't actually have a
port to the .scm, and in fact if the file was loaded via
`load-from-path' you don't know exactly where the .scm is at all.
Perhaps we should residualize into the .go whether the file was compiled
for `load' or for `load-from-path', and what was the original path of
the file.
> Good point, thanks for the reminder about that. But (for 1.9/2.0)
> `include' will always be well-defined and reliably relative to the
> containing file's name, won't it?
Yes, at expansion time. But note the .scm/.go installation case; and
also note that the code that chooses when to use a .go over a .scm
doesn't know anything about dependencies, currently, so a change to an
included file doesn't trigger recompilation of the includer.
Andy
--
http://wingolog.org/
next prev parent reply other threads:[~2011-01-30 11:42 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-08 11:45 Modules Marek Kubica
2010-12-08 18:11 ` Modules Andreas Rottmann
2010-12-09 1:19 ` Modules Nala Ginrut
2011-01-28 16:26 ` Modules Andy Wingo
2011-01-29 12:13 ` Modules Marek Kubica
2011-01-29 13:08 ` Modules Neil Jerram
2011-01-29 13:18 ` Modules Neil Jerram
2011-01-29 17:04 ` Modules Andy Wingo
2011-01-29 18:37 ` Modules Marek Kubica
2011-01-29 23:17 ` Modules Neil Jerram
2011-01-30 10:13 ` Modules Thien-Thi Nguyen
2011-01-30 11:42 ` Andy Wingo [this message]
2011-02-13 19:05 ` Modules Andy Wingo
2011-01-29 17:07 ` Modules Andy Wingo
2011-01-29 18:40 ` Modules Marek Kubica
2011-01-29 23:35 ` Modules Neil Jerram
2011-02-01 21:43 ` Modules Andy Wingo
2011-02-02 14:43 ` Modules Jon Wilson
-- strict thread matches above, loose matches on Subject: below --
2004-03-21 5:40 modules Ian Zimmerman
2004-03-21 14:47 ` modules Andreas Rottmann
2004-03-22 18:05 ` modules Ian Zimmerman
2004-03-23 16:05 ` modules Robert Uhl
2004-03-21 21:29 ` modules Thien-Thi Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3pqre39f4.fsf@unquote.localdomain \
--to=wingo@pobox.com \
--cc=guile-user@gnu.org \
--cc=neil@ossau.uklinux.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).