unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Ian Hulin <ian@hulin.org.uk>
Cc: guile-user@gnu.org
Subject: Re: Strange error from %search-load-path via include-from-path when parameter is not a literal string
Date: Mon, 17 Oct 2011 17:54:06 -0400	[thread overview]
Message-ID: <87vcrnp9mp.fsf@yeeloong.netris.org> (raw)
In-Reply-To: <j7hrlt$p39$1@dough.gmane.org> (Ian Hulin's message of "Mon, 17 Oct 2011 19:20:45 +0100")

Ian Hulin <ian@hulin.org.uk> writes:
> I'm trying to write a V2/V1 compatible function like the following:
>
> (define (ly:include the-file)
>   (if (string>? (version) "1.9.10")
>       (include-from-path the-file)
>       (load-from-path the-file)))

The problem is that `include' and `include-from-path' are not
procedures, but syntactic constructs that actually replace themselves
with the contents of the included file at macro-expansion time.

Among other things, this allows you to include a file into a local
lexical environment, e.g. if "foo.scm" contains "(define test 5)" then
the following procedure will return 5, and `test' will become a local
variable within `foo':

  (define (foo)
    (include "foo.scm")
    test)

Since `include' and `include-from-path' is performed at macro-expansion
time, obviously its parameter must be a literal string at
macro-expansion time.  Therefore, you can't use it from a procedure as
you attempted, but you could make a macro instead:

(define-syntax ly:include
   (if (string>? (version) "1.9.10")
       (syntax-rules () ((_ fn) (include-from-path fn)))
       (syntax-rules () ((_ fn) (load-from-path fn)))))

    Best,
     Mark



      parent reply	other threads:[~2011-10-17 21:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-17 18:20 Strange error from %search-load-path via include-from-path when parameter is not a literal string Ian Hulin
2011-10-17 21:36 ` Andy Wingo
2011-10-19 14:43   ` Ian Hulin
2011-10-17 21:54 ` Mark H Weaver [this message]

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=87vcrnp9mp.fsf@yeeloong.netris.org \
    --to=mhw@netris.org \
    --cc=guile-user@gnu.org \
    --cc=ian@hulin.org.uk \
    /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).