unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Strange error from %search-load-path via include-from-path when  parameter is not a literal string
@ 2011-10-17 18:20 Ian Hulin
  2011-10-17 21:36 ` Andy Wingo
  2011-10-17 21:54 ` Mark H Weaver
  0 siblings, 2 replies; 4+ messages in thread
From: Ian Hulin @ 2011-10-17 18:20 UTC (permalink / raw)
  To: guile-user

Hi,

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

I get
ERROR in procedure %search-load-path: Wrong type to apply in position
1 (expecting string): the-file.

Bug or user error?

(include-from-path) also gives similar errors at the REPL when the
filename argument is not a literal string.

Guile Version is 2.0.2

Cheers,
Ian Hulin




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

* Re: Strange error from %search-load-path via include-from-path when  parameter is not a literal string
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Andy Wingo @ 2011-10-17 21:36 UTC (permalink / raw)
  To: Ian Hulin; +Cc: guile-user

Hi,

On Mon 17 Oct 2011 20:20, 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)))
>
> I get
> ERROR in procedure %search-load-path: Wrong type to apply in position
> 1 (expecting string): the-file.
>
> Bug or user error?

User error, unfortunately.  `include' is a macro that expects a literal
string, not a procedure that expects an expression that evaluates to a
string.  For this to work, ly:include would also need to be a macro.

How about:

  (cond-expand
    (guile-2
     (define-syntax ly:include
       (syntax-rules ()
         ((_ the-file) (include-from-path the-file)))))
    (else
     (define (ly:include the-file)
       (load-from-path the-file))))

Assuming of course that you really need it to be ly:include.  The
portable (1.8/2.0) option is to use modules instead of load-from-path.

Regards,

Andy
-- 
http://wingolog.org/



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

* Re: Strange error from %search-load-path via include-from-path when parameter is not a literal string
  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-17 21:54 ` Mark H Weaver
  1 sibling, 0 replies; 4+ messages in thread
From: Mark H Weaver @ 2011-10-17 21:54 UTC (permalink / raw)
  To: Ian Hulin; +Cc: guile-user

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



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

* Re: Strange error from %search-load-path via include-from-path when parameter is not a literal string
  2011-10-17 21:36 ` Andy Wingo
@ 2011-10-19 14:43   ` Ian Hulin
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Hulin @ 2011-10-19 14:43 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-user

Hi Andy and Mark,
Many thanks for the info.

Also thanks for the catch re using modules and portability, I'll have
to address the issue of the tidying up what definitions need to be
loaded into the main (lily) module from other files, and which of
those need to be modules, which was work I had been hoping to defer :-{.

Cheers,

Ian Hulin

On 17/10/11 22:36, Andy Wingo wrote:
> Hi,
> 
> On Mon 17 Oct 2011 20:20, 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)))
>> 
>> I get ERROR in procedure %search-load-path: Wrong type to apply
>> in position 1 (expecting string): the-file.
>> 
>> Bug or user error?
> 
> User error, unfortunately.  `include' is a macro that expects a
> literal string, not a procedure that expects an expression that
> evaluates to a string.  For this to work, ly:include would also
> need to be a macro.
> 
> How about:
> 
> (cond-expand (guile-2 (define-syntax ly:include (syntax-rules () 
> ((_ the-file) (include-from-path the-file))))) (else (define
> (ly:include the-file) (load-from-path the-file))))
> 
> Assuming of course that you really need it to be ly:include.  The 
> portable (1.8/2.0) option is to use modules instead of
> load-from-path.
> 
> Regards,
> 
> Andy




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

end of thread, other threads:[~2011-10-19 14:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).