unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* display path of directory of a file and bug?
@ 2020-09-06 14:03 Zelphir Kaltstahl
  2020-09-06 15:12 ` 2QdxY4RzWzUUiLuE
  0 siblings, 1 reply; 3+ messages in thread
From: Zelphir Kaltstahl @ 2020-09-06 14:03 UTC (permalink / raw)
  To: Guile User

Hello Guile Users!

I've hit a weird issue when trying to display the path to the directory
of a source code file. The following experimental code I put into a file:

~~~~START: example.scm~~~~
(display
 (simple-format
  #f "~a\n"
  (dirname (current-filename))))
~~~~END~~~~~~~~~~~~~~~~~~~

Then I wanted to try, whether the output changes, depending on from
which directory I call:

~~~~START~~~~
guile example.scm
~~~~END~~~~~~

from

/home/user/dev/Guile/examples-and-convenience-procedures/file-system

The output was:

~~~~START~~~~
/home/user/dev/Guile/examples-and-convenience-procedures/file-system
~~~~END~~~~~~

As I expected. Then I tried from one directory up:

~~~~START~~~~
guile file-system/example.scm
~~~~END~~~~~~

And the output stayed the same. Satisfied, that the output stays the
same, I renamed the file into something more meaningful. (btw.: If there
is a better way to get the path of the directory of a file, please let
me know!) Then something weird happened:

~~~~START~~~~

user@xlx200:~/dev/Guile/examples-and-convenience-procedures/file-system$ mv example.scm display-dir-of-file.scm
user@xlx200:~/dev/Guile/examples-and-convenience-procedures/file-system$ guile display-dir-of-file.scm 
Backtrace:
In ice-9/boot-9.scm:
  1736:10  7 (with-exception-handler _ _ #:unwind? _ #:unwind-for-type _)
In unknown file:
           6 (apply-smob/0 #<thunk 7f82ac5434c0>)
In ice-9/boot-9.scm:
    718:2  5 (call-with-prompt ("prompt") #<procedure 7f82ac5568e0 at ice…> …)
In ice-9/eval.scm:
    619:8  4 (_ #(#(#<directory (guile-user) 7f82ac17ef00>)))
In ice-9/boot-9.scm:
   2806:4  3 (save-module-excursion #<procedure 7f82ac1711b0 at ice-9/boot…>)
  4351:12  2 (_)
In display-dir-of-file.scm:
      4:2  1 (_)
In unknown file:
           0 (dirname #f)

ERROR: In procedure dirname:
In procedure scm_to_utf8_stringn: Wrong type argument in position 1 (expecting string): #f
user@xlx200:~/dev/Guile/examples-and-convenience-procedures/file-system$ mv display-dir-of-file.scm example.scm
user@xlx200:~/dev/Guile/examples-and-convenience-procedures/file-system$ guile example.scm 
/home/user/dev/Guile/examples-and-convenience-procedures/file-system
user@xlx200:~/dev/Guile/examples-and-convenience-procedures/file-system$ cp example.scm display-dir-of-file.scm
user@xlx200:~/dev/Guile/examples-and-convenience-procedures/file-system$ guile example.scm 
/home/user/dev/Guile/examples-and-convenience-procedures/file-system
user@xlx200:~/dev/Guile/examples-and-convenience-procedures/file-system$ guile display-dir-of-file.scm 
;;; note: source file /home/user/dev/Guile/examples-and-convenience-procedures/file-system/display-dir-of-file.scm
;;;       newer than compiled /home/user/.cache/guile/ccache/3.0-LE-8-4.3/home/user/dev/Guile/examples-and-convenience-procedures/file-system/display-dir-of-file.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/user/dev/Guile/examples-and-convenience-procedures/file-system/display-dir-of-file.scm
;;; compiled /home/user/.cache/guile/ccache/3.0-LE-8-4.3/home/user/dev/Guile/examples-and-convenience-procedures/file-system/display-dir-of-file.scm.go
/home/user/dev/Guile/examples-and-convenience-procedures/file-system
user@xlx200:~/dev/Guile/examples-and-convenience-procedures/file-system$ guile display-dir-of-file.scm 
/home/user/dev/Guile/examples-and-convenience-procedures/file-system
user@xlx200:~/dev/Guile/examples-and-convenience-procedures/file-system$ guile display-dir-of-file.scm 
/home/user/dev/Guile/examples-and-convenience-procedures/file-system
user@xlx200:~/dev/Guile/examples-and-convenience-procedures/file-system$

~~~~END~~~~~~

I also tried with `guile -L . ...` and `guile -L file-system ...` at
some point, but now it simply works and I cannot reproduce the error any
longer. It seems to have something to do with the file name itself. I
also don't see, why it would compile again after copying the file. So I
tested something:

If I move a file using `mv`, a recomplation seems to be not required. If
I copy the file instead, Guile recompiled it. Does this have something
to do with inodes or creation date, which is differently handled when
using `cp` instead of `mv`?

With the whole error thing, I am beginning to doubt myself, but I am
quite sure (99%), that I did not change the code in the file during the
whole process.

This was inside Emacs M-x shell. My GNU Guile is installed via GNU Guix
and is version 3.0.4.

Since it now seems to work, I am only concerned, that there might be a
bug somewhere. Or is there an explanation?

Regards,
Zelphir

-- 
repositories: https://notabug.org/ZelphirKaltstahl



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

* Re: display path of directory of a file and bug?
  2020-09-06 14:03 display path of directory of a file and bug? Zelphir Kaltstahl
@ 2020-09-06 15:12 ` 2QdxY4RzWzUUiLuE
  2020-09-08 10:32   ` Catonano
  0 siblings, 1 reply; 3+ messages in thread
From: 2QdxY4RzWzUUiLuE @ 2020-09-06 15:12 UTC (permalink / raw)
  To: guile-user

On 2020-09-06 at 16:03:17 +0200,
Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> wrote:

> If I move a file using `mv`, a recomplation seems to be not
> required. If I copy the file instead, Guile recompiled it. Does this
> have something to do with inodes or creation date, which is
> differently handled when using `cp` instead of `mv`?

That was my first thought.  Renaming a file (using mv) doesn't change
the timestamp, and it's likely that guile tries to use a cached version
but some of the pieces don't fit right.  Someone with more knowledge of
guile and its caching will have to provide more details.

Possible solutions?  (1) Clean your cache.  Mine is somewhere under
$HOME/.cache/guile/ccache.  (2) Use GUILE_AUTO_COMPILE=fresh to force
guile to ignore the cache and recompile the source file.  (3) Don't do
that.  ;-)

HTH,
Dan



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

* Re: display path of directory of a file and bug?
  2020-09-06 15:12 ` 2QdxY4RzWzUUiLuE
