* Re: include can't work
[not found] <mailman.171.1384534862.25052.guile-devel@gnu.org>
@ 2013-11-15 17:12 ` Daniel Llorens
0 siblings, 0 replies; 12+ messages in thread
From: Daniel Llorens @ 2013-11-15 17:12 UTC (permalink / raw)
To: guile-devel
> Date: Fri, 15 Nov 2013 15:40:47 +0800
> From: Nala Ginrut <nalaginrut@gmail.com>
> I encountered a bug while trying include some file:
> --------------------------cut------------------------
> scheme@(guile-user)> (include "aa.scm")
> While compiling expression:
> ERROR: In procedure string-length: Wrong type argument in position 1
> (expecting string): #f
> --------------------------end------------------------
>
> The content of aa.scm is trivial but I still list it:
> ------------------cut---------------
> (let ((x (expt 2 10)))
> (display x))
> ------------------end---------------
> Don't argue with the meaning of aa.scm please, it's unrelated to this
> 'include' issue.
>
> Guile version: GNU Guile 2.0.9.92-d3606
I also see this in 2.1.0.1718-5ba10.
^ permalink raw reply [flat|nested] 12+ messages in thread
* include can't work
@ 2013-11-15 7:40 Nala Ginrut
2013-11-17 3:19 ` Mark H Weaver
0 siblings, 1 reply; 12+ messages in thread
From: Nala Ginrut @ 2013-11-15 7:40 UTC (permalink / raw)
To: guile-devel Development
I encountered a bug while trying include some file:
--------------------------cut------------------------
scheme@(guile-user)> (include "aa.scm")
While compiling expression:
ERROR: In procedure string-length: Wrong type argument in position 1
(expecting string): #f
--------------------------end------------------------
The content of aa.scm is trivial but I still list it:
------------------cut---------------
(let ((x (expt 2 10)))
(display x))
------------------end---------------
Don't argue with the meaning of aa.scm please, it's unrelated to this
'include' issue.
Guile version: GNU Guile 2.0.9.92-d3606
Thanks!
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: include can't work
2013-11-15 7:40 Nala Ginrut
@ 2013-11-17 3:19 ` Mark H Weaver
2013-11-17 4:33 ` Mark H Weaver
2013-11-17 8:24 ` Nala Ginrut
0 siblings, 2 replies; 12+ messages in thread
From: Mark H Weaver @ 2013-11-17 3:19 UTC (permalink / raw)
To: Nala Ginrut; +Cc: guile-devel
Nala Ginrut <nalaginrut@gmail.com> writes:
> I encountered a bug while trying include some file:
> --------------------------cut------------------------
> scheme@(guile-user)> (include "aa.scm")
> While compiling expression:
> ERROR: In procedure string-length: Wrong type argument in position 1
> (expecting string): #f
> --------------------------end------------------------
The problem is that when the filename passed to 'include' is a relative
pathname, it interprets that pathname relative to the directory of the
file containing the 'include' form. In this case, the 'include' form is
not in a file at all, so that can't work.
Obviously the error message should be improved, but the upshot is this:
if you want to use 'include' from the REPL, or from some other port with
no associated filename, then you must pass it an absolute pathname.
In this case, I suppose the intuitive expectation is that the filename
should be interpreted relative to the current working directory of the
Guile process, but that is totally different than how 'include' is
expected to work in the usual case. Personally, I think it would be a
mistake to muddy the semantics of 'include' to support these two very
different uses.
When you're at the REPL, why not just use 'load' instead?
Thoughts?
Mark
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: include can't work
2013-11-17 3:19 ` Mark H Weaver
@ 2013-11-17 4:33 ` Mark H Weaver
2013-11-17 21:09 ` Ludovic Courtès
2013-11-17 8:24 ` Nala Ginrut
1 sibling, 1 reply; 12+ messages in thread
From: Mark H Weaver @ 2013-11-17 4:33 UTC (permalink / raw)
To: Nala Ginrut; +Cc: guile-devel
[-- Attachment #1: Type: text/plain, Size: 384 bytes --]
Mark H Weaver <mhw@netris.org> writes:
> Obviously the error message should be improved, but the upshot is this:
> if you want to use 'include' from the REPL, or from some other port with
> no associated filename, then you must pass it an absolute pathname.
Here's a patch to improve the error message.
I'll push it to stable-2.0 if there are no objections.
Thanks,
Mark
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] Improve error when 'include' form with relative path is not in a file --]
[-- Type: text/x-patch, Size: 2462 bytes --]
From bd2db5da3210887d1a128f186851a780c0166b24 Mon Sep 17 00:00:00 2001
From: Mark H Weaver <mhw@netris.org>
Date: Sat, 16 Nov 2013 23:24:42 -0500
Subject: [PATCH] Improve error when 'include' form with relative path is not
in a file.
Reported by Nala Ginrut <nalaginrut@gmail.com>.
* module/ice-9/psyntax.scm (include): Give a proper error message when
given a relative pathname, and when the form is not in a file.
* module/ice-9/psyntax-pp.scm: Regenerate.
---
module/ice-9/psyntax-pp.scm | 9 ++++++++-
module/ice-9/psyntax.scm | 12 +++++++++---
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/module/ice-9/psyntax-pp.scm b/module/ice-9/psyntax-pp.scm
index 254f701..3928bed 100644
--- a/module/ice-9/psyntax-pp.scm
+++ b/module/ice-9/psyntax-pp.scm
@@ -2974,7 +2974,14 @@
((read-file
(lambda (fn dir k)
(let ((p (open-input-file
- (if (absolute-file-name? fn) fn (in-vicinity dir fn)))))
+ (if (absolute-file-name? fn)
+ fn
+ (if dir
+ (in-vicinity dir fn)
+ (syntax-violation
+ 'include
+ "relative pathname only allowed when the include form is in a file"
+ x))))))
(let ((enc (file-encoding p)))
(set-port-encoding! p (let ((t enc)) (if t t "UTF-8")))
(let f ((x (read p)) (result '()))
diff --git a/module/ice-9/psyntax.scm b/module/ice-9/psyntax.scm
index 576fc3f..84b2ef9 100644
--- a/module/ice-9/psyntax.scm
+++ b/module/ice-9/psyntax.scm
@@ -2952,9 +2952,15 @@
(define read-file
(lambda (fn dir k)
(let* ((p (open-input-file
- (if (absolute-file-name? fn)
- fn
- (in-vicinity dir fn))))
+ (cond ((absolute-file-name? fn)
+ fn)
+ (dir
+ (in-vicinity dir fn))
+ (else
+ (syntax-violation
+ 'include
+ "relative pathname only allowed when the include form is in a file"
+ x)))))
(enc (file-encoding p)))
;; Choose the input encoding deterministically.
--
1.7.5.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: include can't work
2013-11-17 4:33 ` Mark H Weaver
@ 2013-11-17 21:09 ` Ludovic Courtès
2013-11-18 6:14 ` Mark H Weaver
0 siblings, 1 reply; 12+ messages in thread
From: Ludovic Courtès @ 2013-11-17 21:09 UTC (permalink / raw)
To: guile-devel
Mark H Weaver <mhw@netris.org> skribis:
> Mark H Weaver <mhw@netris.org> writes:
>> Obviously the error message should be improved, but the upshot is this:
>> if you want to use 'include' from the REPL, or from some other port with
>> no associated filename, then you must pass it an absolute pathname.
>
> Here's a patch to improve the error message.
> I'll push it to stable-2.0 if there are no objections.
Looks good to me, but s/pathname/file name/?
Thanks for catching this,
Ludo’.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: include can't work
2013-11-17 3:19 ` Mark H Weaver
2013-11-17 4:33 ` Mark H Weaver
@ 2013-11-17 8:24 ` Nala Ginrut
2013-11-17 10:09 ` Mark H Weaver
1 sibling, 1 reply; 12+ messages in thread
From: Nala Ginrut @ 2013-11-17 8:24 UTC (permalink / raw)
To: Mark H Weaver; +Cc: guile-devel
[-- Attachment #1: Type: text/plain, Size: 320 bytes --]
2013-11-17 AM11:19 "Mark H Weaver" <mhw@netris.org>:
> When you're at the REPL, why not just use 'load' instead?
Thanks for the explain, but it's not used in a REPL. I just used the REPL
to explain the issue.
Racket's "include" support relative path, so I made the mistake.
>
> Thoughts?
>
> Mark
[-- Attachment #2: Type: text/html, Size: 505 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: include can't work
2013-11-17 8:24 ` Nala Ginrut
@ 2013-11-17 10:09 ` Mark H Weaver
2013-11-18 7:55 ` Nala Ginrut
0 siblings, 1 reply; 12+ messages in thread
From: Mark H Weaver @ 2013-11-17 10:09 UTC (permalink / raw)
To: Nala Ginrut; +Cc: guile-devel
Nala Ginrut <nalaginrut@gmail.com> writes:
> 2013-11-17 AM11:19 "Mark H Weaver" <mhw@netris.org>:
>> When you're at the REPL, why not just use 'load' instead?
>
> Thanks for the explain, but it's not used in a REPL. I just used the
> REPL to explain the issue.
In that case, can you tell us where the 'include' macro was used?
> Racket's "include" support relative path, so I made the mistake.
Guile's 'include' also supports relative paths if the (include "...")
form is found within a file, or more generally, if it was read from a
port that had its filename set.
Please tell us more about what you were doing, so that we can find out
what's going wrong.
Thanks,
Mark
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: include can't work
2013-11-17 10:09 ` Mark H Weaver
@ 2013-11-18 7:55 ` Nala Ginrut
2013-11-18 18:13 ` Mark H Weaver
0 siblings, 1 reply; 12+ messages in thread
From: Nala Ginrut @ 2013-11-18 7:55 UTC (permalink / raw)
To: Mark H Weaver; +Cc: guile-devel
On Sun, 2013-11-17 at 05:09 -0500, Mark H Weaver wrote:
> Guile's 'include' also supports relative paths if the (include "...")
> form is found within a file, or more generally, if it was read from a
> port that had its filename set.
>
> Please tell us more about what you were doing, so that we can find out
> what's going wrong.
>
I think it's a common situation. I planed to include b.scm into a.scm,
like:
-----------------a.scm--------------------
(define-syntax define-primitive
......)
(include "b.scm")
-----------------end----------------------
And let b.scm contains all the primitives definitions, which is
explicitly for later extending.
-----------------b.scm-------------------
(define-primitive %halt 0 0)
(define-primitive pair? 1 1)
(define-primitive cons 2 2)
......
------------------end--------------------
Now my solution is to copy all the contents from b.scm to a.scm.
But this way seems not so cool hmm...
> Thanks,
> Mark
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: include can't work
2013-11-18 7:55 ` Nala Ginrut
@ 2013-11-18 18:13 ` Mark H Weaver
2013-11-18 18:15 ` Mark H Weaver
0 siblings, 1 reply; 12+ messages in thread
From: Mark H Weaver @ 2013-11-18 18:13 UTC (permalink / raw)
To: Nala Ginrut; +Cc: guile-devel
Nala Ginrut <nalaginrut@gmail.com> writes:
> On Sun, 2013-11-17 at 05:09 -0500, Mark H Weaver wrote:
>> Guile's 'include' also supports relative paths if the (include "...")
>> form is found within a file, or more generally, if it was read from a
>> port that had its filename set.
>>
>> Please tell us more about what you were doing, so that we can find out
>> what's going wrong.
>>
>
> I think it's a common situation. I planed to include b.scm into a.scm,
> like:
> -----------------a.scm--------------------
> (define-syntax define-primitive
> ......)
> (include "b.scm")
> -----------------end----------------------
>
> And let b.scm contains all the primitives definitions, which is
> explicitly for later extending.
> -----------------b.scm-------------------
> (define-primitive %halt 0 0)
> (define-primitive pair? 1 1)
> (define-primitive cons 2 2)
> ......
> ------------------end--------------------
This should work if "a.scm" and "b.scm" are files in the same directory.
It works for me. I'm unable to reproduce the problem you're seeing.
Can you help me to reproduce it? How are you loading "a.scm"?
Thanks,
Mark
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: include can't work
2013-11-18 18:13 ` Mark H Weaver
@ 2013-11-18 18:15 ` Mark H Weaver
2013-11-19 3:06 ` Nala Ginrut
0 siblings, 1 reply; 12+ messages in thread
From: Mark H Weaver @ 2013-11-18 18:15 UTC (permalink / raw)
To: Nala Ginrut; +Cc: guile-devel
Mark H Weaver <mhw@netris.org> writes:
> This should work if "a.scm" and "b.scm" are files in the same directory.
> It works for me. I'm unable to reproduce the problem you're seeing.
> Can you help me to reproduce it? How are you loading "a.scm"?
It occurs to me that this might be caused by one of your Guile
customizations. Can you try it with your customizations disabled?
Thanks,
Mark
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: include can't work
2013-11-18 18:15 ` Mark H Weaver
@ 2013-11-19 3:06 ` Nala Ginrut
0 siblings, 0 replies; 12+ messages in thread
From: Nala Ginrut @ 2013-11-19 3:06 UTC (permalink / raw)
To: Mark H Weaver; +Cc: guile-devel
On Mon, 2013-11-18 at 13:15 -0500, Mark H Weaver wrote:
> Mark H Weaver <mhw@netris.org> writes:
> > This should work if "a.scm" and "b.scm" are files in the same directory.
> > It works for me. I'm unable to reproduce the problem you're seeing.
> > Can you help me to reproduce it? How are you loading "a.scm"?
>
> It occurs to me that this might be caused by one of your Guile
> customizations. Can you try it with your customizations disabled?
>
I tried it under 'guile -q' ,and the problem remains, but it's OK for
absolute path. Did I miss something?
> Thanks,
> Mark
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2013-11-19 3:06 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.171.1384534862.25052.guile-devel@gnu.org>
2013-11-15 17:12 ` include can't work Daniel Llorens
2013-11-15 7:40 Nala Ginrut
2013-11-17 3:19 ` Mark H Weaver
2013-11-17 4:33 ` Mark H Weaver
2013-11-17 21:09 ` Ludovic Courtès
2013-11-18 6:14 ` Mark H Weaver
2013-11-17 8:24 ` Nala Ginrut
2013-11-17 10:09 ` Mark H Weaver
2013-11-18 7:55 ` Nala Ginrut
2013-11-18 18:13 ` Mark H Weaver
2013-11-18 18:15 ` Mark H Weaver
2013-11-19 3:06 ` Nala Ginrut
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).