@ 2020-09-08 10:32   ` Catonano
  0 siblings, 0 replies; 3+ messages in thread
From: Catonano @ 2020-09-08 10:32 UTC (permalink / raw)
  To: Guile User

Il giorno dom 6 set 2020 alle ore 17:13 <2QdxY4RzWzUUiLuE@potatochowder.com>
ha scritto:

> On 2020-09-06 at 16:03:17 +0200,
> Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> wrote:
>
> > If I move a file using `mv`, a recomplation seems to be not
> > required. If I copy the file instead, Guile recompiled it. Does this
> > have something to do with inodes or creation date, which is
> > differently handled when using `cp` instead of `mv`?
>
> That was my first thought.  Renaming a file (using mv) doesn't change
> the timestamp, and it's likely that guile tries to use a cached version
> but some of the pieces don't fit right.


Probably the cached version contains, hardwired, to say so, the _old_ name
of the file so when the compiled version runs, the file can't be found ?

Also if this is the case, the error message is... suboptimal ?

Maybe, being able to process the exception that gets raised, you could
extract more information about the error

The interesting line is this one

  1736:10  7 (with-exception-handler _ _ #:unwind? _ #:unwind-for-type _)

If you can manage to somehow process such exception, it'd be nice if you
would share what you find ☺


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

end of thread, other threads:[~2020-09-08 10:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-06 14:03 display path of directory of a file and bug? Zelphir Kaltstahl
2020-09-06 15:12 ` 2QdxY4RzWzUUiLuE
2020-09-08 10:32   ` Catonano

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